更新时间:2023-11-29 23:16:46
我花了几个小时来做,但是我能使它工作.现在,我只需要SELECT,这样您就可以根据类别中的需要对其进行修改了.我正在使用2.1.0.2版
I spent hours doing this but I got it working. Now, I only needed the SELECT so you go and modified it to your needs in the category.tpl I'm using version 2.1.0.2
1-转到/catalog/controller/product/category.php 然后>>找到产品阵列
1- Go to /catalog/controller/product/category.php Then >> Find the product array
$data['products'][] = array(
'product_id' => $result['product_id'],
2-将此代码添加到数组上方
2- Add this code above the array
foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
foreach ($option['product_option_value'] as $option_value) {
$product_option_value_data[] = array(
'product_option_value_id' => $option_value['product_option_value_id'],
'option_value_id' => $option_value['option_value_id'],
'name' => $option_value['name'],
'image' => $this->model_tool_image->resize($option_value['image'], 50, 50),
'price' => $price,
'price_prefix' => $option_value['price_prefix']
);
}
$option_data[] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value' => $product_option_value_data,
'option_id' => $option['option_id'],
'name' => $option['name'],
'type' => $option['type'],
'value' => $option['value'],
'required' => $option['required']
);
}
3-将此代码添加到产品数组中
3- add this code inside the products array
'option' => $option_data
4-转到/catalog/view/theme/您的模板/template/product/category.tpl并将此代码添加到您的产品循环中
4- Go to /catalog/view/theme/YOUR TEMPLATE/template/product/category.tpl and add this code to your product loop
<?php foreach ($product['option'] as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<select name="option[<?php echo $option['product_option_id']; ?>]" id="input-option<?php echo $option['product_option_id']; ?>" class="form-control">
<option value="">SELECT EXTENDED LENGTH</option>
<?php foreach ($option['product_option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
<?php } ?>
<?php } ?>
我仍在使用javascript,因此无需添加产品页面就可以将带有数量和选项的产品添加到购物车中.谢谢
I'm still working in the javascript so I can add product to the cart with quantity and options without going into the product's page. Thanks