Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 根据用户将产品添加到购物车中的情况,为每个产品添加包含特定数量的数量字段_Javascript_Php_Opencart_Opencart2.x - Fatal编程技术网

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

Javascript 根据用户将产品添加到购物车中的情况,为每个产品添加包含特定数量的数量字段,javascript,php,opencart,opencart2.x,Javascript,Php,Opencart,Opencart2.x,我在“添加到购物车”按钮附近添加了一个数量框,用于添加到购物车中的特定产品。最初它是零。当用户/客户将产品添加到购物车中时,其大小应逐个增加 文件template/module/feature.tpl <button class="product-btn-add" type="button" onclick="cart.minus('<?php echo $product['product_id']; ?>');pq_minus( $(this).parent() );">

我在“添加到购物车”按钮附近添加了一个数量框,用于添加到购物车中的特定产品。最初它是零。当用户/客户将产品添加到购物车中时,其大小应逐个增加

文件
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>

您可以从购物车类
system/library/cart.php

尝试打印($this->cart->getProducts())

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


祝你好运

那么你存储这些值的代码在哪里?@Naruto我使用的是Opencart 2.x,我没有存储值,这就是问题所在,Opencart已经在某处存储了它,但我无法在“特色”中获得它。
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 );
}