我正在Opencart 2.x中开发一个购物车。
一切都很顺利,但我被困在一个地方,我需要cart.tpl
中的下拉列表,而不是在带有更新购物车按钮的输入框中显示数量。
我已经查看了cart.php
的控制器,但不知道从哪里获得数量。
研究的代码如下:
$data['products'][] = array(
'cart_id' => $product['cart_id'],
'thumb' => $image,
'name' => $product['name'],
'model' => $product['model'],
}
我试着在这里添加数量,但无法进入cart.tpl.
然后我决定检查购物车add()
的功能,并获得如下数量:
public function add() {
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);
$data['qty'] = sprintf($product_info['quantity']);
// I added this data line
}
但即便如此,在cart.tpl上执行CCD_ 4也无济于事。有什么建议吗?
首先打开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