Beispiel #1
0
        public async Task <HSLineItem> UpsertLineItem(string orderID, HSLineItem liReq, VerifiedUserContext user)
        {
            // get me product with markedup prices correct currency and the existing line items in parellel
            var productRequest           = _meProductCommand.Get(liReq.ProductID, user);
            var existingLineItemsRequest = ListAllAsync.List((page) => _oc.LineItems.ListAsync <HSLineItem>(OrderDirection.Outgoing, orderID, page: page, pageSize: 100, filters: $"Product.ID={liReq.ProductID}", accessToken: user.AccessToken));
            var orderRequest             = _oc.Orders.GetAsync(OrderDirection.Incoming, orderID);
            var existingLineItems        = await existingLineItemsRequest;
            var product       = await productRequest;
            var li            = new HSLineItem();
            var markedUpPrice = ValidateLineItemUnitCost(orderID, product, existingLineItems, liReq);

            liReq.UnitPrice = await markedUpPrice;
            var order = await orderRequest;

            Require.That(!order.IsSubmitted, new ErrorCode("Invalid Order Status", 400, "Order has already been submitted"));

            liReq.xp.StatusByQuantity = LineItemStatusConstants.EmptyStatuses;
            liReq.xp.StatusByQuantity[LineItemStatus.Open] = liReq.Quantity;

            var preExistingLi = ((List <HSLineItem>)existingLineItems).Find(eli => LineItemsMatch(eli, liReq));

            if (preExistingLi != null)
            {
                li = await _oc.LineItems.SaveAsync <HSLineItem>(OrderDirection.Incoming, orderID, preExistingLi.ID, liReq);
            }
            else
            {
                li = await _oc.LineItems.CreateAsync <HSLineItem>(OrderDirection.Incoming, orderID, liReq);
            }
            await _promotionCommand.AutoApplyPromotions(orderID);

            return(li);
        }
Beispiel #2
0
        public async Task <HSOrder> ApplyAutomaticPromotions(string orderID)
        {
            await _promotionCommand.AutoApplyPromotions(orderID);

            return(await _oc.Orders.GetAsync <HSOrder>(OrderDirection.Incoming, orderID));
        }