public string SaveOrderAsChangeOrder(Guid userId, Guid cartId) { try { PurchaseOrder po = GetPurchaseOrder(userId, cartId); PipelineHelper pipeLineHelper = new PipelineHelper(Extensions.SiteHelper.GetSiteName()); pipeLineHelper.RunPipeline(og: po, transacted: true, loggingEnabled: Configuration.EnableLoggingPipeline, pipelineName: "Checkout", pipelinePath: string.Format ("{0}\\pipelines\\checkout.pcf", HttpContext.Current.Server.MapPath("."))); po.TrackingNumber = GetNextControlNumber(); po.Status = "Submitted"; po.Save(); return(po.TrackingNumber); } catch (Exception ex) { EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging); eventLog.WriteErrorLog("Error in SaveOrderAsChangeOrder: ", ex); throw ex; } }
public string SaveCartAsOrder(Guid userId, Guid cartId) { try { var context = Extensions.SiteHelper.GetOrderContext(); var basket = context.GetBasket(userId, cartId); bool reorder = false; foreach (LineItem lineItem in basket.OrderForms[0].LineItems) { if (lineItem["LinePosition"] == null) { reorder = true; } else { if (lineItem["LinePosition"].Equals("0")) { reorder = true; } } } if (reorder) { EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging); eventLog.WriteInformationLog("SaveCartAsOrder : reorder"); int startIndex = 1; // main frame needs lineposition to not be null foreach (LineItem lineItem in basket.OrderForms[0].LineItems) { lineItem["LinePosition"] = startIndex; startIndex++; } } PipelineHelper pipeLineHelper = new PipelineHelper(Extensions.SiteHelper.GetSiteName()); pipeLineHelper.RunPipeline(og: basket, transacted: true, loggingEnabled: Configuration.EnableLoggingPipeline, pipelineName: "Checkout", pipelinePath: string.Format ("{0}\\pipelines\\checkout.pcf", HttpContext.Current.Server.MapPath("."))); basket.TrackingNumber = GetNextControlNumber(); basket["OriginalOrderNumber"] = basket.TrackingNumber; var purchaseOrder = basket.SaveAsOrder(); return(purchaseOrder.TrackingNumber); } catch (Exception ex) { EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging); eventLog.WriteErrorLog("Error in SaveCartAsOrder: ", 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; } }