November Happy Hour will be moved to Thursday December 5th.

How to clone existing order and create new order in episerver

Vote:
 

Hi ,

we are facing problem in clone existing order and creating new order. we are getting errror in at this line.

Error:It is cloning same order id , pls help

PurchaseOrder purchaseOrder = PurchaseOrder.LoadByOrderGroupId(orderId);
Cart retVal = null;
MetaDataContext.DefaultCurrent = OrderContext.MetaDataContext;
PurchaseOrder clonedPurchaseOrder = (PurchaseOrder)purchaseOrder.Clone();
clonedPurchaseOrder.SetParent(clonedPurchaseOrder); // error in this line 
clonedPurchaseOrder.AcceptChanges();

#181652
Aug 25, 2017 19:40
Vote:
 

Why do you need to call SetParent there? And to itself? If you want to link it to the original PO, you should have called clonedPurchaseOrder.SetParent(purchaseOrder); instead

#181653
Aug 25, 2017 19:55
Vote:
 

Tried and receiving the following error

"Cannot insert duplicate key row in object 'dbo.OrderGroup' with unique index 'IX_OrderGroup'. The duplicate key value is (86a19704-390a-4e43-abdc-d3b526a8702d).
The statement has been terminated."

Do we have any other option to copy the same order with different order id ? If so please let me know. Its urgent

#181654
Aug 25, 2017 20:11
Vote:
 

What are you trying to do? Are you trying to create a same order? I.e. are you trying to allow customer to re-order (create a new order with same items and information)? Or are you trying to create the entirely same order (keep all the statuses, etc. so if the order is completed then the new order is compled as well)? 

#181655
Aug 25, 2017 22:47
Vote:
 

It seems you want to create new order, so here a sample code if you are using CartHelper:

CartHelper ch = new CartHelper();

ch.Cart.Add(oldPurchaseOrder);

So Cart has an Add(OrderGroup) method which allow you to copy from existing PO. From there you can save it as a new PO (.SaveAsPurchaseOrder()).

#181656
Aug 25, 2017 22:50
Vote:
 

I want to create order with existing order information and I just need to edit some details like shipment and order name. Can you send sample code for this ?

#181657
Aug 26, 2017 5:14
Vote:
 

The code above that quan wrote will do just the thing.

CartHelper ch = new CartHelper();
ch.Cart.Add(oldPurchaseOrder);
var copiedPurchaseOrder = ch.Cart.SaveAsPurchaseOrder();
// Now you have a copied purchase order, modify it as you wish
#181658
Aug 26, 2017 9:02
Vote:
 

I tried the above code and looks like the shipment is not copied in new order. Can you please send the sample syntax to copy/edit shipment ?

#181665
Aug 28, 2017 7:36
Vote:
 

What's the value of 

copiedPurchaseOrder.OrderForms.First().Shipments

?

#181666
Aug 28, 2017 7:49
Vote:
 

I can see the value while debugging but the shipment is not showing up in episerver backend. Am i missing something ? Pls advice

#181667
Aug 28, 2017 7:57
Vote:
 

Hi Uma,

Before SaveAsPurchaseOrder you may need to run CartPrepare/CartCheckout work/activity flow if you use old abstraction and simulate the checkout ... ? depending on what you want to achieve, hope it helps...

Regards

#181699
Aug 28, 2017 15:01
Vote:
 

Can you  send sample code for CartPrepare/CartCheckout work/activity flow ? Since I am new to episerver I am not aware of this

#181703
Aug 28, 2017 16:01
Vote:
 

https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-Commerce/8/Workflows/Workflows/

#181704
Aug 28, 2017 16:16
Vote:
 

Hi

I am facing another issue. How can i update line items which is inside shipment ? 

Please Advice

#181712
Aug 29, 2017 7:51
Vote:
 

I can highly advice you to go on a course. Episerver Commerce is a little bit complexer than Episerver CMS, there for it is important to understand concepts and apis.

Also buy the bible "Pro Episerver Commerce", take some hours and read it, you'll get your answers there too https://leanpub.com/proepiservercommerce

Regards

#181734
Aug 29, 2017 10:29
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.