添加产品后,如何防止购物车模式(ajax)打开? [英] How do I prevent the cart modal (ajax) from opening after adding a product?

查看:133
本文介绍了添加产品后,如何防止购物车模式(ajax)打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我添加一款新产品时,购物车都会以模态形式开启。我确实需要,希望和喜欢购物车的模式方法,我只是想在每次添加产品时都禁用它。



代码必须位于某处在这里: 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;
}
};

这样做可以防止在添加产品后打开购物车模式,但也会禁止我打开购物车如果点击购物车按钮。



接下来我可以尝试什么?

解决方案 div>

它从来没有真正发生过我想要的功能,但我完全理解。请按照以下步骤操作,以获取模态购物车的运行状态:



注意:我正在查看最新版本的行数版本即将合并到木材大师中。


  1. 在私有函数变量声明下添加 cartToggleCallback cartUpdateCallback 之后。


  2. showModal 中,更改 Shopify.getCart (cartUpdateCallback); Shopify.getCart(cartToggleCallback); 这是第475行左右。

  3. 制作 cartUpdateCallback 的完整副本,并命名新函数 cartToggleCallback

  4. buildCart(cart); > case'modal in 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.

  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);
};

这篇关于添加产品后,如何防止购物车模式(ajax)打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆