Page 1 of 1

Discount price in Featured products

Posted: Wed Dec 14, 2016 2:30 am
by enocea01
I am new to Opencart and I am trying to display the quantity discount in the featured products - without success. I am using Opencart 2.3. Basically, what I would like to achieve is to pass the variables quantity and price from the controller file featured.php to the view file featured.tpl.
Here is what I have tried:
1) In the file /catalog/controller/extension/module/featured.php after the

Code: Select all

$product_info = $this->model_catalog_product->getProduct($product_id);
I added the following code:

Code: Select all

$discounts = $this->model_catalog_product->getProductDiscounts($product_id);

$data['discounts'][] = array();

foreach ($discounts as $discount) {
    $data['discounts'][] = array(
'quantity' => $discount['quantity'],
'price' => $discount['price']
);
}
2) In the file /catalog/view/theme/default/template/extension/module/featured.tpl I added the following code:

Code: Select all

<?php foreach ($discounts as $discount) { ?>
<span>
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?>
</span><br>
<?php } ?>
Any help would be very much appreciated!

Re: Discount price in Featured products

Posted: Wed Dec 14, 2016 7:53 am
by thekrotek
Product discounts array doesn't have "quantity" index. You should use $product_info for that. Try this:

Code: Select all

'quantity' => $product_info['quantity'],

Re: Discount price in Featured products

Posted: Sun Dec 18, 2016 9:37 pm
by enocea01
It worked! :-) Thanks a lot!