Clone a Purchase Order or Convert into Cart


How can i clone a purchase order Or How can i convert an existing purchase order into Cart?

Apr 12, 2013 13:38

PurchaseOrder purchaseOrder = null;//Get somehow Cart retVal = null; // Clone the object // need to set meta data context before cloning MetaDataContext.DefaultCurrent = OrderContext.MetaDataContext; PurchaseOrder clonedPurchaseOrder = (PurchaseOrder)purchaseOrder.Clone(); clonedPurchaseOrder.SetParent(clonedPurchaseOrder); // Second: create new cart retVal = (Cart)OrderContext.Current.ShoppingCartClassInfo.CreateInstance(); // Third: migrate order group retVal.Initialize(clonedPurchaseOrder);

    You will want to rerun the workflows on the cart to properly calcuate totals again incase somethint has chnaged.  I would also delete the payments on the cart before manipulating.

Apr 12, 2013 22:44

Thanks Mark.

Ware are using Commerce Server R2SP2

Type 'Mediachase.Commerce.Orders.PurchaseOrder' in Assembly 'Mediachase.Commerce, Version=5.2.628.0, Culture=neutral, PublicKeyToken=6e58b501b34abce3' is not marked as serializable.

further ShoppingCartClassInfo and Initiaze are internal Functions.

Apr 15, 2013 10:33

This worked for me 
public static void CopyCart(Cart _cart, PurchaseOrder orderGroup)
// Initial validation
if (_cart == null) throw new ArgumentNullException("_cart");
if (orderGroup == null) throw new ArgumentNullException("orderGroup");
// need to set meta data context before cloning
MetaDataContext.DefaultCurrent = OrderContext.MetaDataContext;
OrderForm of = orderGroup.OrderForms[0].Clone() as OrderForm;

// Remove existing Order Forms
for (int i = _cart.OrderForms.Count-1 ; i>=0;i--)

//Add order Forms to basket from PurchasOrder.

// Remove existing Order Addresses
for (int i = _cart.OrderAddresses.Count-1 ; i>=0;i--)

foreach (OrderAddress address in orderGroup.OrderAddresses)
MetaDataContext.DefaultCurrent = OrderContext.MetaDataContext;
OrderAddress oa = address.Clone() as OrderAddress;

_cart.AddressId = orderGroup.AddressId;
_cart.AffiliateId = orderGroup.AffiliateId;
_cart.ApplicationId = orderGroup.ApplicationId;
_cart.BillingCurrency = orderGroup.BillingCurrency;
_cart.CustomerId = orderGroup.CustomerId;
_cart.CustomerName = orderGroup.CustomerName;
_cart.ProviderId = orderGroup.ProviderId;
_cart.Status = orderGroup.Status;
_cart.Owner = orderGroup.Owner;
_cart.OwnerOrg = orderGroup.OwnerOrg;
_cart.ShippingTotal = orderGroup.ShippingTotal;
_cart.SiteId = orderGroup.SiteId;
_cart.SubTotal = orderGroup.SubTotal;
_cart.TaxTotal = orderGroup.TaxTotal;
_cart.Total = orderGroup.Total;


Apr 15, 2013 11:40
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.