/// <summary>
            /// Sets the line level delivery options.
            /// </summary>
            /// <param name="salesTransaction">The sales transaction being updated.</param>
            /// <param name="lineDeliverySpecifications">The delivery specifications at the line level.</param>
            /// <returns>Updated sales transaction.</returns>
            private SalesTransaction UpdateLineLevelDeliveryOptions(SalesTransaction salesTransaction, IEnumerable <LineDeliverySpecification> lineDeliverySpecifications)
            {
                ThrowIf.Null(lineDeliverySpecifications, "lineDeliverySpecifications");

                // Clear header level delivery information.
                salesTransaction.DeliveryMode    = null;
                salesTransaction.ShippingAddress = null;

                Dictionary <string, LineDeliverySpecification> lineDeliverySpecificationsByLineId = lineDeliverySpecifications.ToDictionary(k => k.LineId);

                foreach (var salesLine in salesTransaction.SalesLines)
                {
                    if (salesLine != null)
                    {
                        LineDeliverySpecification currentLineDeliverySpecification;

                        if (lineDeliverySpecificationsByLineId.TryGetValue(salesLine.LineId, out currentLineDeliverySpecification))
                        {
                            ClearLineLevelDeliveryValues(salesLine);

                            DeliverySpecification currentDeliverySpecification = currentLineDeliverySpecification.DeliverySpecification;

                            this.ValidateDeliveryMode(currentDeliverySpecification.DeliveryModeId);

                            salesLine.DeliveryMode = currentDeliverySpecification.DeliveryModeId;

                            switch (currentDeliverySpecification.DeliveryPreferenceType)
                            {
                            case DeliveryPreferenceType.ShipToAddress:
                                salesLine.ShippingAddress = currentDeliverySpecification.DeliveryAddress;
                                break;

                            case DeliveryPreferenceType.PickupFromStore:
                                salesLine.ShippingAddress    = currentDeliverySpecification.DeliveryAddress;
                                salesLine.FulfillmentStoreId = currentDeliverySpecification.PickUpStoreId;
                                break;

                            case DeliveryPreferenceType.ElectronicDelivery:
                                UpdateElectronicDeliveryInfo(
                                    salesLine,
                                    currentDeliverySpecification.ElectronicDeliveryEmailAddress,
                                    currentDeliverySpecification.ElectronicDeliveryEmailContent);
                                break;

                            default:
                                var message = string.Format("Unsupported delivery preference type [{0}] is specified.", currentDeliverySpecification.DeliveryPreferenceType);
                                throw new InvalidOperationException(message);
                            }
                        }
                    }
                }

                return(salesTransaction);
            }
Exemplo n.º 2
0
            /// <summary>
            /// Updates the delivery specification.
            /// </summary>
            /// <param name="deliverySpecification">The delivery specification.</param>
            /// <returns>The updated shopping cart.</returns>
            public async Task <ActionResult> UpdateDeliverySpecification(DeliverySpecification deliverySpecification)
            {
                EcommerceContext      ecommerceContext      = ServiceUtilities.GetEcommerceContext(this.HttpContext);
                CartOperationsHandler cartOperationsHandler = new CartOperationsHandler(ecommerceContext);

                SessionType sessionType = ServiceUtilities.GetSessionType(this.HttpContext, isCheckoutSession: true);
                string      cartId      = ServiceUtilities.GetCartIdFromRequestCookie(this.HttpContext, sessionType);

                Cart cart = await cartOperationsHandler.UpdateDeliverySpecification(cartId, deliverySpecification);

                return(this.Json(cart));
            }
            /// <summary>
            /// Commits the selected delivery option to the cart when entire order is being 'delivered' as a single entity.
            /// </summary>
            /// <param name="shoppingCartId">The shopping cart identifier.</param>
            /// <param name="deliverySpecification">The selected delivery option.</param>
            /// <returns>
            /// The updated shopping cart.
            /// </returns>
            /// <exception cref="System.ArgumentNullException">Thrown when the shoppingCartId or shippingOptions is null or empty.</exception>
            public virtual async Task <Cart> UpdateDeliverySpecification(string shoppingCartId, DeliverySpecification deliverySpecification)
            {
                if (string.IsNullOrWhiteSpace(shoppingCartId))
                {
                    throw new ArgumentNullException(nameof(shoppingCartId));
                }

                if (deliverySpecification == null)
                {
                    throw new ArgumentNullException(nameof(deliverySpecification));
                }

                ManagerFactory managerFactory = Utilities.GetManagerFactory(this.EcommerceContext);
                ICartManager   cartManager    = managerFactory.GetManager <ICartManager>();

                Cart cart = await cartManager.UpdateDeliverySpecification(shoppingCartId, deliverySpecification);

                cart = await DataAugmenter.GetAugmentedCart(this.EcommerceContext, cart);

                return(cart);
            }
Exemplo n.º 4
0
 public Task <Cart> UpdateDeliverySpecification(string id, DeliverySpecification deliverySpecification)
 {
     return(Task.Run(() => OrderManager.Create(CommerceRuntimeManager.Runtime).UpdateDeliverySpecification(id, deliverySpecification)));
 }
            /// <summary>
            /// Sets the order level delivery options.
            /// </summary>
            /// <param name="salesTransaction">The sales transaction being updated.</param>
            /// <param name="deliverySpecification">The selected delivery option.</param>
            /// <returns>Updated sales transaction.</returns>
            private SalesTransaction UpdateOrderLevelDeliverySpecification(SalesTransaction salesTransaction, DeliverySpecification deliverySpecification)
            {
                ClearLineLevelDeliveryValues(salesTransaction.SalesLines);

                this.ValidateDeliveryMode(deliverySpecification.DeliveryModeId);

                salesTransaction.DeliveryMode = deliverySpecification.DeliveryModeId;

                switch (deliverySpecification.DeliveryPreferenceType)
                {
                case DeliveryPreferenceType.ShipToAddress:
                    salesTransaction.ShippingAddress = deliverySpecification.DeliveryAddress;
                    break;

                case DeliveryPreferenceType.PickupFromStore:
                    salesTransaction.ShippingAddress = deliverySpecification.DeliveryAddress;
                    foreach (SalesLine salesLine in salesTransaction.SalesLines)
                    {
                        salesLine.FulfillmentStoreId = deliverySpecification.PickUpStoreId;
                    }

                    break;

                case DeliveryPreferenceType.ElectronicDelivery:
                    foreach (SalesLine salesLine in salesTransaction.SalesLines)
                    {
                        UpdateElectronicDeliveryInfo(salesLine, deliverySpecification.ElectronicDeliveryEmailAddress, deliverySpecification.ElectronicDeliveryEmailContent);
                    }

                    break;

                default:
                    var message = string.Format("Unsupported delivery preference type [{0}] is specified.", deliverySpecification.DeliveryPreferenceType);
                    throw new InvalidOperationException(message);
                }

                return(salesTransaction);
            }