Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.0-rc3
Component:
Order
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
23 Aug 2011 at 07:31 UTC
Updated:
24 Aug 2015 at 10:45 UTC
Jump to comment: Most recent
Comments
Comment #1
googletorp commentedI don't believe you can setup Commerce from within the UI on how to handle order numbers, but you could create any custom logic and use the hooks for when an order is completed, created etc, to make it use any order_number system you please (in a custom module).
Comment #2
rszrama commentedYep, that's right. One way to do it would be to use a variable_get() / variable_set() to track the current order number and use the checkout completion hook that googletorp mentioned to set the order number to your desired value. The hook is hook_commerce_checkout_copmlete($order).
Comment #3
franfran commentedThanks for the advice! So I should have my own module and database table to map the Commerce order number and my own formatted Receipe number?
And for any display like order list in the admin page, order complete email, and order history in member's page, I queue and display the Receipe number instead of the Commerce order number.
Comment #4
rszrama commentedYou don't need to do this, because the Order Number is a column of the commerce_order table that you can actually use to store these numbers. The only thing you need to do is make sure you have a way to keep track of what number to use next. Then on hook_commerce_order_update() or hook_commerce_checkout_complete(), you should change the order's order_number property to the required value. Doing this on checkout completion makes sense to me.
Comment #6
adrianmak commentedthe Order Number in table is a numeric data type, how could I use a string pattern of order number ?
Comment #7
rszrama commentedThe order_id is numeric, but order_number is actually a varchar (text or numbers). You just have to implement some method of setting the order number to what you want on order creation or some other event (such as checkout completion).
Comment #8
guguss commentedHi,
I had to solve that issue for a personal project. I'm now trying to provide a more generic solution to handle that.
It's still on my sandbox for now : http://drupal.org/sandbox/GuGuss/1765778
Comment #9
aidanlis commentedOften an admin, not a user, creates the order so we needed to use presave:
Comment #10
dianikol commentedWhat about using a rule to do that? Just a quick plan
1) Event: After updating an existing commerce order
2) Conditions: Data comparison: if the unchanged order status is not pending or edit and the updated status is pending
3) Action: Use PHP to get the latest completed order to see what the next order number should be and do the update to the order number according to your plans
Maybe you can set a variable with variable_set a starting point value and then using this variable to the rule action from above to set the order number.
Something like that. I hope it's clear :)
GuGuss sandbox module works great for orders made by customers but not when an admin make the order
Tell be what do you think for the rule solution
Thanks
Comment #11
bpirkle commentedThe rules solution worked for me. The rule entry in my features module looks like this:
And the code in my custom module looks like this:
Comment #12
anybody#11 is great! What do you think about creating a module for that or including this as (possibly disabled) rule in DC? (favourite)
Comment #13
lmeurs commentedThanks for #11. I did not use the rule entry for a Features module, but created a rule through the Rules UI for the After saving a new commerce order event. The order did not save automatically, so I had to add a
saveoption to the commerce_order parameter:Worked out fine, thanks again!
Comment #14
hosais commentedHi Imeurs,
May I ask "sage option to the commerce_order" means? how can we change order number by some settings?
Thanks.
hosais
Comment #15
lmeurs commented@hosais: It has been a few months, so please bare with me. :-)
I do not remember why the addition of the
save => TRUEoption was necessary, but the following worked for me, hopefully it will for you too.Based on the solution from #11 I created file
sitecommerce.rules.incfor one of my site's custom modules namedsitecommercewith the following contents (replacesitecommercefor the name of your own module):In this file we defined a Rules action with callback function, after this I created a rule through the Rules UI for the After saving a new commerce order event and selected our new action.
Callback function
sitecommerce_rule_action_custom_order_number()generates a new order number based on prefix (set through Rules UI), the last two digits of the current year and the order ID starting at 2222 and padded to 6 digits. This function can off course be altered to your likings.Comment #16
hosais commented@lmeurs
I really appreciate your quick and detail response. I am sincerely sorry that I responded your post so late.
I will get back to this issue soon.
Thank you again.
hosais
Comment #17
mandus.cz commentedCustom Order Number