/// <summary>
            /// Executes the workflow to fetch delivery options for given product and address.
            /// </summary>
            /// <param name="request">Instance of <see cref="GetProductDeliveryOptionsRequest"/>.</param>
            /// <returns>Instance of <see cref="GetProductDeliveryOptionsResponse"/>.</returns>
            protected override GetProductDeliveryOptionsResponse Process(GetProductDeliveryOptionsRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.ShippingAddress, "request.ShippingAddress");

                // Validate and resolve address
                ShippingHelper.ValidateAndResolveAddress(this.Context, request.ShippingAddress);

                // Get the delivery options
                var serviceRequest = new GetProductDeliveryOptionsServiceRequest(request.ShippingAddress, request.ItemId, request.InventoryDimensionId)
                {
                    QueryResultSettings = request.QueryResultSettings
                };
                var serviceResponse = this.Context.Execute <GetProductDeliveryOptionsServiceResponse>(serviceRequest);

                return(new GetProductDeliveryOptionsResponse(serviceResponse.DeliveryOptions));
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Fetches the delivery options applicable for the item/inventDimId and Address.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>Delivery options applicable.</returns>
            /// <remarks>This API is typically used to display the delivery options in Item details page.</remarks>
            private static GetProductDeliveryOptionsServiceResponse GetProductDeliveryOptions(GetProductDeliveryOptionsServiceRequest request)
            {
                if (request.ShippingAddress == null)
                {
                    throw new ArgumentNullException("request", "request.ShippingAddress");
                }

                var dataServiceRequest = new GetItemDeliveryOptionsDataRequest(request.ItemId, request.InventoryDimensionId, request.ShippingAddress.ThreeLetterISORegionName, request.ShippingAddress.State);

                dataServiceRequest.QueryResultSettings = request.QueryResultSettings;
                var dataServiceResponse = request.RequestContext.Execute <EntityDataServiceResponse <DeliveryOption> >(dataServiceRequest);

                var deliveryOptions = dataServiceResponse.PagedEntityCollection;

                // Raise notification if no delivery options are found.
                if (!deliveryOptions.Results.Any())
                {
                    EmptyProductDeliveryOptionSetNotification notification = new EmptyProductDeliveryOptionSetNotification(request.ShippingAddress, request.ItemId, request.InventoryDimensionId);
                    request.RequestContext.Notify(notification);
                }

                return(new GetProductDeliveryOptionsServiceResponse(deliveryOptions));
            }