我想在分类页面(产品列表)和产品页面上显示特殊价格折扣%。喜欢
<h3><?php echo (($price[0]-$special[0])/$price[0])*100 ?>% Discount</h3>但是,在产品和类别页面没有货币代码的情况下,我们如何获取价格呢?或
也许我们也可以获取选定的货币,然后从$price和$special中排除它。提前谢谢。
发布于 2020-01-15 11:57:26
1.类别控制器:
文件路径: catalog\controller\product\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.产品控制器:
文件路径: catalog\controller\product\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.find这条线
<h1><?php echo $heading_title; ?></h1>后加
<?php if ($special) { ?>
<h3 style="color:red;"><?php echo $disPercentage; ?>% Discount</h3>
<?php } ?>

发布于 2020-01-12 15:05:30
在相应的控制器文件中找到:
$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);同样的特别价格..。
https://stackoverflow.com/questions/59695015
复制相似问题