public string CancelPurchaseOrder(Guid userId, Guid orderId) { try { CommerceServer.Core.Runtime.Orders.PurchaseOrder po = GetPurchaseOrder(userId, orderId); po.Status = "Cancelled"; po.TrackingNumber = GetNextControlNumber(); po.Save(); return(po.TrackingNumber); } catch (Exception ex) { EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging); eventLog.WriteErrorLog("Error in CancelPurchaseOrder: ", ex); throw ex; } }
public string UpdatePurchaseOrder(Guid userId, Guid orderId, string requestedShipDate, List <PurchaseOrderLineItemUpdate> lineItemUpdates) { try { CommerceServer.Core.Runtime.Orders.PurchaseOrder po = GetPurchaseOrder(userId, orderId); CommerceServer.Core.Runtime.Orders.LineItem[] lineItems = new CommerceServer.Core.Runtime.Orders.LineItem[po.OrderForms[0].LineItems.Count]; po.OrderForms[0].LineItems.CopyTo(lineItems, 0); po["RequestedShipDate"] = requestedShipDate; foreach (PurchaseOrderLineItemUpdate i in lineItemUpdates) { CommerceServer.Core.Runtime.Orders.LineItem lineItem = lineItems.Where(x => x.ProductId == i.ItemNumber).FirstOrDefault(); // find existing item based on item number if (i.Status == "changed" && lineItem != null) { lineItem.Quantity = i.Quantity; lineItem["Each"] = i.Each; lineItem["CatchWeight"] = i.CatchWeight; lineItem.Status = "changed"; } if (i.Status == "deleted" && lineItem != null) { lineItem.Status = "deleted"; } if (i.Status == "added" && lineItem == null) { CommerceServer.Core.Runtime.Orders.LineItem li = new CommerceServer.Core.Runtime.Orders.LineItem() { ProductId = i.ItemNumber, Quantity = i.Quantity, Status = "added" }; li["CatchWeight"] = i.CatchWeight; li["Each"] = i.Each; li["Notes"] = string.Empty; li.ProductCatalog = i.Catalog; li.Status = "added"; li["LinePosition"] = po.OrderForms[0].LineItems.Count + 1; po.OrderForms[0].LineItems.Add(li); } if (i.Status == "added" && lineItem != null) { lineItem.Quantity = i.Quantity; lineItem["Each"] = i.Each; lineItem["CatchWeight"] = i.CatchWeight; } } if (po.Status.StartsWith("confirmed", StringComparison.InvariantCultureIgnoreCase)) { po.Status = "Confirmed with un-submitted changes"; } PipelineHelper pipeLineHelper = new PipelineHelper(Extensions.SiteHelper.GetSiteName()); pipeLineHelper.RunPipeline(og: po, transacted: true, loggingEnabled: false, pipelineName: "Checkout", pipelinePath: string.Format ("{0}\\pipelines\\checkout.pcf", HttpContext.Current.Server.MapPath("."))); po.Save(); return(po.TrackingNumber); } catch (Exception ex) { EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging); eventLog.WriteErrorLog("Error in UpdatePurchaseOrder: ", ex); throw ex; } }