Jump to content

[Solved] How to display price in top seller block


Recommended Posts

How to display price in top seller block?
I manage to configurate new product block but for top sellers block it doesn't work. What is the difirence about this both modules?

There is the code what I used to new product block:

                        {if isset($newproduct.show_price) && $newproduct.show_price && !isset($restricted_country_mode)}{if !$priceDisplay}{convertPrice price=$newproduct.price}{else}{convertPrice price=$newproduct.price_tax_exc}{/if}
{/if}



But this code doesn't work on top seller block, why??

Link to comment
Share on other sites

How to display price in top seller block?
I manage to configurate new product block but for top sellers block it doesn't work. What is the difirence about this both modules?

There is the code what I used to new product block:
                        {if isset($newproduct.show_price) && $newproduct.show_price && !isset($restricted_country_mode)}{if !$priceDisplay}{convertPrice price=$newproduct.price}{else}{convertPrice price=$newproduct.price_tax_exc}{/if}
{/if}



But this code doesn't work on top seller block, why??



Usually this is because certain variables are not created as a smarty variable by the php class (in this case modules/blockbestseller/blockbestseller.php). So the price variable is simply not assigned. You could try to edit the php file (!!! you are changing core module files and will loose the change when upgrading).

Look for this code :
$smarty->assign(array(
           'best_sellers' => $best_sellers,
           'mediumSize' => Image::getSize('medium')));
       return $this->display(__FILE__, 'blockbestsellers.tpl');



And substitute is for this code (UNTESTED)

$smarty->assign(array(
           'best_sellers' => $best_sellers,
           'mediumSize' => Image::getSize('medium'),
           'product_price' => $bestseller['price'] ));
       return $this->display(__FILE__, 'blockbestsellers.tpl');



Then in your template file you can access the price like this: {$product_price}
This is an untested example. You have to figure out if it works correctly. Dont have a good internetconnection here.

Link to comment
Share on other sites


I'm wondering why the code work on new product block module but don't work on best seller block. There is some big difference about those modules?


Did you actually read my post ??
I said, and i quote myself
Usually this is because certain variables are not created as a smarty variable by the php class (in this case modules/blockbestseller/blockbestseller.php). So the price variable is simply not assigned.


If you dont know how Smarty works then you can find info here: http://www.smarty.net/documentation

I doesn’t work.


Duh? I gave you an UNTESTED example. Now you try to improve it. If you dont know how to program php, then search the forum because there are many examples there where you can learn from. Or maybe somebody else has done this before.
Link to comment
Share on other sites

I discover code what displays price :

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


But the price are incorrect, BUT if I use simply {$product.price} it displays correct price, why is that? But also I can't display specific price if product has discount so I anyway need to make it like new product block.

Usually this is because certain variables are not created as a smarty variable by the php class (in this case modules/blockbestseller/blockbestseller.php). So the price variable is simply not assigned.

But why then in newproductblock.php there are no price variables?
Link to comment
Share on other sites

Ok, I found problem! Deleted "Light" in blockbestsellers.php and the code what I used in new product block now works on top seller block.
from:

$bestsellers = ProductSale::getBestSalesLight((int)($params['cookie']->id_lang), 0, 5);


to:

$bestsellers = ProductSale::getBestSales((int)($params['cookie']->id_lang), 0, 5);



But I would like to know- what that line do? And if it's ok to edit that line?
On first look all looks right.

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...
  • 7 months later...

Yes ! Nice job ... getBestSales instead of getBestSalesLight !

I have just override my themes/.../modules/blockbestsellers/blockbestsellers-home.tpl

And have added this to display also specific prices with prices without reduction with "text-decoration: line-through;" ...

{if isset($product.reduction) && $product.reduction && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}
<div class="price_without_reduction">{convertPrice price=$product.price_without_reduction}</div>
{/if}

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...

maann how i can do that but on blocknewproduct ?? i mean, display the price the correct prcice?, i tried but shows me 0.00$ and that is not the actual price

 

What is your code ?

Have you tried this ?

{convertPrice price=$product.price_without_reduction}

 

I use a template override in my theme folder/modules /homefeatured/homefeatured.tpl to display the specific price and the price without reduction

 

{if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
<div class="price_container">
 {if isset($product.reduction) && $product.reduction && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}
 <div style="margin-top:-10px;color:#666;font-size:.8em;font-weight:normal;text-align:right;text-decoration: line-through;">{convertPrice price=$product.price_without_reduction}</div>
 {/if}
 {if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}
</div>
{/if}

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

  • 1 year 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...