I have learned that much of the sales tracking and order history is dependent on the sales being made through the use of commerce checkout. For my project, however, I was utilizing the Commerce Kickstarter distribution to create a system to manage business sales whereby the admin would create customer profiles and, subsequently, be able to select from existing customer profiles when an order is created.
That is to say, the admin is the only necessary user.
I soon found, however, that order histories for each Customer Profile remained unchanged after orders. To get around this, I created a rule to create a User Profile to match every Customer Profile whenever the latter is created. In order to associate ownership of the Customer Profile by the New User, I wrote an additional script and triggered it as part of the rule.
Although the Customer Profiles are now owner by their respective Users, the Order History remains unchanged for each user - new orders do not create any history. This is because the user associated with the orders is whichever user is logged in, rather than the user associated with the Customer Profile being chosen for the order. I would like to rectify this as it would allow me to enjoy the full benefits of Commerce Reporting.
My first intuition is to use function hook_commerce_order_presave -> but I have found no examples of this, and am unsure as to the specific structure of $order. Can anyone shed some light on this?