Jump to content

Display lowest price on product list.


Recommended Posts

I have a question, I have products work with quantity by discount.
eg. 1 quantity is standard € 2.25
but by 10 quantity’s the price for one = € 2.00

Is it possible to display the lowest price in the product list in this case € 2.00 ?

Customers see than immediately the lowest price, and that’s what counts.

I hope somebody can help me with this and understand this.

Stefan

Link to comment
Share on other sites

This is a tricky problem. I think I've found a solution though. Add the following code after line 59 of category.php in the root of PrestaShop v1.3.1 (the $cat_products = line):

for ($i = 0; $i < sizeof($cat_products); $i++)
{            
   $quantity_discounts = QuantityDiscount::getQuantityDiscounts(intval($cat_products[$i]['id_product']), $cat_products[$i]['price']);
   $from_price = $cat_products[$i]['price'];

   foreach ($quantity_discounts as $quantity_discount)
       if ($quantity_discount['real_value'] < $from_price)
           $from_price = $quantity_discount['real_value'];

   if ($from_price != $cat_products[$i]['price'])        
       $cat_products[$i]['from_price'] = $from_price;
}



then change line 18 of product-list.tpl in your theme's directory from:

{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}



to:

{if $product.from_price}{l s='From'} {convertPrice price=$product.from_price}{else}{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}{/if}



This will display "From $xx.xx" for products with quantity discounts and just "$xx.xx" for products without quantity discounts. It will pick the quantity discount that results in the lowest per-unit price.

Note that this will work for the category listings only. To do this for the featured products, search results and other prices will require similiar modifications to other files.

Link to comment
Share on other sites

Ok , maybe is this idea a simple solution:

Make a new input field in the backoffice on the add product / change product pages.
I can fill in there the price what I like to display in the product-list.

So that I can decide on that way what I like to display in the product-list?

Link to comment
Share on other sites

That's no easier, since it still requires creating a new field. The easiest way would be to put the price in another field, depending on which fields you are using. For example, you could use the "Wholesale price" field, then change product-list.tpl to read the wholesale price instead of the price. If you are already using that field, you could use the Location field instead.

Link to comment
Share on other sites

Change line 18 of product-list.tpl from:

{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}



to:

{if $product.location|intval > 0}{convertPrice price=$product.location|intval}{elseif !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}

Link to comment
Share on other sites

Oops, my mistake. Try the following instead:

{if $product.location|floatval > 0}{convertPrice price=$product.location|floatval}{elseif !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}

Link to comment
Share on other sites

Rocky,

Thanks, that part works fine right know! (I will soon make a donation to you).
My last question and last part, maybe you can help me also with this (small) problem:

I work with the module: quantity discounts

But it works without taxes, so the prices with quantity discount displays not right.

The part of the code from the module which display the prices etc:

function writeDiscountsContent(price) {ldelim}
   var discountStr = "
";
   var discountedPrice = 0;

   {foreach from=$qd_quantity_discounts item='qd_quantity_discount' name='quantity_discounts'}
       discountStr += "{$qd_quantity_discount.quantity|intval} ";
       {if $qd_quantity_discount.quantity|intval > 1}
           discountStr += "{l s='quantities' mod='quantitydiscounts'}: ";
       {else}
           discountStr += "{l s='quantity' mod='quantitydiscounts'}: ";
       {/if}
       {if $qd_quantity_discount.id_discount_type|intval == 1}
           discountedPrice = price - (price * {$qd_quantity_discount.value} / 100);
       {else}
           discountedPrice = price - {$qd_quantity_discount.value}; 
       {/if}
       discountStr += formatCurrency(discountedPrice, currencyFormat, currencySign, currencyBlank) + "
";
   {/foreach}        
   discountStr += "
";




maybe you have the solution or somebody else...
I have contact the module maker but he is on holiday and I need this very soon.

Link to comment
Share on other sites

  • 3 months later...

Rocky.

Thanks for you help with my previous question above.

I need also display the location in the new_order mail in the module Mailalerts.

When I add this in the codes into mailalerts.php it willn't work..:

'{location}' => $product['location']->location(),  

(line 158)

I also add this code:

'.$product['location'].'

line 112

You solved my previous question also, so I hope that you can help me again.

Thanks.

Link to comment
Share on other sites

It's not that easy, since PrestaShop doesn't store the location of the products with the order. You will have to add extra code to get the location. Change lines 107-108 of modules/mailalerts/mailalerts.php from:

foreach ($params['cart']->getProducts() AS $key => $product)
{



to:

foreach ($params['cart']->getProducts() AS $key => $product)
{
   $productObj = new Product(intval($product['id_product']), false, $id_lang);



Then you can use $productObj->location in the foreach loop to display the product's location.

Link to comment
Share on other sites

The codes that you tell me, I try:

foreach ($params['cart']->getProducts() AS $key => $product)
{
   $productObj = new Product(intval($product['id_product']), false, $id_lang); 



And this one for the display.

'.$product['location'].'



Will not working...

Link to comment
Share on other sites

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