Jump to content

[FREE TUTORIAL] Show the lowest price (from xx$) in product list


NemoPS

Recommended Posts

Hey everybody!

I just finished writing a short tutorial on how to aklways display the lowest possible price in product list. This means that you will be able to display from 12$ for example, if one of you products costs 12$ when bought in stock; even in the original price is different.

 

Really useful for wholesales and office suppliers

 

Here: http://nemops.com/lowest-price-prestashop-product-list/

 

 

Cheers!

Fabio

Link to comment
Share on other sites

  • 8 months later...
  • 2 months later...
  • 1 month later...

Is there a way to show "From $xx" just for products that have multiple combinations. My site has a few product items that have multiple sizes. The sizes greatly vary in price. Currently, the product list shows it as the lowest price, but it doesn't say "From" so it could be very misleading for people. I would only need it to say "From" only in this circumstance. Not needed for every product listing.

 

Thanks!

Link to comment
Share on other sites

  • 3 weeks later...

Thanks! But there is a problem with taxes. You never change price_tax_ecl. value. So, if you need to display it in your template, the value is false.

 

And actually, I display prices with tax in my shop, and the lowest price calculate is without tax.

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

  • 2 months later...

Yes, I have two customer groups. "Customer" and "Reseller".

The customer get the prices with tax and everything is fine with the lowest price.

But the reseller get the prices without tax and he see the single prices, not the lowest prices.

Link to comment
Share on other sites

Good morning,

 

yes they apply to all customer groups, all customer, all countries.

Just currency is used on "Euro" but there is only euro in the shop at the moment.

 

If I change the reseller group tp "with tax", everything is fine. Only if I change it to "without tax" the minimum prices can´t get shown.

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

In product_list.tpl, there is a part:

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

 Is it possible that your tutorial only takes a change on ".price"?

Do I have to do the whole tutorial again but with ".price_tax_exc" instead of ".price"?

 

Only ad the last line again like this doesn´t run. It get negative prices than.

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

$this->cat_products[$key]['price_tax_exc'] = min($prices_array);

$this->cat_products[$key]['qt_disc'] = true;
Edited by Shad86 (see edit history)
Link to comment
Share on other sites

On the shop top it says: float(3.61) float(19.54) string(9) "-1.000000" float(50.96) float(-7.57) float(34.03)

Don´t know what it means.

 

Edit: These are the prices of the products in this category... Did I put it in the right place?

 

 

I can put some screenshot on my post if you want, I calculate the whole time but I can´t get the price it shows if I put in the line:

$this->cat_products[$key]['price_tax_exc'] = min($prices_array);

It does something but I don´t know what. Without tax, the price is 46,81€. The lowest quantity price is 10,51€. But it shows 3,61€ in the product list...

I try to understand what it does to maybe fix it.

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

I understand now...

It simply take the price without tax minus the lowest discount price.

BUT this can make negative prices.

I have to put in new prices especially for the reseller group.

That runs. It´s a pity that the lowest discount price calculation doen´t run for them too...

Link to comment
Share on other sites

Sure:

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);
       var_dump(min($prices_array));
 $this->cat_products[$key]['price_tax_exc'] = min($prices_array);
$this->cat_products[$key]['qt_disc'] = true;
Edited by Shad86 (see edit history)
Link to comment
Share on other sites

If the price get calculated minus the discount prices without tax (that are shown in the product), everything would be ok.

But it uses the discount prices with tax, so it can calculate negative prices...

 

I can´t enough PHP but isn´t it possible to add an "if than else" command?

Something like:

 

if (['price_tax_exc'])
            $price = $discount['price_tax_exc'];
        else {
             $price = $product['price_without_reduction'] - $discount['price_tax_exc'];    }                    

 

or something like this?

I mean that it calculate with the discounts without tax, not the discounts with tax.

The table in the product calculate the discounts with and without tax like it should. So I think it must be possible on one way.

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

  • 2 months later...

Very useful tutorial. It works on 1.6.0.8. If we show the lowest price from on product list page it would also be good to show it on product comparison. I can't make it to work though.

 

Am I right in thinking that it should be done by adding CompareController.php to overrides with the code provided and modify products-comparison.tpl? Please help...

Link to comment
Share on other sites

Yes, you are right, that should be the way. Check if the override is working in the first place, like by adding die('test'); in the method you override. Just to see if it's working

Hello and thank you for this tuto

I am on 1.6.06 and doc if I understand well it is necessary to replace:

{if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}
<span itemprop="price" class="price product-price">
{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
</span>
 
By this code:
 
{If isset ($ product.show_price) && $ product.show_price && isset ($ restricted_country_mode)!} < durée classe = "prix" de style = "display: inline;" > {ls = 'From'} {if $ priceDisplay! } {convertPrice prix = $ product.price} {autre} {convertPrice prix = $ product.price_tax_exc} {/ if} </ durée > < br /> {/ if}
 
Is it?. Thank you
Link to comment
Share on other sites

uh? no, that second snippet you pasted is all wrong, this is the one

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

Link to comment
Share on other sites

Nemo1. Yes. The override file is working but I believe the content of it needs to be altered in order to work for product comparison, for example the last line of your code to "reassign the product list with our corrected prices":
 
$this->context->smarty->assign('products', $this->cat_products);
 
I am not good at coding and don't know what needs to be changed here. Also, in the code that you provided for override file there are more fragments that refer to "cat_products". Not sure if this would work for CompareController.php

Link to comment
Share on other sites

It looks that there is more going on within function initContent() in CompareController.php than in CategoryController.php. I tried to add the code to CompareController.php but it didn't work for me. Where exactly would you add the code? Has anyone achieved displaying 'price from' on product comparison? I would appreciate help with this...

Link to comment
Share on other sites

  • 5 months later...

Dear Nemo1,

 

and where do I have to put it in?

Before the: $this->cat_products[$key]['price_tax_exc'] = min($prices_array); ??

 

Hello Shad86,

same question here!

 

I gave to display minimum price from classic User Group who have display tax ON (that is okay), and for Pro Group who have display tax OFF.

Have you reach that ?

Thanks!

Link to comment
Share on other sites

Its a long time ago...

We have an issue with don´t displaying the tax. I think it was because of our "from" price. It shows minus prices than because the price without tax minus prices with tax.

So we decided to show tax everytime and it´s ok for us.

Link to comment
Share on other sites

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

No i didnt, i bough the module for it.

The module name is Agile quantity discount indicator.

It work on my presta 1.6.1.4 but well, it's a pay module.

 

Thanks for your answer, I will look into because can't get the tutorial get to work either. 

Link to comment
Share on other sites

  • 1 month later...

Hi everyone!!

It worked perfectly for me with 1.6.1

 

but i have a little problem>

i'd like to show same discounted price also in "new products" "homefeatured"

CAN I?

 

http://www.magliettepersonalizzate.info
(home not working)

http://www.magliettepersonalizzate.info/index.php?id_category=13&controller=category
(working good)

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

You can basically apply the same procedure to them, but you might have to remove caching from these modules before, otherwise you won't see you changes take place

Ciao NEMO ;)

 

it's not totally clear what you mean ( cause i'm not expert in php )

i should modify other .tpl ? (for example in modules interested -newproducts, homefeatured-)

i should add more override controllers?

and about removing caching from these modules before i can't understand  what i have to do :((

 

sorry cause i'm a nub

hope you have patience  to explain me step by step

pm me (also italian) if you think we go offtopic here

sorry for disturbing again

Link to comment
Share on other sites

  • 2 weeks later...

On Prestashop 1.6.5 you can use "hookActionProductListModifier" in your module. This way, it's also working with Blocklayered module.

public function hookActionProductListModifier($params)
{
	if (isset($params['cat_products']) && ! empty($params['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 ($params['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);

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

				$params['cat_products'][$key]['price_tax_exc'] = min($prices_array);
				$params['cat_products'][$key]['qt_disc'] = true;
			}
		}
	}
}
Edited by Mangateur (see edit history)
Link to comment
Share on other sites

 

On Prestashop 1.6.5 you can use "hookActionProductListModifier" in your module. This way, it's also working with Blocklayered module.

public function hookActionProductListModifier($params)
{
	if (isset($params['cat_products']) && ! empty($params['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 ($params['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);

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

				$params['cat_products'][$key]['price_tax_exc'] = min($prices_array);
				$params['cat_products'][$key]['qt_disc'] = true;
			}
		}
	}
}

wich module?

where i should add the code you paste?

sorry cause i'm really newbie i'm learning step by step while making my website http://www.magliettepersonalizzate.info

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

  • 8 months later...
  • 10 months 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...