public override void ExecuteQuery(CommerceQueryOperation queryOperation, OperationCacheDictionary operationCache, CommerceQueryOperationResponse response)
        {
            if ((int)((CommerceServer.Foundation.CommerceModelSearch)(queryOperation.SearchCriteria)).Model.Properties["BasketType"] == 1) // when retrieving purchase order, supplement data that isn't auto mapped
            {
                foreach (CommerceEntity e in response.CommerceEntities)
                {
                    CommerceServer.Core.Runtime.Orders.PurchaseOrder po =
                        (operationCache.FirstOrDefault().Value as Dictionary <string, CommerceServer.Core.Runtime.Orders.OrderGroup>)[e.Id] as CommerceServer.Core.Runtime.Orders.PurchaseOrder;
                    CommerceServer.Core.Runtime.Orders.LineItem[] lineItems = new CommerceServer.Core.Runtime.Orders.LineItem[po.OrderForms[0].LineItems.Count];

                    if (po.OrderForms[0].LineItems.Count > 0)
                    {
                        po.OrderForms[0].LineItems.CopyTo(lineItems, 0);
                    }

                    bool skip = true;
                    foreach (var prop in e.Properties)
                    {
                        if (skip)
                        {
                            if (prop.Key == "BranchId") // only start setting custom properties
                            {
                                skip = false;
                            }
                            if (skip)
                            {
                                continue;
                            }
                        }
                        if (po[prop.Key] != null)
                        {
                            prop.Value = po[prop.Key];
                        }
                    }
                    // next do line items
                    if (e.Properties["LineItems"] != null)
                    {
                        foreach (var l in (e.Properties["LineItems"] as CommerceRelationshipList))
                        {
                            List <CommercePropertyItem> items = l.Target.Properties.Where(x => x.Value == null).ToList();
                            CommerceServer.Core.Runtime.Orders.LineItem poLineItem = lineItems.Where(x => x.LineItemId.ToCommerceServerFormat() == l.Target.Id).FirstOrDefault();
                            skip = true;
                            foreach (var prop in l.Target.Properties)
                            {
                                if (skip)
                                {
                                    if (prop.Key == "LinePosition") // only lookup BEK custom properties
                                    {
                                        skip = false;
                                    }
                                    if (skip)
                                    {
                                        continue;
                                    }
                                }
                                if (poLineItem[prop.Key] != null)
                                {
                                    prop.Value = poLineItem[prop.Key];
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        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;
            }
        }