Jump to content

Display price "from"


Lpeek

Recommended Posts

I have a product that changes price depending on what attributes the user selects. Is there a way to display the price as: "from £##.##" in the category listing and the product page so my customers don't think all sizes are one price?

Link to comment
Share on other sites

You'll need to edit change line 18 of product-list.tpl in your theme's directory (in PrestaShop v1.3) from:

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



to:

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

Link to comment
Share on other sites

You are right. In that case, try:

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



I haven't tested it, but I think it should work.

Link to comment
Share on other sites

thanks again rocky! I appreciate your help! :)

It's on the right track, but again, the products attributes dont always change the price... its only on certain items/attributes. I could see it being a bit complicated... :(

to show exactly what I mean...

I have a sweatshirt which costs £15 and it's available in sizes S, M, L, XL and XXL, but the XXL size costs £1 more. All products will have sizes S, M and L, but not every product will have XXL, so not all products have more than 1 price, so really I need to work on something that finds if an attribute alters the price, and if it does, then display the from string.

I think that makes sense... But like I said, it sounds like it could be quite complex :(

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

I need to do the same, but on Prestashop 1.2.5, where the products-list.tpl is different from the one mentioned in this thread before:

           
                 {if $product.on_sale}
{l s='On sale!'}
               {elseif ($product.reduction_price != 0 || $product.reduction_percent != 0) && ($product.reduction_from == $product.reduction_to OR ($smarty.now|date_format:'%Y-%m-%d' <= $product.reduction_to && $smarty.now|date_format:'%Y-%m-%d' >= $product.reduction_from))}
{l s='Price lowered!'}
               {/if}

               {if !$priceDisplay || $priceDisplay == 2}
{convertPrice price=$product.price}{if $priceDisplay == 2} {l s='+Tx'}{/if}{/if}

               {if $priceDisplay}
{convertPrice price=$product.price_tax_exc}{if $priceDisplay == 2} {l s='-Tx'}{/if}{/if}

               {if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}
{l s='Add to cart'}{else}



Can you please tell me what to change so I can display a "From:" on those products with various prices?
Regards,

Jose

Link to comment
Share on other sites

Just make the same change I did above to both the prices:

{if $product.on_sale}
{l s='On sale!'}
               {elseif ($product.reduction_price != 0 || $product.reduction_percent != 0) && ($product.reduction_from == $product.reduction_to OR ($smarty.now|date_format:'%Y-%m-%d' <= $product.reduction_to && $smarty.now|date_format:'%Y-%m-%d' >= $product.reduction_from))}
{l s='Price lowered!'}
               {/if}

               {if !$priceDisplay || $priceDisplay == 2}
{if $product.id_product_attribute}{l s='from'}{/if} {convertPrice price=$product.price}{if $priceDisplay == 2} {l s='+Tx'}{/if}{/if}

               {if $priceDisplay}
{if $product.id_product_attribute}{l s='from'}{/if} {convertPrice price=$product.price_tax_exc}{if $priceDisplay == 2} {l s='-Tx'}{/if}{/if}

               {if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}
{l s='Add to cart'}{else} 

Link to comment
Share on other sites

Rocky,

That was very helpful.
We were also able to include the "FROM" ("desde" in Spanish) into the SPECIALS (OFERTAS), NEW PRODUCTS (NOVEDADES) module and the FEATURED PRODUCTS block on the Home Page.
You can see them here: http://www.pescashop.com/index.php

The only block where we couldn't put it in was the BEST SELLERS block (LO MAS VENDIDO).
We tried with this code but it doesn't recognize it:

{if $id_product.id_product_attribute }
{l s='desde'}{/if}



Would you know what has to be changed in it to work in this block?
Thanks in advance!

Jose

Link to comment
Share on other sites

You need to change lines 107-110 of the getBestSalesLight function in classes/ProductSale.php from:

SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, i.`id_image`, il.`legend`, ps.`quantity` AS sales, p.`ean13`, cl.`link_rewrite` AS category
FROM `'._DB_PREFIX_.'product_sale` ps 
LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).')



to:

SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, pa.`id_product_attribute`, i.`id_image`, il.`legend`, ps.`quantity` AS sales, p.`ean13`, cl.`link_rewrite` AS category
FROM `'._DB_PREFIX_.'product_sale` ps 
LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1)



Then you can use the following in blockbestsellers.tpl:

{$product.id_product_attribute}

Link to comment
Share on other sites

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

I've done this, it's a bit hard to explain because we've got a custom theme, but below is the php code and template code to get the "from" thing working. Quite a bit of code because it has to check if each attribute affects the price.

In category.php this is what the code looked like "before":

if ($category->id != 1)
       {
           $nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true);
           include(dirname(__FILE__).'/pagination.php');
           $smarty->assign('nb_products', $nbProducts);
           $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay);
       }



and this is what it looks like "now":

if ($category->id != 1)
       {
           $nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true);
           include(dirname(__FILE__).'/pagination.php');
           $smarty->assign('nb_products', $nbProducts);
           $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay);
           foreach($cat_products as &$cat_product){
               $cat_product['all_prices'] = array();
               $product = new Product($cat_product['id_product'], true, intval($cookie->id_lang));
               $cat_product['all_prices'][] = floatval($cat_product['price']);
               $attributesGroups = $product->getAttributesGroups(intval($cookie->id_lang));
               if (Db::getInstance()->numRows())
               {
                   $combinationImages = $product->getCombinationImages(intval($cookie->id_lang));
                   foreach ($attributesGroups AS $k => $row){
                       $cat_product['all_prices'][] = floatval($cat_product['price']) + floatval($row['price']);
                   }
               }
               $diff_prices = array_unique($cat_product['all_prices']);
               array_multisort($diff_prices);
               $cat_product['from_price'] = (count($diff_prices)>1) ? array_shift($diff_prices) : false;
           }
       }




Then in themes/your_theme/product-list.tpl this is what it might have looked like before:

{convertPrice price=$product.price}



and this is what i changed it to.

{if $product.from_price}from {convertPrice price=$product.from_price}{else}{convertPrice price=$product.price}{/if}



Examples:

http://bastbodyjewellery.com.au/7-eyebrow-jewellery
http://bastapparel.com.au/18-punk-accessories

Link to comment
Share on other sites

  • 4 weeks later...
I've done this, it's a bit hard to explain because we've got a custom theme, but below is the php code and template code to get the "from" thing working. Quite a bit of code because it has to check if each attribute affects the price.

In category.php this is what the code looked like "before":

if ($category->id != 1)
       {
           $nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true);
           include(dirname(__FILE__).'/pagination.php');
           $smarty->assign('nb_products', $nbProducts);
           $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay);
       }



and this is what it looks like "now":

if ($category->id != 1)
       {
           $nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true);
           include(dirname(__FILE__).'/pagination.php');
           $smarty->assign('nb_products', $nbProducts);
           $cat_products = $category->getProducts(intval($cookie->id_lang), intval($p), intval($n), $orderBy, $orderWay);
           foreach($cat_products as &$cat_product){
               $cat_product['all_prices'] = array();
               $product = new Product($cat_product['id_product'], true, intval($cookie->id_lang));
               $cat_product['all_prices'][] = floatval($cat_product['price']);
               $attributesGroups = $product->getAttributesGroups(intval($cookie->id_lang));
               if (Db::getInstance()->numRows())
               {
                   $combinationImages = $product->getCombinationImages(intval($cookie->id_lang));
                   foreach ($attributesGroups AS $k => $row){
                       $cat_product['all_prices'][] = floatval($cat_product['price']) + floatval($row['price']);
                   }
               }
               $diff_prices = array_unique($cat_product['all_prices']);
               array_multisort($diff_prices);
               $cat_product['from_price'] = (count($diff_prices)>1) ? array_shift($diff_prices) : false;
           }
       }




Then in themes/your_theme/product-list.tpl this is what it might have looked like before:

{convertPrice price=$product.price}



and this is what i changed it to.

{if $product.from_price}from {convertPrice price=$product.from_price}{else}{convertPrice price=$product.price}{/if}



Examples:

http://bastbodyjewellery.com.au/7-eyebrow-jewellery
http://bastapparel.com.au/18-punk-accessories



So nice, it works on my shop
Link to comment
Share on other sites

  • 1 month later...

Hi Rocky I'm using 1.3.2.3 final and the prodcut-list.tpl code is once again different.

>{if isset($products)}
   <!-- Products list -->
</pre>
<ul>
   {foreach from=$products item=product name=products}


getImageLink($product.link_rewrite, $product.id_image, 'home')}" alt="{$product.legend|escape:'htmlall':'UTF-8'}" width="{$homeSize.width}" height="{$homeSize.height}" />
{if $product.new == 1}{l s='new'}{/if}{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}

{$product.description|truncate:360:'...'|strip_tags:'UTF-8'}
                                                                                 

           {$product.reference}
               {if $product.on_sale}
{l s='On sale!'}
               {elseif ($product.reduction_price != 0 || $product.reduction_percent != 0) && ($product.reduction_from == $product.reduction_to OR ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $product.reduction_to && $smarty.now|date_format:'%Y-%m-%d %H:%M:%S' >= $product.reduction_from))}
{l s='Price lowered!'}
               {/if}

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

{if ($product.quantity > 0)}{l s='Available'}{else}{l s='Out of stock'}{/if}

               {if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}
{l s='Add to cart'}
               {else}
{l s='Add to cart'}
               {/if}
{l s='View'}


   {/foreach}
</ul>
<br>   <!-- /Products list --><br



Any idea what change I'd need to make to get the 'from' to show only on items with attributes?

Thanks
Baz

Link to comment
Share on other sites

  • 5 months later...
  • 2 months later...
  • 2 years later...
  • 5 months later...

You'll need to edit change line 18 of product-list.tpl in your theme's directory (in PrestaShop v1.3) from:

 

<span class="price" style="display: inline;">{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span>

to:

 

<span class="price" style="display: inline;">{l s='from'} {if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span>

Ok, now I can show "From" before price... but can I display the lowest price if I have a quantity discount?

 

PS version 1.4.11

Link to comment
Share on other sites

  • 3 weeks later...

On my site I need to display 'From £' prices for products that have multiple options that change the price only.

 

For example, a bag of 2kg dog food is £5.99 which is the cheapest, then a 10kg bag is £13.99.

 

 

If I have products that come in a different colour but not there is no change to the price, I don't need it to display a 'From £' price.

 

I hope this makes sense and hopefully someone can give me a solution that works.

 

Cheers.

 

I'm using PS v1.4.9

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

  • 1 month later...

On my site I need to display 'From £' prices for products that have multiple options that change the price only.

 

For example, a bag of 2kg dog food is £5.99 which is the cheapest, then a 10kg bag is £13.99.

 

 

If I have products that come in a different colour but not there is no change to the price, I don't need it to display a 'From £' price.

 

I hope this makes sense and hopefully someone can give me a solution that works.

 

Cheers.

 

I'm using PS v1.4.9

Also want this on my 1.4.9 prestashop site, from price is a must you would of thought.

Link to comment
Share on other sites

  • 2 weeks later...

On my site I need to display 'From £' prices for products that have multiple options that change the price only.

 

For example, a bag of 2kg dog food is £5.99 which is the cheapest, then a 10kg bag is £13.99.

 

 

If I have products that come in a different colour but not there is no change to the price, I don't need it to display a 'From £' price.

 

I hope this makes sense and hopefully someone can give me a solution that works.

 

Cheers.

 

I'm using PS v1.4.9

maybe someone has a solution for PS v1.5.x, really need to display "from" before product price in products list, where not only are the combinations, but their prices are different. If product has several combinations, but their prices are the same, do not to display "from".

 

Thanks

Link to comment
Share on other sites

  • 1 year later...
  • 2 years later...

You are right. In that case, try:

 

<span class="price" style="display: inline;">{if $product.id_product_attribute}{l s='from'}{/if} {if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span>

I haven't tested it, but I think it should work.

 

 

Hi everyone,

 

that code works well, :D

but does enybody know, how to change scope from

{if $product.id_product_attribute} {l s='from'} {/if} // which displays "from" to all products with any attributes

to

display "from" only for a product with a specific, for ex. my id_feature_value == 4258 ?

I tried some codes but none "from"displayed :(

{if $product.id_feature_value == 4258} {l s='from'} {/if}
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...