Jump to content

Display the lowest price of a product inside a category (Prestashop 1.7.8)?


GabrielJic

Recommended Posts

Hello,

Let's say for e.g. I have the category books. There are 12 products in this category.

The lowest price of a "book" is $10 and the highest is $44.

I want to display a custom heading inside the category page, saying "Prices starting from $10", where $10 is the lowest price of a product inside that category.

I want to do this accross all categories/subcategories on the website.

Link to comment
Share on other sites

Disclaimer: Before anyone mentions it, I know smarty isn't intended to be used for calculations etc. This could be done in a much better way with some overrides or a module, but for the sake of a quick and easy solution....

I tried this in templates/catalog/listing/category.tpl and also in templates/catalog/_partials/category-header.tpl and it works 🤷‍♀️

{assign var="lowest_price_formatted" value=""}
{assign var="lowest_price_amount" value=-1}

{foreach from=$listing.products item=product}
    {if $product.price_amount < $lowest_price_amount || $lowest_price_amount == -1}
        {$lowest_price_amount = $product.price_amount}
        {$lowest_price_formatted = $product.price}
    {/if}
{/foreach}

<p>Prices starting from {$lowest_price_formatted}</p>

 

  • Like 1
Link to comment
Share on other sites

On 7/28/2022 at 7:21 PM, lordignus said:

Disclaimer: Before anyone mentions it, I know smarty isn't intended to be used for calculations etc. This could be done in a much better way with some overrides or a module, but for the sake of a quick and easy solution....

I tried this in templates/catalog/listing/category.tpl and also in templates/catalog/_partials/category-header.tpl and it works 🤷‍♀️

{assign var="lowest_price_formatted" value=""}
{assign var="lowest_price_amount" value=-1}

{foreach from=$listing.products item=product}
    {if $product.price_amount < $lowest_price_amount || $lowest_price_amount == -1}
        {$lowest_price_amount = $product.price_amount}
        {$lowest_price_formatted = $product.price}
    {/if}
{/foreach}

<p>Prices starting from {$lowest_price_formatted}</p>

 

That is a quick fix. Thanks. I might make a free module for this. Bacause there are products with combinations and that is hard to do in smarty templates

Link to comment
Share on other sites

Hello, something is wrong with this code because it showing me the same price in all subcategories even though some of them have more expensive products.

I did this https://nemops.com/product-count-price-ranges-subcategories-prestashop-thirtybees 

but have the same results. Showing me correct items count but not price :(

 

image.png

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

17 hours ago, DorianS said:

Hello, something is wrong with this code because it showing me the same price in all subcategories even though some of them have more expensive products.

The code in my previous post works for the intended purpose of showing the lowest priced product in a category on that particlar category's page. What you're trying to do is something different.

Link to comment
Share on other sites

1 hour ago, lordignus said:

The code in my previous post works for the intended purpose of showing the lowest priced product in a category on that particlar category's page. What you're trying to do is something different.

Ok :) have you got maybe any idea, what to make it works in my purpose? :)

Link to comment
Share on other sites

  • 6 months later...
On 7/28/2022 at 4:51 PM, lordignus said:

Disclaimer: Before anyone mentions it, I know smarty isn't intended to be used for calculations etc. This could be done in a much better way with some overrides or a module, but for the sake of a quick and easy solution....

I tried this in templates/catalog/listing/category.tpl and also in templates/catalog/_partials/category-header.tpl and it works 🤷‍♀️

{assign var="lowest_price_formatted" value=""}
{assign var="lowest_price_amount" value=-1}

{foreach from=$listing.products item=product}
    {if $product.price_amount < $lowest_price_amount || $lowest_price_amount == -1}
        {$lowest_price_amount = $product.price_amount}
        {$lowest_price_formatted = $product.price}
    {/if}
{/foreach}

<p>Prices starting from {$lowest_price_formatted}</p>

 

I tested with this code which works on PS 17.. But how to display the biggest price? Thanks for your hel

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