예제 #1
0
        // used on post order submit
        public async Task <List <HSLineItem> > SetInitialSubmittedLineItemStatuses(string buyerOrderID)
        {
            var lineItems = await ListAllAsync.List((page) => _oc.LineItems.ListAsync <HSLineItem>(OrderDirection.Incoming, buyerOrderID, page: page, pageSize: 100));

            var updatedLineItems = await Throttler.RunAsync(lineItems, 100, 5, li =>
            {
                var partial = new PartialLineItem()
                {
                    xp = new
                    {
                        StatusByQuantity = new Dictionary <LineItemStatus, int>()
                        {
                            { LineItemStatus.Submitted, li.Quantity },
                            { LineItemStatus.Open, 0 },
                            { LineItemStatus.Backordered, 0 },
                            { LineItemStatus.Canceled, 0 },
                            { LineItemStatus.CancelRequested, 0 },
                            { LineItemStatus.Returned, 0 },
                            { LineItemStatus.ReturnRequested, 0 },
                            { LineItemStatus.Complete, 0 }
                        },
                        Returns      = new List <LineItemClaim>(),
                        Cancelations = new List <LineItemClaim>()
                    }
                };
                return(_oc.LineItems.PatchAsync <HSLineItem>(OrderDirection.Incoming, buyerOrderID, li.ID, partial));
            });

            return(updatedLineItems.ToList());
        }
예제 #2
0
        public async Task <decimal> ValidateLineItemUnitCost(string orderID, SuperHSMeProduct product, List <HSLineItem> existingLineItems, HSLineItem li)
        {
            if (product.PriceSchedule.UseCumulativeQuantity)
            {
                int totalQuantity = li?.Quantity ?? 0;
                foreach (HSLineItem lineItem in existingLineItems)
                {
                    if (li == null || !LineItemsMatch(li, lineItem))
                    {
                        totalQuantity += lineItem.Quantity;
                    }
                }
                decimal priceBasedOnQuantity = product.PriceSchedule.PriceBreaks.Last(priceBreak => priceBreak.Quantity <= totalQuantity).Price;
                var     tasks = new List <Task>();
                foreach (HSLineItem lineItem in existingLineItems)
                {
                    // Determine markup for all specs for this existing line item
                    decimal lineItemTotal = priceBasedOnQuantity + GetSpecMarkup(lineItem.Specs, product.Specs);
                    if (lineItem.UnitPrice != lineItemTotal)
                    {
                        PartialLineItem lineItemToPatch = new PartialLineItem();
                        lineItemToPatch.UnitPrice = lineItemTotal;
                        tasks.Add(_oc.LineItems.PatchAsync <HSLineItem>(OrderDirection.Incoming, orderID, lineItem.ID, lineItemToPatch));
                    }
                }
                await Task.WhenAll(tasks);

                // Return the item total for the li being added or modified
                return(li == null ? 0 : priceBasedOnQuantity + GetSpecMarkup(li.Specs, product.Specs));
            }
            else
            {
                decimal lineItemTotal = 0;
                if (li != null)
                {
                    // Determine price including quantity price break discount
                    decimal priceBasedOnQuantity = product.PriceSchedule.PriceBreaks.Last(priceBreak => priceBreak.Quantity <= li.Quantity).Price;
                    // Determine markup for the 1 line item
                    lineItemTotal = priceBasedOnQuantity + GetSpecMarkup(li.Specs, product.Specs);
                }
                return(lineItemTotal);
            }
        }
예제 #3
0
 private async Task SaveShipMethodByLineItem(List <LineItem> lineItems, List <ShipMethodSupplierView> shipMethods, string buyerOrderID)
 {
     if (shipMethods != null)
     {
         foreach (LineItem lineItem in lineItems)
         {
             string shipFromID = lineItem.ShipFromAddressID;
             if (shipFromID != null)
             {
                 ShipMethodSupplierView shipMethod  = shipMethods.Find(shipMethod => shipMethod.ShipFromAddressID == shipFromID);
                 string          readableShipMethod = shipMethod.Name.Replace("_", " ");
                 PartialLineItem lineItemToPatch    = new PartialLineItem {
                     xp = new { ShipMethod = readableShipMethod }
                 };
                 LineItem patchedLineItem = await _oc.LineItems.PatchAsync(OrderDirection.Incoming, buyerOrderID, lineItem.ID, lineItemToPatch);
             }
         }
     }
 }
예제 #4
0
        public void can_serialize_partial()
        {
            // good test case - xp and a nested object
            var p = new PartialProduct {
                Name        = "MyProduct",
                xp          = new { foo = 1 },
                Description = "blah",
                Inventory   = new PartialInventory {
                    QuantityAvailable = 999
                }
            };

            JsonAssert.AreEquivalent(new {
                Name        = "MyProduct",
                xp          = new { foo = 1 },
                Description = "blah",
                Inventory   = new { QuantityAvailable = 999 }
            }, p);

            // another good one - collection property
            var li = new PartialLineItem {
                ID    = "id",
                Specs = new LineItemSpec[] {
                    new PartialLineItemSpec {
                        SpecID = "spec1", Value = "foo"
                    },
                    new PartialLineItemSpec {
                        SpecID = "spec2", OptionID = "3"
                    }
                }
            };

            JsonAssert.AreEquivalent(new {
                ID    = "id",
                Specs = new object[] {
                    new { SpecID = "spec1", Value = "foo" },
                    new { SpecID = "spec2", OptionID = "3" }
                }
            }, li);
        }
예제 #5
0
        private async Task <LineItem> PatchPartialLineItemComment(Misc.Shipment shipment, string newShipmentId)
        {
            PartialLineItem             partialLineItem;
            Dictionary <string, object> commentDictonary = new Dictionary <string, object>();

            //Add new comment
            if (shipment?.ShipmentLineItemComment == null || shipment?.ShipmentLineItemComment == "")
            {
                return(null);
            }

            commentDictonary.Add(newShipmentId, shipment?.ShipmentLineItemComment);

            partialLineItem = new PartialLineItem()
            {
                xp = new
                {
                    Comments = commentDictonary
                }
            };

            return(await _oc.LineItems.PatchAsync(OrderDirection.Outgoing, shipment.OrderID, shipment.LineItemID, partialLineItem));
        }