Jump to content

1.7 show unit price on category page


folkifoon

Recommended Posts

I would like to show the unit price with the label (per meter for example) when a products has a unite price. Otherwise just show the regular price.

I know the file i have to edit is:

templates/catalog/_partials/miniatures/product_cat.tpl



What code do i need to add to show the unit price?


     {block name='product_price_and_shipping'}
        {if $product.show_price}
          <div class="product-price-and-shipping">
            {if $product.has_discount}
              {hook h='displayProductPriceBlock' product=$product type="old_price"}
              <span class="regular-price">{$product.regular_price}</span>
            {/if}
 
            {hook h='displayProductPriceBlock' product=$product type="before_price"}
 
            <span itemprop="price" class="price">{$product.price}</span>
 
            {hook h='displayProductPriceBlock' product=$product type='unit_price'}
 
            {hook h='displayProductPriceBlock' product=$product type='weight'}
 
          </div>
        {/if}
      {/block} 
Link to comment
Share on other sites

Try:

{$product.unit_price}

I'm afraid, no! PrestaShop stores the net price for a single product. There is no db field for the unit price, just the price ratio is stored. This is why you have to implement an algorithm for the unit price you want to display. Like you see here: https://www.prestashop.com/forums/topic/563489-solved-how-i-show-unitprice-for-my-product-in-a-list-category/?do=findComment&comment=2439629

 

And if this were not enough, since years the developers confuse unit price in the sense of price per unit with unit price in the sense of price of a single product. So you find in Product.php code like this:

 $row['unit_price'] = ($row['unit_price_ratio'] != 0  ? $row['price'] / $row['unit_price_ratio'] : 0);

And in OrderDetail.php or e.g. PaymentModule.php unit price is defined as price per product:

 $this->unit_price_tax_incl = (float)$product['price_wt'];
if (isset($product['price']) && $product['price']) {
    $product_var_tpl['unit_price'] = Tools::displayPrice($product['price'], $this->context->currency, false);
    $product_var_tpl['unit_price_full'] = Tools::displayPrice($product['price'], $this->context->currency, false)
    .' '.$product['unity'];
    } else {
    $product_var_tpl['unit_price'] = $product_var_tpl['unit_price_full'] = '';
}
Link to comment
Share on other sites

i got help and he got it almost to work. Only the strang thing is, it shows the unit price Tax Included on category page, but when i open product page it shows the correct price (tax excluded). Something wrong with the code (mytheme/templates/catalog/_partials/miniatures/product_cat.tpl)
 

{$product.unit_price|replace:'€':''}
{$product.unit_price / 1.21}
—>
		{if $product.unity && $product.unit_price_ratio > 0.000000}
			<span itemprop="price" class="price">{l s='%unit_price%' d='Shop.Theme.Catalog' sprintf=['%unit_price%' => $product.unit_price_full]}</p>
		{else}
			<span itemprop="price" class="price">{$product.price}</span>
		{/if}
Edited by folkifoon (see edit history)
Link to comment
Share on other sites

  • 10 months later...

Hello, 

I have exactly the same problem with my product lists: the unit prices are listed TAX INCLUDED on the category page but on th eproduct page the unit price is TAX EXCL.

Furthermore, I've seen that this code could show Unit prices, but on 1.7, there is an error on the convertPrice function which is unknown: 

{if $product.unit_price_ratio}
        {math equation="b/a" a=$product.unit_price_ratio b=$product.price assign=realunit}
        {convertPrice price=$realunit} {l s="per"} {$product.unity}
    {/if}

 

I'd like to have my unit prices shown as the other prices: with the reduction and tax excluded.

Thanks in advance for any help.

Best Regards,

 

 

 

Link to comment
Share on other sites

  • 8 months later...
  • 6 months later...
  • 1 year later...
  • 2 months later...

hi !

here is a working solution (show unit product price without tax in product list) for prestashop 1.7.6.9 with classic theme (may work with others versions)

 

edit themes/classic/templates/catalog/_partials/miniatures/product.tpl

around line 70 after :

    <span class="sr-only">{l s='Price' d='Shop.Theme.Catalog'}</span>
    <span itemprop="price" class="price">{$product.price} HT</span>

add :
    {if $product.unit_price_full != ""}
         {math assign="result" equation="rprice / ratio" rprice=$product.price_tax_exc ratio=$product.unit_price_ratio}
         <br><span class="unit_price">(soit {$result|string_format:"%.2f"} € HT {$product.unity})</span>
    {/if}

result in product list is (in euros / french) 

   Sable en sac de 2kg
         20,60 € HT
(soit 10,30 € HT le kilo)

 

You have to add some custom CSS to expand the miniature look

in themes/classic/assets/css/custom.css

add :

/* PRODUCTS LIST */
.products .thumbnail-container, .featured-products .thumbnail-container, .product-accessories .thumbnail-container, .product-miniature .thumbnail-container {height:338px;}
.products .thumbnail-container .product-thumbnail, .featured-products .thumbnail-container .product-thumbnail, .product-accessories .thumbnail-container .product-thumbnail, .product-miniature .thumbnail-container .product-thumbnail {height:calc(100% - 90px)}
.products .product-description, .featured-products .product-description, .product-accessories .product-description, .product-miniature .product-description {height:90px;}
.products .highlighted-informations, .featured-products .highlighted-informations, .product-accessories .highlighted-informations, .product-miniature .highlighted-informations {height : 4.125rem}

 

Enjoy !

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

  • 8 months later...
En 18/5/2021 a las 6:54 PM, fcherrier dijo:

hi !

here is a working solution (show unit product price without tax in product list) for prestashop 1.7.6.9 with classic theme (may work with others versions)

 

edit themes/classic/templates/catalog/_partials/miniatures/product.tpl

around line 70 after :

    <span class="sr-only">{l s='Price' d='Shop.Theme.Catalog'}</span>
    <span itemprop="price" class="price">{$product.price} HT</span>

add :
    {if $product.unit_price_full != ""}
         {math assign="result" equation="rprice / ratio" rprice=$product.price_tax_exc ratio=$product.unit_price_ratio}
         <br><span class="unit_price">(soit {$result|string_format:"%.2f"} € HT {$product.unity})</span>
    {/if}

result in product list is (in euros / french) 

   Sable en sac de 2kg
         20,60 € HT
(soit 10,30 € HT le kilo)

 

You have to add some custom CSS to expand the miniature look

in themes/classic/assets/css/custom.css

add :

/* PRODUCTS LIST */
.products .thumbnail-container, .featured-products .thumbnail-container, .product-accessories .thumbnail-container, .product-miniature .thumbnail-container {height:338px;}
.products .thumbnail-container .product-thumbnail, .featured-products .thumbnail-container .product-thumbnail, .product-accessories .thumbnail-container .product-thumbnail, .product-miniature .thumbnail-container .product-thumbnail {height:calc(100% - 90px)}
.products .product-description, .featured-products .product-description, .product-accessories .product-description, .product-miniature .product-description {height:90px;}
.products .highlighted-informations, .featured-products .highlighted-informations, .product-accessories .highlighted-informations, .product-miniature .highlighted-informations {height : 4.125rem}

 

Enjoy !

Hello, I am trying to do something similar but in the "HOME" but I am using the "Warehouse" template and it does not work for me, can someone help me, would I know how to call the "unit price"
PS: PS 1.7.8.3 Warehouse: 4.5.3 and Elementor @4you.software @ventura

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