在 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 中排除。 提前致谢。

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

$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);

同款特价...

1.类别控制器:

File Path : catalog\controller\product\category.php

一个。找到这条线

$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);

乙。找到这条线

$special = false;

添加后

$disPercentage = false;

摄氏度。找到这条线

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

添加后

'disPercentage' => $disPercentage,

2。类别视图页面:

File Path : catalog\view\theme\default\template\product\category.tpl

一个。找到这条线

<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。产品总监:

File Path : catalog\controller\product\product.php

一个。找到这条线

$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);

乙。找到这条线

$data['special'] = false;

添加后

$data['disPercentage'] = false;

4.产品查看页面:

File Path : catalog\view\theme\default\template\product\product.tpl

A.find这一行

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

添加后

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