How do I prevent the cart modal (ajax) from opening after adding a product?

99封情书 提交于 2019-12-11 20:43:33

问题


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.

  1. Add cartToggleCallback after cartUpdateCallback under the Private function variable declarations. This is around line 260.

  2. In showModal, change Shopify.getCart(cartUpdateCallback); to Shopify.getCart(cartToggleCallback); This is around line 475.

  3. Make a complete copy of cartUpdateCallback and name the new function cartToggleCallback. This is around line 689.

  4. Comment out buildCart(cart); from case 'modal in cartUpdateCallback

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!