Skip to content

Commit

Permalink
apphtml5 page trace update
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed Jul 1, 2021
1 parent 4406c4c commit 4265c0a
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 154 deletions.
1 change: 1 addition & 0 deletions app/apphtml5/modules/Catalog/block/category/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function getLastData()
'filter_info' => Yii::$service->category->getFilterInfo($this->_category, $this->_where),
'filter_price' => $this->getFilterPrice(),
'filter_category' => $this->getFilterCategoryHtml(),
'categoryM' => $this->_category,
'page_count' => $page_count,
//'content' => Yii::$service->store->getStoreAttrVal($this->_category['content'],'content'),
//'created_at' => $this->_category['created_at'],
Expand Down
1 change: 1 addition & 0 deletions app/apphtml5/modules/Catalog/block/product/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function getLastData()
'_id' => $this->_product[$productPrimaryKey],
'buy_also_buy' => $this->getProductBySkus($skus),
'brand_name' => $this->_brandName,
'productM' => $this->_product,
];
}

Expand Down
1 change: 1 addition & 0 deletions app/apphtml5/modules/Catalogsearch/block/index/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ protected function getSearchProductColl()
'product_id','sku', 'spu', 'name', 'image',
'price', 'special_price',
'special_from', 'special_to',
'brand_id',
'url_key', 'score',
];
$where = $this->_where;
Expand Down
1 change: 1 addition & 0 deletions app/apphtml5/modules/Cms/block/home/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function getProductBySkus($skus)
'sku', 'spu', 'name', 'image',
'price', 'special_price',
'special_from', 'special_to',
'brand_id',
'url_key', 'score',
];
$filter['where'] = ['in', 'sku', $skus];
Expand Down
5 changes: 3 additions & 2 deletions app/apphtml5/theme/base/html5/catalog/category/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<!-- 添加 class infinite-scroll 和 data-distance 向下无限滚动可不加infinite-scroll-bottom类,这里加上是为了和下面的向上无限滚动区分-->
<div class=" infinite-scroll infinite-scroll-bottom" data-distance="10">
<div class="list-block">
<div class="list-container">
<div class="list-container category_product">
<?= Yii::$service->page->widget->render('cms/productlist' , ['products' => $products] ); ?>

</div>
Expand Down Expand Up @@ -190,4 +190,5 @@ function addItems() {
<?php $this->endBlock(); ?>
</script>
<?php $this->registerJs($this->blocks['category_product_filter'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
<?= Yii::$service->page->trace->getTraceCategoryJsCode($name_default_lang) ?>
<?= Yii::$service->page->trace->getTraceCategoryJsCode($this, $categoryM, $products) ?>

137 changes: 69 additions & 68 deletions app/apphtml5/theme/base/html5/catalog/product/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,72 @@
</div>
</div>
<script>
// add to cart js
<?php $this->beginBlock('add_to_cart') ?>
$(document).ready(function(){
// add to cart js
<?php $this->beginBlock('add_to_cart') ?>
var addToCart = function(){
i = 1;
$(".product_custom_options .pg .rg ul.required").each(function(){
val = $(this).find("li.current a.current").attr("value");
if(!val){
$(this).parent().parent().css("border","1px dashed #cc0000").css('padding-left','10px').css("margin-left","-10px");
i = 0;
}else{
$(this).parent().parent().css("border","none").css('padding-left','0px').css("margin-left","0px");

}
});
if(i){
custom_option = new Object();
$(".product_custom_options .pg .rg ul").each(function(){
$m = $(this).find("li.current a.current");
attr = $m.attr("attr");
value = $m.attr("value");
custom_option[attr] = value;
});
custom_option_json = JSON.stringify(custom_option);
//alert(custom_option_json);
sku = $(".sku").val();
qty = $(".qty").val();
qty = qty ? qty : 1;
csrfName = $(".product_csrf").attr("name");
csrfVal = $(".product_csrf").val();

$(".product_custom_options").val(custom_option_json);
$(this).addClass("dataUp");
// ajax 提交数据

addToCartUrl = "<?= Yii::$service->url->getUrl('checkout/cart/add'); ?>";
$data = {};
$data['custom_option'] = custom_option_json;
$data['product_id'] = $(".product_view_id").val();
$data['qty'] = qty;
if (csrfName && csrfVal) {
$data[csrfName] = csrfVal;
}
$.ajax({
async:true,
timeout: 6000,
dataType: 'json',
type:'post',
data: $data,
url:addToCartUrl,
success:function(data, textStatus){
if(data.status == 'success'){
items_count = data.items_count;
$("#js_cart_items").html(items_count);
window.location.href="<?= Yii::$service->url->getUrl("checkout/cart") ?>";
}else{
content = data.content;
$(".addProductToCart").removeClass("dataUp");
alert(content);
}

},
error:function (XMLHttpRequest, textStatus, errorThrown){}
});
}
};
$(document).ready(function(){
productAjaxUrl = "<?= Yii::$service->url->getUrl('customer/ajax/product'); ?>";
product_id = $(".product_view_id").val();
$.ajax({
Expand All @@ -195,69 +258,7 @@
error:function (XMLHttpRequest, textStatus, errorThrown){}
});

$(".addProductToCart").click(function(){
i = 1;
$(".product_custom_options .pg .rg ul.required").each(function(){
val = $(this).find("li.current a.current").attr("value");
if(!val){
$(this).parent().parent().css("border","1px dashed #cc0000").css('padding-left','10px').css("margin-left","-10px");
i = 0;
}else{
$(this).parent().parent().css("border","none").css('padding-left','0px').css("margin-left","0px");

}
});
if(i){
custom_option = new Object();
$(".product_custom_options .pg .rg ul").each(function(){
$m = $(this).find("li.current a.current");
attr = $m.attr("attr");
value = $m.attr("value");
custom_option[attr] = value;
});
custom_option_json = JSON.stringify(custom_option);
//alert(custom_option_json);
sku = $(".sku").val();
qty = $(".qty").val();
qty = qty ? qty : 1;
csrfName = $(".product_csrf").attr("name");
csrfVal = $(".product_csrf").val();

$(".product_custom_options").val(custom_option_json);
$(this).addClass("dataUp");
// ajax 提交数据

addToCartUrl = "<?= Yii::$service->url->getUrl('checkout/cart/add'); ?>";
$data = {};
$data['custom_option'] = custom_option_json;
$data['product_id'] = $(".product_view_id").val();
$data['qty'] = qty;
if (csrfName && csrfVal) {
$data[csrfName] = csrfVal;
}
$.ajax({
async:true,
timeout: 6000,
dataType: 'json',
type:'post',
data: $data,
url:addToCartUrl,
success:function(data, textStatus){
if(data.status == 'success'){
items_count = data.items_count;
$("#js_cart_items").html(items_count);
window.location.href="<?= Yii::$service->url->getUrl("checkout/cart") ?>";
}else{
content = data.content;
$(".addProductToCart").removeClass("dataUp");
alert(content);
}

},
error:function (XMLHttpRequest, textStatus, errorThrown){}
});
}
});
$(".addProductToCart").click(addToCart);
// product favorite
$("#divMyFavorite").click(function(){
if($(this).hasClass('act')){
Expand Down Expand Up @@ -312,8 +313,8 @@
});
$.init();
<?php $this->endBlock(); ?>
<?php $this->registerJs($this->blocks['add_to_cart'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
<?php $this->registerJs($this->blocks['add_to_cart'],\yii\web\View::POS_READY);//将编写的js代码注册到页面底部 ?>
</script>
<?= Yii::$service->page->trace->getTraceProductJsCode($sku, $spu) ?>
<?= Yii::$service->page->trace->getTraceProductJsCode($this, $productM) ?>


4 changes: 2 additions & 2 deletions app/apphtml5/theme/base/html5/catalogsearch/index/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<!-- 添加 class infinite-scroll 和 data-distance 向下无限滚动可不加infinite-scroll-bottom类,这里加上是为了和下面的向上无限滚动区分-->
<div class=" infinite-scroll infinite-scroll-bottom" data-distance="10">
<div class="list-block">
<div class="list-container">
<div class="list-container category_product">
<?php if(is_array($products) && !empty($products)): ?>
<?php
$parentThis['products'] = $products;
Expand Down Expand Up @@ -174,4 +174,4 @@ function addItems() {
<?php $this->endBlock(); ?>
</script>
<?php $this->registerJs($this->blocks['category_product_filter'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
<?= Yii::$service->page->trace->getTraceSearchJsCode($traceSearchData) ?>
<?= Yii::$service->page->trace->getTraceSearchJsCode($this, $traceSearchData, $products) ?>
Loading

0 comments on commit 4265c0a

Please sign in to comment.