I would like to ask for your help because this thing is driving me crazy.
I have opencart 2.1.0.2 with journal2 theme installed and I have modified product.php and product.tpl in order to show the percentage of the discounted price of a special product in product page (see attachment).
The code I have used in product.php is the following:
Code: Select all
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
//my code
$data['priceInt'] = $this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'));
//------------my code
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
//------------my code
$data['specialInt'] = $this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'));
$data['specialSavings'] = round((($data['priceInt']-$data['specialInt'])/$data['priceInt'])*100, 0);
if ( $data['specialSavings'] >= 23 && $data['specialSavings'] <= 27 )
{
$data['specialSavings'] = 25;
}
else {
$data['specialSavings'] = 20;
}
//my code
In product.tpl I have this code in order to show the percentage:
Code: Select all
<li class="product-price"><?php echo $price; ?></li>
<?php } else { ?>
<li class="price-old"><?php echo $price; ?></li>
<li class="price-new"><?php echo $special; ?></li>
<!---------my code starts -------------->
<li><h1 style="color:red;"> -<?php echo $specialSavings; ?>%</h1></li>
Now, when I try to implement the same code in category.php, I face 2 problems:
1) In homepage where I have set all products to be shown, in first page afte the total 2 pages of pagination, works fine! When I click on the second page, the percentage is dissapeared!
2) I f I click on a subcategory, the percentage is shown wrong e.g. it may be 26% and it shows 20% as if the part of the following code doesn't work:
Code: Select all
if ( $data['specialSavings'] >= 23 && $data['specialSavings'] <= 27 )
{
$data['specialSavings'] = 25;
}
else {
$data['specialSavings'] = 20;
}
Thanks in advance!