コード例 #1
0
        public ActionResult SetShippingMethods(SetShippingArgs args)
        {
            var result = this.deliveryRepository.SetShippingMethods(args);

            if (result.Success)
            {
                return(this.JsonOk(result.Data));
            }

            return(this.JsonError(result.Errors?.ToArray(), HttpStatusCode.InternalServerError, tempData: result.Data));
        }
        public Result <SetShippingModel> SetShippingMethods(SetShippingArgs setShippingArgs)
        {
            var result = new Result <SetShippingModel>();

            try
            {
                result.SetResult(
                    new SetShippingModel
                {
                    Success = true
                });
                var currentCart = this.CartManager.GetCurrentCart(
                    this.StorefrontContext.ShopName,
                    this.VisitorContext.ContactId);

                if (!currentCart.ServiceProviderResult.Success)
                {
                    result.SetErrors(currentCart.ServiceProviderResult);
                    return(result);
                }

                var cart               = currentCart.Result;
                var partyEntityList    = this.EntityMapper.MapToPartyEntityList(setShippingArgs.ShippingAddresses);
                var shippingOptionType =
                    ConnectOptionTypeHelper.ToShippingOptionType(setShippingArgs.OrderShippingPreferenceType);
                var shippingInfo = this.EntityMapper.MapToShippingInfoArgumentList(setShippingArgs.ShippingMethods);

                var managerResponse = this.CartManager.AddShippingInfo(cart, partyEntityList, shippingOptionType, shippingInfo);

                if (!managerResponse.ServiceProviderResult.Success)
                {
                    result.SetErrors(managerResponse.ServiceProviderResult);
                    return(result);
                }
            }
            catch (Exception ex)
            {
                result.SetErrors(nameof(this.SetShippingMethods), ex);
            }

            return(result);
        }