[英]Opencart 2.3 - showing discount in featured extension
I am new to Opencart and I am trying to display the quantity discount in the featured products - without success. 我是Opencart的新手,我试图在特色产品中显示数量折扣-没有成功。 I am using Opencart 2.3.
我正在使用Opencart 2.3。 Basically, what I would like to achieve is to pass the variables
quantity
and price
from the controller file featured.php
to the view file featured.tpl
. 基本上,我想实现的是将变量
quantity
和price
从控制器文件featured.php
传递到视图文件featured.tpl
。
Here is what I have tried: 这是我尝试过的:
1) In the file /catalog/controller/extension/module/featured.php
after the $product_info = $this->model_catalog_product->getProduct($product_id);
1)在
$product_info = $this->model_catalog_product->getProduct($product_id);
之后的文件/catalog/controller/extension/module/featured.php
$product_info = $this->model_catalog_product->getProduct($product_id);
I added the following code: 我添加了以下代码:
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);
$data['discounts'][] = array();
foreach ($discounts as $discount) {
$data['discounts'][] = array(
'quantity' => $discount['quantity'],
'price' => $discount['price']
);
}
2) In the file /catalog/view/theme/default/template/extension/module/featured.tpl
I added the following code: 2)在文件
/catalog/view/theme/default/template/extension/module/featured.tpl
我添加了以下代码:
<?php foreach ($discounts as $discount) { ?>
<span>
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?>
</span><br>
<?php } ?>
Any help would be very much appreciated! 任何帮助将不胜感激!
I have tried several other variations of code (eg the solution provided here ), but no success. 我尝试了其他几种代码变体(例如, 此处提供的解决方案),但没有成功。
Go to catalog\\language\\en-gb\\extension\\module\\featured.php Add following code: 转到目录\\语言\\ zh-CN \\扩展名\\模块\\ featured.php,添加以下代码:
$_['text_discount'] = ' or more ';
Go to catalog\\controller\\extension\\module\\featured.php Find following lines of code: 转到catalog \\ controller \\ extension \\ module \\ featured.php查找以下代码行:
$data['heading_title'] = $this->language->get('heading_title');
Add following lines of code: 添加以下代码行:
$data['text_discount'] = $this->language->get('text_discount');
Find following lines of code: 查找以下代码行:
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
Add following lines of code: 添加以下代码行:
$discounts = $this->model_catalog_product->getProductDiscounts($product_id);
$product_info['discounts'] = array();
foreach ($discounts as $discount) {
$product_info['discounts'][] = array(
'quantity' => $discount['quantity'],
'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
);
}
Find following lines of code: 查找以下代码行:
$data['products'][] = array(
'product_id' => $product_info['product_id'],
Just below it Add following lines of code: 在其正下方,添加以下代码行:
'discounts'=>$product_info['discounts'],
Now go to catalog\\view\\theme\\YOUR_ACTIVE_THEME\\template\\extension\\module\\featured.tpl 现在转到目录\\视图\\主题\\您的ACTIVE_THEME \\模板\\扩展名\\模块\\ featured.tpl
Find following lines of code: 查找以下代码行:
<div class="button-group">
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
Add above it or where ever you want to show but need to inside the product array: 在其上方或想要显示但需要在产品阵列内的任何位置添加:
<?php if ($product['discounts']) { ?>
<ul>
<hr>
<?php foreach ($product['discounts'] as $discount) { ?>
<li><?php echo $discount['quantity']; ?><?php echo $text_discount; ?><?php echo $discount['price']; ?></li>
<?php } ?>
</ul>
<?php } ?>
You can download the ocmod at Show Discounts at featured module Ocmod OpenCart 2.3.02 您可以在特色模块Ocmod OpenCart 2.3.02的Show Discounts上下载ocmod。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.