London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
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.
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.
Thanks.
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--)
{
_cart.OrderForms[i].Delete();
}
//Add order Forms to basket from PurchasOrder.
_cart.OrderForms.Add(of);
// Remove existing Order Addresses
for (int i = _cart.OrderAddresses.Count-1 ; i>=0;i--)
{
_cart.OrderAddresses[i].Delete();
}
foreach (OrderAddress address in orderGroup.OrderAddresses)
{
MetaDataContext.DefaultCurrent = OrderContext.MetaDataContext;
OrderAddress oa = address.Clone() as OrderAddress;
_cart.OrderAddresses.Add(oa);
}
_cart.SetParent(_cart);
_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;
_cart.AcceptChanges();
}
How can i clone a purchase order Or How can i convert an existing purchase order into Cart?