Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

How do I create custom order numbers in SS-shop?

Go to End

4 Posts   2128 Views

Bruce B

Community Member, 164 Posts

30 December 2015 at 6:19pm

I would like my order numbers to be a little more controllable than just starting at 00001 for the first order. Ideally, I'd like to specify an alphanumeric prefix. Any suggestions?
My immediate problem is I'm working on site No 2 and my PayPal sandbox account won't process payments because the Invoice Id has already been processed. (due to testing on site 1)


Community Member, 63 Posts

10 February 2016 at 5:09pm

I've noticed there's a Reference field on the Order db Object which you should be able to set somewhere and then use it in the Paypal payment.
I'm not sure where to set it though, I'm relearning everything after a long Hiatus

Bruce B

Community Member, 164 Posts

10 February 2016 at 7:46pm

Coming back after a long hiatus – sounds familiar. Its that reference field I want. I'll see how I can set it. Ideally I'd reset it at the start of each year to something like 20160001.


Community Member, 6 Posts

16 September 2016 at 8:54pm

Edited: 16/09/2016 8:55pm

This answer comes maybe a little late.

There is a hook in the Order model to override the reference number. Like this:

 * shop.yml
 * Order:
 *   extensions:
 *     - Order_Extension
class Order_Extension extends DataExtension
	public function generateReference(&$reference)
		$reference = date("ym") . str_pad($this->owner->ID, 6, '0', STR_PAD_LEFT);
		$candidate = $reference;
		//prevent generating references that are the same
		$count = 0;

		while (DataObject::get_one('Order', "\"Reference\" = '$candidate'")) {
			$candidate = $reference . "" . $count;

		$this->owner->Reference = $candidate;

I don't know about my refference number genereration is the best. If you want a totally uniqe reference, this pattern look good: