Exemple #1
0
        protected virtual async Task MapShippingAddressPostalCodeToShipmentAsync(UpdateShippingAddressPostalCodeParam param, Shipment shipment)
        {
            var country = await CountryService.RetrieveCountryAsync(new RetrieveCountryParam
            {
                CultureInfo = param.CultureInfo,
                IsoCode     = param.CountryCode
            }).ConfigureAwait(false);

            country.Validate(param.PostalCode);

            if (shipment.Address == null)
            {
                shipment.Address = new Address {
                    PropertyBag = new PropertyBag()
                };
            }

            if (shipment.Address.PropertyBag != null)
            {
                shipment.Address.PropertyBag[AddressBookIdPropertyBagKey] = Guid.Empty; // because the updated address will not correspond to any registered address
            }

            shipment.Address.PostalCode  = param.PostalCode;
            shipment.Address.CountryCode = country.IsoCode;
            shipment.Address.RegionCode  = GetRegionCodeBasedOnPostalCode(param.PostalCode, param.CountryCode);
        }
Exemple #2
0
        public virtual async Task <CartViewModel> UpdateShippingAddressPostalCodeAsync(UpdateShippingAddressPostalCodeParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            ProcessedCart cart = await CartRepository.GetCartAsync(new GetCartParam
            {
                BaseUrl     = param.BaseUrl,
                Scope       = param.Scope,
                CultureInfo = param.CultureInfo,
                CustomerId  = param.CustomerId,
                CartName    = param.CartName
            }).ConfigureAwait(false);

            var shipment = cart?.Shipments.FirstOrDefault() ?? throw new InvalidOperationException("No shipment was found in the cart.");

            await MapShippingAddressPostalCodeToShipmentAsync(param, shipment);

            return(await UpdateCartAsync(new UpdateCartViewModelParam
            {
                BaseUrl = param.BaseUrl,
                BillingCurrency = cart.BillingCurrency,
                CartName = cart.Name,
                CartType = cart.CartType,
                Coupons = cart.Coupons,
                CultureInfo = param.CultureInfo,
                Customer = cart.Customer,
                CustomerId = cart.CustomerId,
                OrderLocation = cart.OrderLocation,
                Payments = cart.Payments,
                PropertyBag = cart.PropertyBag,
                Scope = cart.ScopeId,
                Shipments = cart.Shipments,
                Status = cart.Status
            }).ConfigureAwait(false));
        }