Jump to content

Show "from X$" When Quantity Discount


Recommended Posts

Does someone know a way to get prestashop (1.5.3) to show "from X$" instead of showing the highest price on productlist, home featured and product page when I have quantity discount enabled?

 

The customer is usually interested in the lowest possible price instead of the highest.

THanks in advance!

Link to comment
Share on other sites

Hi there,

i did it for a customer some time ago. Quantity discounts are not assigned in the product list, therefore you need to get them with a function in a categorycontroller.php override.

 

For each cat_products there after processing the parent process() function, use something like this

 

$qty_discounts = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
					SELECT id_group, price, from_quantity, reduction, reduction_type
					FROM '._DB_PREFIX_.'specific_price
					WHERE id_product ='.$product['id_product'].'
					AND from_quantity > 1
					AND id_group '.$sqlGroups.'
					ORDER BY from_quantity ASC');

 

You can further process them and remove quantity. This is the most flexible way, since also takes percentages in consideration (you can't just use a SQL query with MIN/MAX in this case!).

 

Then, in the template, you can use something like this:

 

   {foreach from=$product.qty_discounts item=qt_disc}
	<tr>
	 <td>{$qt_disc.from_quantity} {l s='Units'}</td>
	 {$qty_taxed = ($qt_disc.price/100)*$product.rate}
	 {math equation= "a + b" a=$qt_disc.price b=$qty_taxed assign=correct_disc}
	 <td>{convertPrice price=$correct_disc}</td>
	 {if $correct_disc < $product.price} {$product.price = $correct_disc}{$product.price_tax_exc = $correct_disc}{/if}
	</tr>
   {/foreach}

To basically assign the lowest price to the product price.

 

It's just copied/pasted from mine, you'll of course need to adapt it. It's just meant to show you the process vaguely :)

Edited by Nemo1 (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 10 months later...

Im using this great script by Nemo but since upgrade to 1.5.6.2 I havent been able to get it to work on home featured products.

Is there someone who have it on home featured and not only product-list and would like to be so kind to write their solution here? :)

Would really appriciate it :)

 

(This is the script im talking about: http://nemops.com/lowest-price-prestashop-product-list/#.UvPDg3ewbDE

Link to comment
Share on other sites

No, no error at all. Its working flawlessly at product-list but I havent been able to come up with the right solution to apply the rule to the price variable in home featured also :/

Step 3 in your guide is not exactly doable in the same way since home feautred price looks a bit different. I dont really get wich parts I need to add to the override controller to :/ 

Link to comment
Share on other sites

yes I did. But is it just to apply the same code:

{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='From'}
        {/if}
        {if !$priceDisplay}
            {convertPrice price=$product.price}
        {else}
            {convertPrice price=$product.price_tax_exc}
        {/if}
    </span><br />
{/if}

to homefeatured.tpl?

 

I guess its these lines I should replace then?

{if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
					<p class="price_container">
						<a href="{$product.link|escape:'html'}" title="{$product.name|escape:html:'UTF-8'}" class="price" >
							{if !$priceDisplay}
								{convertPrice price=$product.price}
							{else}
								{convertPrice price=$product.price_tax_exc}
							{/if}

Is there any additional lines that needs to be added to override except the ones mentioned in your guide?

Link to comment
Share on other sites

No worries,

I mean part 1 and 2. copy it inside the hookHome function after products are retrieved, and simply swap the name from $this->cat_products to products ;)

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


/* TRYING TO APPLY TO HOME FEATURED ALSO */
if($this->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->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);


/* trying to apply step 2 to homefeatured also */

/* 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->products[$key]['price'] = min($prices_array);
$this->products[$key]['qt_disc'] = true;
} // end if quantity discounts
$this->context->smarty->assign('products', $this->products);


} // close the foreach
}
}
}

Ive tried to add step 1 and step 2. Step 1 works fine (if I try to save and reload the page).

However after adding step 2 it breaks the layout of for example product-list.tpl and prevents it from loading correctly.

Did I add step 2 incorrect in some way?

Huge thanks for helping me :)

 

 

Edited by prestalearn (see edit history)
Link to comment
Share on other sites

No no no.

You have to put that 'trying to apply code' inside homefeatured.php, hookHome function ;)

Oh thank you I finally got it to work now :)

Since prestashop has some kind of bug and displays quantity discount set for each currency (to avoid negative price on quantity products) all my quantity prices "from xxx" is displayed ex vat. Is it easy to show this with vat?

 

(Just to clarify: If I add a general discount in my default currency it shows inc vat. But to avoid negative price on currency discounts I need to set discount for each currency individually and then it doesnt display inc vat)

Link to comment
Share on other sites

I understand. Do you think one of these options perhaps could be a workaround?

 

1. Make the price parameter (lowest possible price) in home featured and product-list get multiplied with the current VAT? For example my VAT is 25% so it should take price*1,25?

 

or

 

2. Make the price parameter (lowest possible price) in home featured and product-list get hardcoded and multiplied with 1,25?

This will cause wrong price for countries i sell without vat to but at least its better than all pricec wrong :)

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...