Jump to content

Get "Lowest price" on Block New Products


Plexy89

Recommended Posts

Hi guys,

 

I am overriding CategoryControllerCore with a functionality which shows the "Lowest price" on the product list - e.g. if having quantity discounts. 

 

However, this override does not seem to cover the homenewproducts module - even if this one is using the product-list. And I can't get my head around it.

 

Anyone who can help me out?

 

Here's the CategoryController override I use.

 

Thanks a lot in advance!

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

}
}
}
}
Link to comment
Share on other sites

  • 2 weeks later...
You are overriding the CategoryController, so it only applies to the category pages. It won't apply to the "New Products", "Best Sellers", "Manufacturer" and "Supplier" pages or any modules that call product-list.tpl.

 

You'll need to add additional overrides to cover all those pages. It could be a lot of work.

Link to comment
Share on other sites

  • 2 weeks later...

 

You are overriding the CategoryController, so it only applies to the category pages. It won't apply to the "New Products", "Best Sellers", "Manufacturer" and "Supplier" pages or any modules that call product-list.tpl.
 
You'll need to add additional overrides to cover all those pages. It could be a lot of work.

 

Thanks for the reply rocky.

 

Any idea which one to override for the "New products" tab on home? That's the only one I've got problems with right now.

Link to comment
Share on other sites

I suggest overriding the getNewProducts() function in modules/blocknewproducts/blocknewproducts.php.

Thanks a lot! However, when looking at this I realize it's way over my head.

Is there anyone out there who has done this or can help me out?

 

Thanks in advance!

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...