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
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
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)?
It seems you want to create new order, so here a sample code if you are using CartHelper:
CartHelper ch = new CartHelper();
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()).
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 ?
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
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 ?
What's the value of
I can see the value while debugging but the shipment is not showing up in episerver backend. Am i missing something ? Pls advice
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...
Can you send sample code for CartPrepare/CartCheckout work/activity flow ? Since I am new to episerver I am not aware of this
I am facing another issue. How can i update line items which is inside shipment ?
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
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