问题
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?
回答1:
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);
};
来源:https://stackoverflow.com/questions/26412955/how-do-i-prevent-the-cart-modal-ajax-from-opening-after-adding-a-product