heldercervantes Posted July 12, 2017 Share Posted July 12, 2017 I've seen a few threads on this, but not a really definitive answer that's as clean and simple as most things are in PW. I have a products catalogue that branches out with an unlimited number of subcategories. As the user navigates the categories menu, it's supposed to show a list of all products from that point down, with pagination. So I'm doing this: $pl = $page->find('template=product, sort=sort, limit=60'); And from there I foreach to make the product grid and renderPager() for pagination. But the order on the products is not that of the admin. I need them sorted like they are on the admin, grouped by parent, as if you had the whole tree open and picked products from the top down. As of now, my only solution would be to code an iterator that would crawl all subcategories, adding products to a pageArray. Seems overkill. Any better ideas? Thanks Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 12, 2017 Share Posted July 12, 2017 The sort value is only kept consistent per parent, therefore it doesn't do what you want it to do. You could try using "sort=parent, sort=sort", but this will only solve the issue for 1 level of nesting. For anything further you'd probably need to do some serious joining with pages_parents to even get the wanted sort order in mysql. 1 Link to comment Share on other sites More sharing options...
rick Posted July 12, 2017 Share Posted July 12, 2017 @heldercervantes, Completely off topic. I hope that you and your family were not damaged by the recent fires. I have a friend whose family members are still hospitalized; she is recovering from smoke inhalation and the he has severe burns he received while rescuing a dog from a burning building. 1 Link to comment Share on other sites More sharing options...
BitPoet Posted July 13, 2017 Share Posted July 13, 2017 Populating a hidden "sort path" field computed from a page's parents in a saveReady handler should solve this. If your categories are sorted alphabetically, just store the full path, if not, assemble it from the parents' sort values with every value sprintf'd to identical, zero-padded length so alphanumeric sorting works. 5 Link to comment Share on other sites More sharing options...
heldercervantes Posted July 13, 2017 Author Share Posted July 13, 2017 14 hours ago, rick said: @heldercervantes, Completely off topic. I hope that you and your family were not damaged by the recent fires. I have a friend whose family members are still hospitalized; she is recovering from smoke inhalation and the he has severe burns he received while rescuing a dog from a burning building. Fortunately I live quite far from where the fires hit. Unfortunately those are a regular occurrence here, though this year was the worse I can remember. Mediterranean weather + atlantic moisture = lots of trees. Add a freak heatwave and boom. But it's been calm since that one, and hopefully it was that last straw that makes people take real action to prevent more tragedies like this. Link to comment Share on other sites More sharing options...
heldercervantes Posted July 13, 2017 Author Share Posted July 13, 2017 4 hours ago, BitPoet said: Populating a hidden "sort path" field computed from a page's parents in a saveReady handler should solve this. If your categories are sorted alphabetically, just store the full path, if not, assemble it from the parents' sort values with every value sprintf'd to identical, zero-padded length so alphanumeric sorting works. Wow! That's a great idea. Thanks 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