NewUser
NewUser

Reputation: 13333

Opencart show discount price in product featured page

I am new to the opencart. I have setup featured product in my homepage. So when one will visit he can see all the featured product with its description. Now here in this featured page I have shown the product price by using <?php echo $product['price']; ?>. It is showing the product price without any problem. Now I want to show the product discounts in the featured page. So how to do that? Any help and suggestion will be highly appreciable.

Upvotes: 3

Views: 6448

Answers (2)

teja. sandela
teja. sandela

Reputation: 55

Finally, in catalog/view/theme//template/module/featured.tpl add this wherever you want it to display:


enter image description here

Upvotes: 0

Stann0rz
Stann0rz

Reputation: 667

Untested, but should work in theory.

First, in catalog/language/english/module/featured.php add the following line:

$_['text_discount']     = '%s or more %s';

Next, in catalog/controller/module/featured.php do the following:

After $this->data['button_cart'] = $this->language->get('button_cart'); add:

$this->data['text_discount'] = $this->language->get('text_discount');

After $product_info = $this->model_catalog_product->getProduct($product_id); add:

$discounts = $this->model_catalog_product->getProductDiscounts($product_id);
$product_discounts[] = array(); 

foreach ($discounts as $discount) {
    $product_discounts[] = array(
        'quantity' => $discount['quantity'],
        'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
    );
}

After 'href' => $this->url->link('product/product', 'product_id=' . $product_info['product_id']), add:

'discounts'  => $product_discounts

Finally, in catalog/view/theme/<theme>/template/module/featured.tpl add this wherever you want it to display:

<?php foreach ($product['discounts'] as $discount) { ?>
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?><br />
<?php } ?>

Upvotes: 3

Related Questions