Ejemplo n.º 1
0
 public void UpdateShipment(Shipment shipment, ShippingRate shippingCost)
 {
     shipment.ShippingMethodId   = shippingCost.Id;
     shipment.ShippingMethodName = shippingCost.Name;
     shipment.SubTotal           = shippingCost.Money.Amount;
     shipment.ShippingSubTotal   = shippingCost.Money.Amount;
     shipment.AcceptChanges();
 }
Ejemplo n.º 2
0
 public void UpdateShipment(Shipment shipment, ShippingRate shippingCost)
 {
     shipment.ShippingMethodId = shippingCost.Id;
     shipment.ShippingMethodName = shippingCost.Name;
     shipment.SubTotal = shippingCost.Money.Amount;
     shipment.ShippingSubTotal = shippingCost.Money.Amount;
     shipment.AcceptChanges();
 }
        /// <summary>
        /// Verifies whether a shipment is empty.
        /// If the shipment is empty, its operation keys will be canceled.
        /// </summary>
        /// <param name="orderForm">The order form.</param>
        /// <param name="shipment">The shipment.</param>
        /// <remarks>The shipment will be deleted if the order has more than one shipment,
        /// so that it always keep at least one shipment in the order form.
        /// </remarks>
        /// <returns><c>False</c> if the shipment does not have any line item, otherwise <c>True</c>.</returns>
        private bool ValidateShipment(OrderForm orderForm, Shipment shipment)
        {
            if (shipment.LineItemIndexes.Length == 0)
            {
                CancelOperationKeys(shipment);
                if (orderForm.Shipments.Count > 1)
                {
                    shipment.Delete();
                    shipment.AcceptChanges();
                }

                return(false);
            }

            return(true);
        }
        private void RequestInventory(OrderForm orderForm, Shipment shipment, LineItem lineItem)
        {
            var lineItemIndex = orderForm.LineItems.IndexOf(lineItem);
            InventoryRequest request;
            var outOfStock = false;
            InventoryResponse response = null;

            lock (_lockObject)
            {
                // Check quantity of order again to make sure there is enough quantity.
                outOfStock = this.GetNewLineItemQty(lineItem, new List<string>(), shipment) <= 0;

                if (!outOfStock)
                {
                    request = AdjustStockItemQuantity(shipment, lineItem);
                    if (request != null)
                    {
                        response = _inventoryService.Service.Request(request);
                    }
                }
            }

            // if out of stock, delete line item and remove line item from the shipment.
            if (outOfStock)
            {
                Warnings.Add("LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because there is not enough available quantity.", lineItem.DisplayName));
                lineItem.Delete();
                shipment.RemoveLineItemIndex(lineItemIndex);

                // Delete the shipment and cancel operation keys if it has no more line item.
                if (shipment.LineItemIndexes.Length == 0)
                {
                    CancelOperationKeys(shipment);
                    shipment.Delete();
                    shipment.AcceptChanges();
                }
                return;
            }

            if (response != null && response.IsSuccess)
            {
                lineItem.IsInventoryAllocated = true;

                // Store operation keys to Shipment for each line item, to use later for complete request
                var existedIndex = shipment.OperationKeysMap.ContainsKey(lineItemIndex);
                var operationKeys = response.Items.Select(c => c.OperationKey);
                if (!existedIndex)
                {
                    shipment.AddInventoryOperationKey(lineItemIndex, operationKeys);
                }
                else
                {
                    shipment.InsertOperationKeys(lineItemIndex, operationKeys);
                }
            }
        }