1

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?

1

I was able to solve this issue:

RECAP

Problem: Keeping order history in situations where the admin creates orders on behalf of Customers.

Solution: a) User profiles must exist for the customer profiles. If the admin is creating customer profiles, a Rule can be created to a create User Profile whenever a Customer Profile is saved. To do this, I created a field for Customer Profiles called "Username", and use that data to populate the name of the new User.

b) A script will need to be written to automatically associate ownership of the Customer Profile by the appropriate User Profile. I was unable to create a functioning Rule which doesn't use my own php code to handle this.

c) One more rule to change the data value of the Order before it is saved. Specifically, you want to change [commerce-order:owner] to the right value (which can also be supplied by my Customer Profile's "Username" field). You will need to ensure that your rule has a Condition of "entity has field -> username" or the appropriate token won't be available.

I hope this can be helpful to someone!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.