Post by enocea01 » Wed Dec 14, 2016 2:30 am

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!

Newbie

Posts

Joined
Wed Dec 14, 2016 2:23 am

Post by thekrotek » Wed Dec 14, 2016 7:53 am

Product discounts array doesn't have "quantity" index. You should use $product_info for that. Try this:

Code: Select all

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

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by enocea01 » Sun Dec 18, 2016 9:37 pm

It worked! :-) Thanks a lot!

Newbie

Posts

Joined
Wed Dec 14, 2016 2:23 am
Who is online

Users browsing this forum: No registered users and 5 guests