简体   繁体   English

将多个产品添加到产品卡Bigcommerce模具上的购物车

[英]Adding multiple products to cart on product card Bigcommerce Stencil

I'm trying to recreate the functionality here - http://www.babycelebrations.co.uk/ 我正在尝试在此处重新创建功能-http: //www.babycelebrations.co.uk/

Where customers can choose the quantity of the product and add to cart before they get to the product/cart page. 客户可以在其中选择产品数量并在进入产品/购物车页面之前将其添加到购物车。

This was possible in blueprint, but in stencil, obivously the variables work differently, would anyone be able to point me in the right direction of how to edit this code to suit stencil? 这在蓝图中是可能的,但是在模具中,显然变量的工作方式不同,有人能为我指出如何编辑此代码以适合模具的正确方向吗?

<script type="text/javascript">
        $(document).ready(function() {

        $('form.addToCart').submit(function(event) {

        var pid = $('input[name=product_id]', this).val();
        var q = $('input[name=qty]', this).val();

        fastCartAction('/cart.php?action=add&product_id='+ pid +'&qty='+ q);
        event.preventDefault();

        });

        if($('.side-menu').length == 0) {
            var bcURL = $(".Breadcrumb li:last").prev("li").find('a').attr("href");
            $(".Left").load(bcURL + ' #smp');
        }
        });
    </script>

I believe it is controlled by that code and this html - 我相信它是由该代码和此html控制的-

<input type="text" name="qty" value="1" class="qty" />

Any help would be much appreciated, thanks 任何帮助将不胜感激,谢谢

You can use Stencil utils api to facilitate this where you can add items to the cart or update the quantity of an item in the cart. 您可以使用Stencil utils api来简化此操作,您可以在其中向购物车添加商品或更新购物车中商品的数量。

<form class="form" method="post" action="{{product.cart_url}}"
enctype="multipart/form-data" data-cart-item-add>

The above will allow the code below to listen for a triggered event: 上面的代码将允许下面的代码侦听触发的事件:

[...]
import utils from '@bigcommerce/stencil-utils';
[...]
addProductToCart() {
  utils.hooks.on('cart-item-add', (event) => {
    // insert code for adding or updating quantity
  });
}

https://stencil.bigcommerce.com/docs/stencil-utils-api-reference#Cart-API https://stencil.bigcommerce.com/docs/stencil-utils-api-reference#Cart-API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM