首先打开 system\library\cart\cart.php 并找到以下代码行:
$product_data[] = array(
'cart_id' => $cart['cart_id'],
'product_id' => $product_query->row['product_id'],
在这些代码行下面添加以下行:
'product_quantity' => $product_query->row['quantity'],
第二次打开控制器目录\controller\checkout\cart.php 并找到以下代码行:
$data['products'][] = array(
'cart_id' => $product['cart_id'],
在这些代码行下面添加以下行:
'product_quantity'=>$product['product_quantity'],
最后在 catalog/view/theme/YOUR_ACTIVATED_THEME/template/checkout/cart.tpl 找到以下代码行
<td class="text-left">
<div class="input-group btn-block" style="max-width: 200px;">
<input type="text" name="quantity[<?php echo $product['cart_id']; ?>]"
value="<?php echo $product['quantity']; ?>" size="1" class="form-control"/>
<span class="input-group-btn">
<button type="submit" data-toggle="tooltip" title="<?php echo $button_update; ?>"
class="btn btn-primary"><i class="fa fa-refresh"></i></button>
<button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>"
class="btn btn-danger" onclick="cart.remove('<?php echo $product['cart_id']; ?>');"><i
class="fa fa-times-circle"></i></button>
</span></div>
</td>
替换为以下代码:
<!--Changes done-->
<td class="text-left">
<div class="input-group btn-block" style="max-width: 200px;">
<select name="quantity[<?php echo $product['cart_id']; ?>]"
onchange='this.form.submit()'>
<?php for($cp=1; $cp<=$product['product_quantity']; $cp++){ ?>
<option
<?php if($product['quantity']==$cp){ echo "selected"; } ?>
value="<?php echo $cp; ?>"><?php echo $cp; ?></option>
<?php } ?>
</select>
<span class="input-group-btn">
<button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>"
class="btn btn-danger" onclick="cart.remove('<?php echo $product['cart_id']; ?>');"><i
class="fa fa-times-circle"></i></button>
</span>
</div>
</td>
<!--End of Changes done-->
您可以从以下链接下载更改的文件并查看更改以及查看图像中的演示:
https ://webocreation.com/blog/dropdown-quantity-product-cart-page-opencart-2-2