添加产品后,如何防止购物车模式(ajax)打开? [英] How do I prevent the cart modal (ajax) from opening after adding a product?
问题描述
代码必须位于某处在这里: http:// cdn.shopify.com/s/files/1/0656/8697/t/7/assets/ajaxify.js?8066 。
我已经尝试从该方法中删除 buildCart(cart)
(ajaxify.js中的第711行):
cartUpdateCallback = function(cart){
//更新数量和价格
updateCountPrice(cart);
switch(settings.method){
case'flip':
$('。flip-cart span')。html(cart.item_count);
休息;
case'modal':
buildCart(cart); //<<<
休息;
case'drawer':
buildCart(cart);
if(!$ drawerContainer.hasClass('is-visible')){
showDrawer();
} else {
scrollTop();
}
break;
}
};
这样做可以防止在添加产品后打开购物车模式,但也会禁止我打开购物车如果点击购物车按钮。
接下来我可以尝试什么?
它从来没有真正发生过我想要的功能,但我完全理解。请按照以下步骤操作,以获取模态购物车的运行状态:
注意:我正在查看最新版本的行数版本即将合并到木材大师中。
-
在私有函数变量声明下添加
cartToggleCallback
在cartUpdateCallback
之后。 -
在
showModal
中,更改Shopify.getCart (cartUpdateCallback);
至Shopify.getCart(cartToggleCallback);
这是第475行左右。 -
制作
cartUpdateCallback
的完整副本,并命名新函数cartToggleCallback
。
cartUpdateCallback
以上步骤将针对产品何时添加与何时打开购物车创建单独的回调。编辑:要在下面的注释中解决问题,请将 showModal
替换为 >函数与以下内容:
showModal = function(toggle){
$ body.addClass('ajaxcart--是可见');
Shopify.getCart(cartUpdateCallback);
};
Every time I add a new product, the cart opens up as a modal. I do need, want and like the modal method of the cart, I just want to disable it from opening every time a product gets added.
The code has to be somewhere in here: http://cdn.shopify.com/s/files/1/0656/8697/t/7/assets/ajaxify.js?8066.
I've tried removing buildCart(cart)
(line 711 in ajaxify.js) from this method:
cartUpdateCallback = function (cart) {
// Update quantity and price
updateCountPrice(cart);
switch (settings.method) {
case 'flip':
$('.flip-cart span').html(cart.item_count);
break;
case 'modal':
buildCart(cart); // <<<
break;
case 'drawer':
buildCart(cart);
if ( !$drawerContainer.hasClass('is-visible') ) {
showDrawer();
} else {
scrollTop();
}
break;
}
};
This does prevent the cart modal from opening after a product is added, but also disables me from opening the cart if I click on the cart button.
What could I try next?
It never really occurred to me that would be desired functionality, but I totally understand. Follow these steps to get the modal cart working as you'd like:
Note: My line numbers may be off compared to your version as I'm looking at the latest version that will be merged into Timber master soon.
Add
cartToggleCallback
aftercartUpdateCallback
under the Private function variable declarations. This is around line 260.In
showModal
, changeShopify.getCart(cartUpdateCallback);
toShopify.getCart(cartToggleCallback);
This is around line 475.Make a complete copy of
cartUpdateCallback
and name the new functioncartToggleCallback
. This is around line 689.Comment out
buildCart(cart);
fromcase 'modal
incartUpdateCallback
The steps above will create separate callbacks for when a product is added vs when the cart is toggled opened. Let me know if you have any issues!
Edit: To fix the issue in the comment below, replace the showModal
function with the following:
showModal = function (toggle) {
$body.addClass('ajaxcart--is-visible');
Shopify.getCart(cartUpdateCallback);
};
这篇关于添加产品后,如何防止购物车模式(ajax)打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!