Пример #1
0
        public ShippingOptionUpdateResponse UpdateShippingMethod(ICart cart, ShippingOptionUpdateRequest shippingOptionUpdateRequest)
        {
            var configuration = GetConfiguration(cart.Market);
            var shipment      = cart.GetFirstShipment();

            if (shipment != null && Guid.TryParse(shippingOptionUpdateRequest.SelectedShippingOption.Id, out Guid guid))
            {
                shipment.ShippingMethodId = guid;
                shipment.ShippingAddress  = shippingOptionUpdateRequest.ShippingAddress.ToOrderAddress(cart);
                _orderRepository.Save(cart);
            }

            var totals = _orderGroupTotalsCalculator.GetTotals(cart);
            var result = new ShippingOptionUpdateResponse
            {
                OrderAmount      = AmountHelper.GetAmount(totals.Total),
                OrderTaxAmount   = AmountHelper.GetAmount(totals.TaxTotal),
                OrderLines       = GetOrderLines(cart, totals, configuration.SendProductAndImageUrl),
                PurchaseCurrency = cart.Currency.CurrencyCode
            };

            if (ServiceLocator.Current.TryGetExistingInstance(out ICheckoutOrderDataBuilder checkoutOrderDataBuilder))
            {
                checkoutOrderDataBuilder.Build(result, cart, configuration);
            }
            return(result);
        }
Пример #2
0
        public IHttpActionResult ShippingOptionUpdate(int orderGroupId, [FromBody] ShippingOptionUpdateRequest shippingOptionUpdateRequest)
        {
            var cart = _orderRepository.Load <ICart>(orderGroupId);

            var response = _klarnaCheckoutService.UpdateShippingMethod(cart, shippingOptionUpdateRequest);

            return(Ok(response));
        }
Пример #3
0
        public virtual ShippingOptionUpdateResponse UpdateShippingMethod(ICart cart, ShippingOptionUpdateRequest shippingOptionUpdateRequest)
        {
            var configuration      = GetConfiguration(cart.MarketId);
            var shipment           = cart.GetFirstShipment();
            var validationIssues   = new Dictionary <ILineItem, List <ValidationIssue> >();
            var rewardDescriptions = Enumerable.Empty <RewardDescription>();

            if (shipment != null && Guid.TryParse(shippingOptionUpdateRequest.SelectedShippingOption.Id, out Guid guid))
            {
                shipment.ShippingAddress  = shippingOptionUpdateRequest.ShippingCheckoutAddress.ToOrderAddress(cart);
                shipment.ShippingMethodId = guid;
                validationIssues          = _klarnaCartValidator.ValidateCart(cart);
                rewardDescriptions        = _klarnaCartValidator.ApplyDiscounts(cart);
                _orderRepository.Save(cart);
            }

            var totals = _orderGroupCalculator.GetOrderGroupTotals(cart);
            var result = new ShippingOptionUpdateResponse
            {
                OrderAmount      = AmountHelper.GetAmount(totals.Total),
                OrderTaxAmount   = AmountHelper.GetAmount(totals.TaxTotal),
                OrderLines       = GetOrderLines(cart, totals, configuration.SendProductAndImageUrl),
                PurchaseCurrency = cart.Currency.CurrencyCode,
                ShippingOptions  = configuration.ShippingOptionsInIFrame
                    ? GetShippingOptions(cart, cart.Currency)
                    : Enumerable.Empty <ShippingOption>(),
                ValidationIssues   = validationIssues,
                RewardDescriptions = rewardDescriptions
            };

            if (ServiceLocator.Current.TryGetExistingInstance(out ICheckoutOrderDataBuilder checkoutOrderDataBuilder))
            {
                checkoutOrderDataBuilder.Build(result, cart, configuration);
            }

            return(result);
        }