cancel
Showing results for 
Search instead for 
Did you mean: 

Generate random sales order number

SOLVED

Generate random sales order number

How can I generate random sales order numbers.  Thanks in advance for your attention.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Generate random sales order number Type.php

I found the Type.php in /vendor/magento/module-eav/Model/Entity/ 

BUT made the changes in vendor/magento/module-sales-sequence/Model/Sequence.php

After playing with a number of formulas, I settled on this one.

 return $this->getCurrentValue()*RAND(1,1000000);

 

If anyone has other suggestions, I'll love to hear it.

View solution in original post

8 REPLIES 8

Re: Generate random sales order number

Hi @Sheba,

 

Maybe you should explore what happens here:

 

\Magento\Sales\Model\Increment::getNextValue

And then here too:

 

\Magento\Eav\Model\Entity\Type::fetchNewIncrementId

As you can see the second method is looking for the next value.

I guess you can try a plugin over the Magento\Sales\Model\Order class to change the beforeSave method and change the incrementId.

Re: Generate random sales order number

Many thanks Damian. Which file are the syntax in?

Re: Generate random sales order number

Hi @Sheba,


You'll find, for example, at:

 

/vendor/magento/eav/model/entity/type.php

Re: Generate random sales order number

I am using 2.2.1. There is no directory ==> /vendor/magento/eav/model/
entity and no type.php

Re: Generate random sales order number

Re: Generate random sales order number Type.php

Thanks for your responses. I am using 2.2.1 There is no Type.php in
2.2.1 and no directory ==> /app/code/Magento/Eav/Model/Entity/

Please check. Thanks again.

Re: Generate random sales order number Type.php

I found the Type.php in /vendor/magento/module-eav/Model/Entity/ 

BUT made the changes in vendor/magento/module-sales-sequence/Model/Sequence.php

After playing with a number of formulas, I settled on this one.

 return $this->getCurrentValue()*RAND(1,1000000);

 

If anyone has other suggestions, I'll love to hear it.

Re: Generate random sales order number Type.php

Isn't there a chance for not generating unique order numbers?