Jump to content

Display lowest price in product-list.tpl


Recommended Posts

Hi.
 
I'm trying to display the lowest price available from an product on the product list page. (with quantity discounts)
Like this: agile-prestashop-quantity-discount-indic
 
 
 
 
I created a CategoryController.php override file with this code:

<?php

class CategoryController extends CategoryControllerCore
{

public function initContent()
{
    parent::initContent();
     
    if($this->cat_products) {
 
        $id_customer = (isset($this->context->customer) ? (int)$this->context->customer->id : 0);
        $id_group = (isset($this->context->customer) ? $this->context->customer->id_default_group : _PS_DEFAULT_CUSTOMER_GROUP_);
        $id_country = (int)$id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT');
        $id_currency = (int)$this->context->cookie->id_currency;
        $id_shop = $this->context->shop->id;
 
  
        foreach ($this->cat_products as $key => $product) {
 
            $prices_array = array();
 
            /* For each product, grab quantity discounts */
            $quantity_discounts = SpecificPrice::getQuantityDiscounts($product['id_product'], $id_shop, $id_currency, $id_country, $id_group, null, true);
             
			

/* Process quantity discounts to get the real price */
 
if ($quantity_discounts)
{
    foreach ($quantity_discounts as $qkey => $discount) {
         
        if (!(float)$discount['reduction'])
            $price = $discount['price'];
        else {
            if ($discount['reduction_type'] == 'percentage')
            {
                $price = $product['price_without_reduction'] - ($product['price_without_reduction'] * $discount['reduction']);
            }
            else {
                $price = $product['price_without_reduction'] - $discount['reduction'];                         
            }
        }
 
        $prices_array[] = $price;
 
    }

$this->cat_products[$key]['price'] = min($prices_array);
$this->cat_products[$key]['qt_disc'] = true;

} // end if quantity discounts

$this->context->smarty->assign('products', $this->cat_products);
        }
    }
}

}

In my TPL file I put this code:

{* ADDED BELOW  -- SHOW PRICE *}

{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}
    <span class="price" style="display: inline;">
        {if isset($product.qt_disc)}
            {l s='Vanaf'}
        {/if}
        {if !$priceDisplay}
            {convertPrice price=$product.price - $product.attribute_price}
        {else}
            {convertPrice price=$product.price_tax_exc - $product.attribute_price}
        {/if}
    </span><br />
{/if}

But the lowest price is not displayed.

The tpl code is working, but I expect that somethings wrong in the override file.

 

Anyone an idea?

Link to comment
Share on other sites

Hi Nemo.

 

Results:
 

array(0) { } array(1) { [0]=> float(1.9834) } array(2) { [0]=> float(1.9834) [1]=> float(2.0256) } array(0) { } array(1) { [0]=> float(1.9834) } array(2) { [0]=> float(1.9834) [1]=> float(2.0256) } array(0) { } array(1) { [0]=> float(2.4534) } array(2) { [0]=> float(2.4534) [1]=> float(2.5056) } array(0) { } array(1) { [0]=> float(2.4534) } array(2) { [0]=> float(2.4534) [1]=> float(2.5056) } array(0) { } array(1) { [0]=> float(2.4534) } array(2) { [0]=> float(2.4534) [1]=> float(2.5056) } array(0) { } array(1) { [0]=> float(2.8294) } array(2) { [0]=> float(2.8294) [1]=> float(2.8896) } array(0) { } array(1) { [0]=> float(2.8294) } array(2) { [0]=> float(2.8294) [1]=> float(2.8896) } array(0) { } array(1) { [0]=> float(2.8294) } array(2) { [0]=> float(2.8294) [1]=> float(2.8896) } ­

I checked the last product. It got 3 discount quantities:
I checked the array and values:

 

These prices are correct.

 array(3) { [0]=> float(2.8294) [1]=> float(2.8896) [2]=> float(2.9498)

Somehow it still shows €3.01 - 0.12 (attibute price) = €2.89 on the product-list

instead the 2.8294 -> 2.83

 

Im using Prestashop 1.5.6.1 (forgot to tell)

Link to comment
Share on other sites

  • 2 months later...
×
×
  • Create New...