GabrielJic Posted July 28, 2022 Share Posted July 28, 2022 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 More sharing options...
lordignus Posted July 28, 2022 Share Posted July 28, 2022 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> 1 Link to comment Share on other sites More sharing options...
GabrielJic Posted July 28, 2022 Author Share Posted July 28, 2022 It did the job, apparently! Thank you, @lordignus! Link to comment Share on other sites More sharing options...
Ali Samie Posted July 29, 2022 Share Posted July 29, 2022 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 More sharing options...
DorianS Posted August 3, 2022 Share Posted August 3, 2022 (edited) 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 Edited August 3, 2022 by DorianS (see edit history) Link to comment Share on other sites More sharing options...
lordignus Posted August 4, 2022 Share Posted August 4, 2022 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 More sharing options...
DorianS Posted August 4, 2022 Share Posted August 4, 2022 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 More sharing options...
Ali Samie Posted August 4, 2022 Share Posted August 4, 2022 Hi @DorianS Check this out: Link to comment Share on other sites More sharing options...
Manu-41 Posted February 11, 2023 Share Posted February 11, 2023 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now