cancel
Showing results for 
Search instead for 
Did you mean: 

Different number series for carts & orders

Former Member
0 Kudos
2,376

How can we create different number series for carts & orders. Default behavior is when we add to cart & go for order we get cart number as 00000001 & order number as 00000002 & this goes on...And when the server is restarted the number get increased by thousand(1000)...

Pls help.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Hi Anil, You should redefine your Key generator like this

keygen.order.code.name=order_code

keygen.order.code.digits=8

keygen.order.code.start=00000001

keygen.order.code.numeric=true

keygen.order.code.template=SWC$

numberseries.cache.size.order_code=1000

 <bean id="orderCodeGenerator" class="my.project.keygenerator.impl.MyPersistentKeyGenerator">
         <property name="key" value="${keygen.order.code.name}"/>
         <property name="digits" value="${keygen.order.code.digits}"/>
         <property name="start" value="${keygen.order.code.start}"/>
         <property name="numeric" value="${keygen.order.code.numeric}"/>
         <property name="template" value="${keygen.order.code.template}"/>
     </bean>

I hope this will help you. BR Hassan

christoph_meyer
Active Participant
0 Kudos

No, you need to create a generator with a different id, and using a different numberseries key, to use in the cart factory, something like this:

 <bean id="cartCodeGenerator" class="de.hybris.platform.servicelayer.keygenerator.impl.PersistentKeyGenerator">
         <property name="key" value="cart_code" />
         <property name="digits" value="10" />
         <property name="start" value="0" />
         <property name="numeric" value="true" />
         <property name="template" value="$" />
     </bean>
 
Former Member
0 Kudos

Additional information -

numberseries.cache.size.order_code=1000

The number generator uses the above property to cache the next possible codes in the series in order to reduce DB calls and in a clustered environment each node will have its on cache meaning a different set of codes (1000 codes) in the cache.

And since these are in memory caches, a server restart looses the cache, meaning the server gets the next number sequence from the DB which will then be = last code used + 1000

Former Member
0 Kudos

Hi Hasan/Experts,

I dont see the bean - orderCodeGenerator present in saporderexchange-spring.xml, Do I have to add this in my saporderexchange extension spring.xml file?

Or please let me know what configurations need to be done to get this. I am getting error while running spring.getBean("orderCodeGenerator").reset(); from HAC. Can you please help?

Below is the error -

Script execution has failed [reason: Sourced file: inline evaluation of: ``spring.getBean("orderCodeGenerator").reset();'' : Method Invocation reset : at Line: 1 : in file: inline evaluation of: ``spring.getBean("orderCodeGenerator").reset();'' : .reset ( ) Target exception: de.hybris.platform.jalo.JaloInvalidParameterException: did not find number series order_code - cannot reset to [order_code,1,5000000][HY-0] in inline evaluation of: ``spring.getBean("orderCodeGenerator").reset();'' at line number 1]

Former Member
0 Kudos

Hi Ankit,

orderCodeGenerator is in core-spring.xml, not saporderexchange-spring.xml. Unless you have aliased it elsewhere.

Former Member
0 Kudos

Hi Shubham,

Is there any other to find out the previously generated order number? Does hybris keep that number as well somewhere like in a cache or in DB? Basically, I need the last code used.

Thanks, Ashish

Former Member
0 Kudos

where I can define this bean?

Answers (1)

Answers (1)

christoph_meyer
Active Participant
0 Kudos

That is done in spring. Reconfigure the cartFactory to use a new order generator instead of "orderCodeGenerator".

Former Member
0 Kudos

Hi Christoph,

Thanks a ton for your reply. Reconfigured the cartFactory to different order generator but still not able to get different series for carts.

Former Member
0 Kudos

Hi Christoph,

Created the generator as cartCodeGenerator as you mentioned & referred the same in CartFactory as below:

 <bean id="defaultCartFactory" class="de.hybris.platform.order.impl.DefaultCartFactory">
     <property name="keyGenerator" ref="cartCodeGenerator"/>
     <property name="modelService" ref="modelService"/>
     <property name="userService" ref="userService"/>
     <property name="commonI18NService" ref="commonI18NService"/>
 </bean>

Still not able to get different series for Carts, getting the same series used for orders.

christoph_meyer
Active Participant
0 Kudos

Did you wire the beans correctly? e.g. you need to reset the cartFactory alias.

Former Member
0 Kudos

Hi Christoph,

Thanks for suggestion. I am able to generate the different numeric series for carts & orders. I would like to know how to create alpha-numeric series. I had tried with the following local properties

keygen.order.code.name=order_code keygen.order.code.digits=8 keygen.order.code.start=1000000 keygen.order.code.numeric=true keygen.order.code.template=ACC-$-DE

But not able to create alpha numeric series. Request your help for the same.

Former Member
0 Kudos

I found that I had this same problem. I updated the defaultCartFactory from order-spring.xml as specified, but I found out that the cartFactory alias was being overwritten by commerceCartFactory from commerceservices-spring.xml. So I modified the commerceCartFactory bean to use the cartCodeGenerator instead of orderCodeGenerator.

Former Member
0 Kudos

This works, thank you.

Former Member
0 Kudos

In order to have alpha-numeric order numbers, change the keygen.order.code.numeric value to false. Setting this to true restricts it to only number values.

Former Member
0 Kudos

Hi Christop Meyer, I tried this but still getting the numeric value for the SO, I am looking for alpha numeric as per the code above, I believe it will generate SWC00000001 like this. Can you help me posting this class MyPersistentKeyGenerator? or am I missing something here?

Thanks for your sharing...