首页 文章

根据用户添加的产品,将包含特定量的每个产品的数量字段添加到购物车中

提问于
浏览
2

我在购物车中添加了一个数量框,附近添加到购物车按钮 . 最初它是零 . 当用户/客户将产品添加到购物车时,其尺寸应逐一增加 .

档案 template/module/feature.tpl

<button class="product-btn-add" type="button" onclick="cart.minus('<?php echo $product['product_id']; ?>');pq_minus( $(this).parent() );">
    <span class="hidden-sm">-</span>
</button>
<input class="product-quantity-input" type="text"  text-align="center" value="0" size="1" readonly="true">
<button class="product-btn-add" type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');pq_plus( $(this).parent() ); ">
    <span class="hidden-sm">+</span>
</button>

common.js

function pq_setQuantity( $input, add ) {
    var val = pq_getQuantity( $input );
    val += 1 * ( add ? 1 : -1 );
    if( val < 1 )
        val = 0;
    input.attr('value', val.toString()).val( val.toString() );
}               

function pq_getQuantity( $input ) { 
    var val = parseInt( $input.val() );
    if( typeof val == 'NaN' || val < 1 )
        val = 0;
    return val;
}

function pq_plus( $item ) {
    pq_setQuantity( $item.find('.product-quantity-input'), true );
}

function pq_minus( $item ) {
    pq_setQuantity( $item.find('.product-quantity-input'), false );
}

刷新页面时,数量文本输入框变为零

enter image description here
我在刷新前和刷新后添加了两张图片
enter image description here

1 回答

  • 0

    您可以从购物车类中获取购物车信息 system/library/cart.php

    试试 print_r($this->cart->getProducts());

    在这里您可以找到您的购物车的 product_id 和相关的 added quantity . 现在,您可以将相关的添加数量传递给视图文件表单控制器 .

    祝好运

相关问题