繁体   English   中英

在 Opencart:2.3.0.2 中显示特价折扣 %

[英]Show special price discount % in Opencart:2.3.0.2

我想在类别页面(产品列表)和产品页面上显示特价折扣 %。 喜欢

<h3><?php echo (($price[0]-$special[0])/$price[0])*100 ?>% Discount</h3>

但是我们如何在产品和类别页面上获取没有货币代码的价格? 或者

也许我们也可以获取选定的货币,然后将其从 $price 和 $special 中排除。 提前致谢。

1. 类别控制器:

文件路径:目录\\控制器\\产品\\category.php

A. 找到这一行

$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);

添加后

$disPercentage = ((($result['price']-$result['special'])/$result['price']) * 100);

B. 找到这一行

$special = false;

添加后

$disPercentage = false;

C. 找到这一行

'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,

添加后

'disPercentage' => $disPercentage,

2. 分类查看页面:

文件路径:catalog\\view\\theme\\default\\template\\product\\category.tpl

A. 找到这一行

<h4><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></h4>

添加后

<?php if ($product['special']) { ?>
    <h3 style="color:red;"><?php echo $product['disPercentage']; ?>% Discount</h3>
<?php } ?>

产品列表截图:

3. 产品控制器:

文件路径:目录\\控制器\\产品\\product.php

A. 找到这一行

$data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);

添加后

$data['disPercentage'] = ((($product_info['price']-$product_info['special'])/$product_info['price']) * 100);

B. 找到这一行

$data['special'] = false;

添加后

$data['disPercentage'] = false;

4. 产品查看页面:

文件路径:catalog\\view\\theme\\default\\template\\product\\product.tpl

A.找到这条线

<h1><?php echo $heading_title; ?></h1>

添加后

<?php if ($special) { ?>
   <h3 style="color:red;"><?php echo $disPercentage; ?>% Discount</h3>
<?php } ?>

产品页面截图

在相应的控制器文件中找到:

$data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);

用。。。来代替:

$data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'], true, false);

同样有特价...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM