Position Of Items In An Order


One of my customers is creating manual orders as quotations. They send this to the customer, who can choose to accept the quotation and pay for this order online.

Now when a quotation is made, the order/position of items in the order is important. When a quotation contains 100 items, they must be grouped somehow. It is OK if they can use the position of items in the order for this.

Right now, an order sorts the items by their name. I have checked the source code for the query and the ORDER BY clause, but it can not be changed by using an addon/hook. Only when I change the shop's source code it can be changed, but then I can not automatically update anymore.

I would like to see a setting/switch where the shop owner can choose to order products by their name, or order them by the order in which the customer (or admin) added the products.

You can use the get_order_info hook in the fn_get_order_info function to sort $order[‘products’] array according to your needs

Thanks, however it's a little devious it's still very usable :)

Thanks, however it's a little devious it's still very usable :)

What's devious?

Create a hook for get_order_info. Add code to alter the order of the 'products' array as suits your needs.

If the issue is that you don't have the original order product entry order, then you'll need to add a separate hook that will capture that info and then store it and use it as "the order" later or simply do a query to get the order in the DB (I.e. without the ORDER BY) and re-sort according to that order.

Devious in the fact that in the fn_get_order_info function the $order['products'] array is the result of a database query, but after querying and filling the array a lot of extra information is added. So it is not a matter of simply updating the $order['products'] array.

It is to be solved by one of the following methods:

  1. Update the $order['products'] array with an updated database query. Then use the code from the fn_get_order_info function to add the extra information.
  2. Fetch the correct order from the database. Then reorder/rebuild the $order['products'] array.

Second option is the best imo.

Anyway, I'd rather have seen a hook earlier in the process, so I could eithel change the query or change the ORDER BY part.

You can always use a post controller instead of the hook. This is processed after all the business logic and after all the template variables are set. So you can retreive the 'order_info' template variable, adjust it to your needs, then reapply it to the $order_info variable.

This is one of the oldest hooks. Most of the primary functions now have a [function_name]_pre (before DB query) and a [function_name]_post (before the function returns the data. You can always request a new 'post' hook be added just before the array is returned. There's a sticky post in the developers section to request new hooks.