I asked this question many years ago when I was updating my current store but the code has changed since then and the old way of doing it no longer seems to work.
We sort similar products in the same area of the store room, so when we use the invoice or packing slip as a picking list it saves time to have the products listed on the invoice and packing slips in model number order. I think last time it ewas decided to save the items in the basket in the correct order, that then showed them in the right order on the invoice/packing slip.
Before I had to create a new copy of the shopping cart file which is now in includes/versioned/1.0.8.7/shopping_cart.php and add to that file. That now produces a blank page.
What would be the best way to sort the products in the shopping basket, packing slip and invoice by model number?
How to sort products by model number in shopping cart and on invoice
- burt
- Core Team
- Posts: 4561
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 413 times
Re: How to sort products by model number in shopping cart and on invoice
I've had a quick glance at the code and can see where to make a change so the Admin side works as you want, but I am not able to find a hook call that would be suitable. In the meantime, until someone else can find a hook (and write the hook)...or someone finds a different solution;
Make a copy of;
/includes/system/versioned/1.0.7.10/database_order_builder.php
To (note that you might need to create the override folder and that it has nothing to do with the override tmplate);
/includes/system/override/database_order_builder.php
Change L119 in that NEW file to:
Save. Invoice and Packing Slip should now be ordered by model.
-
Note that if someone comes up with a better solution that does not involve overriding the database_order_builder file, all you need to do is delete that NEW database_order_builder.php file and you are back to normal. Then follow their instructions to a better solution.
Make a copy of;
/includes/system/versioned/1.0.7.10/database_order_builder.php
To (note that you might need to create the override folder and that it has nothing to do with the override tmplate);
/includes/system/override/database_order_builder.php
Change L119 in that NEW file to:
Code: Select all
$order_products_query = $GLOBALS['db']->query("SELECT * FROM orders_products WHERE orders_id = " . (int)$this->order->get_id() . " ORDER BY products_model");-
Note that if someone comes up with a better solution that does not involve overriding the database_order_builder file, all you need to do is delete that NEW database_order_builder.php file and you are back to normal. Then follow their instructions to a better solution.
I am not here to build for you.
I am here to build with you. Let's help each other.
I am here to build with you. Let's help each other.
-
14Steve14
- Senior Contributor
- Posts: 923
- Joined: Fri Oct 25, 2019 7:01 pm
- Phoenix Version: v1.0.9.1
- Has thanked: 17 times
- Been thanked: 103 times
Re: How to sort products by model number in shopping cart and on invoice
Thanks @burt Gary. Works like a charm with the test products so hopefully should be alright when there are more items in an order.
Another change ticked off the very long list.
Another change ticked off the very long list.
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: How to sort products by model number in shopping cart and on invoice
Code: Select all
$GLOBALS['all_hooks']->cat('constructOrder', $this);Something like
Code: Select all
public function listen_constructOrder($order) {
usort($order->products, function ($a, $b) { return $a['model'] <=> $b['model']; });
}- burt
- Core Team
- Posts: 4561
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 413 times
Re: How to sort products by model number in shopping cart and on invoice
I missed that Hook. So to test it, try (and note that I have not tested this);
1. Delete that new override file you made.
2.
New File:
/includes/hooks/admin/siteWide/sortProducts.php
Content:
As it's sitewide that Hook should work for both invoice and packingslip.
Be sure to check for unwanted gremlins elsewhere - if any appear let us know.
1. Delete that new override file you made.
2.
New File:
/includes/hooks/admin/siteWide/sortProducts.php
Content:
Code: Select all
class hook_admin_siteWide_sortProducts {
public function listen_constructOrder($order) {
usort($order->products, function ($a, $b) { return $a['model'] <=> $b['model']; });
}
}Be sure to check for unwanted gremlins elsewhere - if any appear let us know.