Anmol singh
Anmol singh

Reputation: 158

Show special price discount % in Opencart:2.3.0.2

I want to Show special price discount % on category page(product listing) as well as product page. Like

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

But how can we fetch the price without currency code on product as well category page? Or

May be we can also fetch selected currency, and then exclude it from $price and $special. Thanks in Advance.

Upvotes: 1

Views: 722

Answers (2)

Mujahid Bhoraniya
Mujahid Bhoraniya

Reputation: 1584

1. Category Controller :

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

A. find this line

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

after add

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

B. find this line

$special = false;

after add

$disPercentage = false;

C. find this line

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

after add

'disPercentage' => $disPercentage,

2. Category View Page:

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

A. find this line

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

after add

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

Product Listing Screenshot :

3. Product Controller :

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

A. find this line

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

after add

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

B. find this line

$data['special'] = false;

after add

$data['disPercentage'] = false;

4. Product View Page :

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

A.find this line

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

after add

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

Product page Screenshot

Upvotes: 1

K. B.
K. B.

Reputation: 1430

in the corresponding controller file find:

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

replace with:

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

The same with a special price...

Upvotes: 0

Related Questions