I've created some controls to shape the way that a category's products are displayed. Drop-downs control Sort order [Name, Price], View as [List, Compact List, Grid] and Show per page [5, 10, 25, All].
Everything happens in a partial named shop:category. It draws the controls, updates VisitorPreferencs with changed settings, and uses AJAX to update content according to Sort order and selected View. Changes to Show per page need a Phpr::$response->redirect to reload the entire page with a URL that is correct for the updated pagination. Looks good, works great.
Then I started working on getting the same control over search results. Though I'd start with my shop:category partial and tweak it. Well I'm still tweaking it!
The search is implemented pretty much as in the demo store. Shop_Product::find_products returning $products and a pagination object.
I managed to get Show per page working by saving the value of $query to VisitorPreferences in the partial. This is necessary because after the control's onchange event [getForm().submit()] $query is empty (because the target page following the submit has a URL ../store/search/ with no search params) and the partial has to recreate the proper search URL from saved values before redirecting with:
Phpr::$response->redirect(root_url('search?query='.urlencode($saved_query).'&records='.urlencode($saved_show)));This works, but I'm thinking there's probably a better way.
A bigger problem is how to change the View (List, Grid, etc).
After landing on the Search page with a setting of 5 records per page and 14 products meeting the search criteria:
$products->Count()= 5
$products->requestRowCount()= 29
$pagination->getRowCount()= 14
Now when I change view, say from List to Grid and update using AJAX (exactly the same method used successfully with category products) the above values do not persist. They are all 0. Looks like the objects don't persist across the AJAX update.
I don't want to make duplicates of these objects that do persist because it's a poor approach. So I figure I'm missing something.
For the category product control I use $category->list_products() which returns a full sorted product list which is easy to manipulate. The search method Shop_Product::find_products returns something a whole lot tougher to deal with.
I haven't even begun to tackle sorting the search results yet :|
Any pointers to best practice how to do this?
One day my posts will be short, but until then...
Thanks
iD

Help















