Opencart 2.3 - 在特色扩展中显示折扣
Opencart 2.3 - showing discount in featured extension
我是 Opencart 的新手,我想在特色产品中显示数量折扣 - 但没有成功。我正在使用 Opencart 2.3。基本上,我想要实现的是将变量 quantity
和 price
从控制器文件 featured.php
传递到视图文件 featured.tpl
.
这是我尝试过的:
1) 在文件/catalog/controller/extension/module/featured.php
中$product_info = $this->model_catalog_product->getProduct($product_id);
之后添加了如下代码:
$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) 在文件 /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 } ?>
非常感谢任何帮助!
我尝试了其他几种代码变体(例如提供的解决方案 here),但没有成功。
转到catalog\language\en-gb\extension\module\featured。php
添加以下代码:
$_['text_discount'] = ' or more ';
转到catalog\controller\extension\module\featured。php
查找以下代码行:
$data['heading_title'] = $this->language->get('heading_title');
添加以下代码行:
$data['text_discount'] = $this->language->get('text_discount');
找到以下代码行:
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
添加以下代码行:
$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'])
);
}
找到以下代码行:
$data['products'][] = array(
'product_id' => $product_info['product_id'],
在其下方添加以下代码行:
'discounts'=>$product_info['discounts'],
现在去 catalog\view\theme\YOUR_ACTIVE_THEME\template\extension\module\featured.tpl
找到以下代码行:
<div class="button-group">
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
在其上方或您想要显示但需要在产品数组内的任何位置添加:
<?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 } ?>
您可以在 Show Discounts at featured module Ocmod OpenCart 2.3.02
下载 ocmod
我是 Opencart 的新手,我想在特色产品中显示数量折扣 - 但没有成功。我正在使用 Opencart 2.3。基本上,我想要实现的是将变量 quantity
和 price
从控制器文件 featured.php
传递到视图文件 featured.tpl
.
这是我尝试过的:
1) 在文件/catalog/controller/extension/module/featured.php
中$product_info = $this->model_catalog_product->getProduct($product_id);
之后添加了如下代码:
$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) 在文件 /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 } ?>
非常感谢任何帮助!
我尝试了其他几种代码变体(例如提供的解决方案 here),但没有成功。
转到catalog\language\en-gb\extension\module\featured。php 添加以下代码:
$_['text_discount'] = ' or more ';
转到catalog\controller\extension\module\featured。php 查找以下代码行:
$data['heading_title'] = $this->language->get('heading_title');
添加以下代码行:
$data['text_discount'] = $this->language->get('text_discount');
找到以下代码行:
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
添加以下代码行:
$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'])
);
}
找到以下代码行:
$data['products'][] = array(
'product_id' => $product_info['product_id'],
在其下方添加以下代码行:
'discounts'=>$product_info['discounts'],
现在去 catalog\view\theme\YOUR_ACTIVE_THEME\template\extension\module\featured.tpl
找到以下代码行:
<div class="button-group">
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');">
在其上方或您想要显示但需要在产品数组内的任何位置添加:
<?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 } ?>
您可以在 Show Discounts at featured module Ocmod OpenCart 2.3.02
下载 ocmod