In this quick episode, we tidy up a small bug with our price range display in the category view. Until now, if you browsed to a category without any products, we ended up showing an error because the app tried to display a price range where there were no products—causing issues with the money formatter.
We've already handled a similar situation for filters by checking if any products actually exist before rendering the filters. Now, we add the same conditional logic for the price range section. We make sure to base this check on the total product count in the category, rather than on products filtered by the current criteria—a subtle but important difference!
After tweaking this, you’ll notice when viewing an empty category, the price range section won't show up and there are no more errors. The rest of the category UI still works, letting you click through to subcategories, where you can start filtering again if there are products. All in all, it's a neat little fix to keep things running smoothly before we move on to bigger features.