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