private OrderDetailsViewModel.DeliveryItem BuildDeliveryRow(OrderOverview orderOverview, ShippingInfo shippingInfo, bool includeVat, Currency currency)
        {
            var shipmentRows = orderOverview.Shipments?.SelectMany(x => x.Rows.Where(y => y.ShippingInfoSystemId.GetValueOrDefault() == shippingInfo.SystemId));
            var shipmentCost = shipmentRows == null ? 0 :
                               includeVat?shipmentRows.Select(x => x.TotalIncludingVat).Sum() : shipmentRows.Select(x => x.TotalExcludingVat).Sum();

            var order              = orderOverview.SalesOrder;
            var channel            = _channelService.Get(order.ChannelSystemId.Value);
            var shippingOptionName = string.Empty;

            if (channel is not null)
            {
                var country     = _countryService.Get(order.CountryCode);
                var countryLink = channel.CountryLinks.FirstOrDefault(x => x.CountrySystemId == country.SystemId);

                if (shippingInfo != null)
                {
                    shippingOptionName = countryLink?.ShippingOptions.FirstOrDefault(x => x.Id.Equals(shippingInfo.ShippingOption))?.Name;
                }
            }

            var model = new OrderDetailsViewModel.DeliveryItem
            {
                DeliveryId           = shippingInfo.SystemId,
                DeliveryMethodTitle  = shippingOptionName,
                DeliveryRowTotalCost = currency.Format(shipmentCost, true, CultureInfo.CurrentUICulture)
            };

            model.Address.MapFrom(shippingInfo.ShippingAddress);

            return(model);
        }
Esempio n. 2
0
        private OrderDetailsViewModel.DeliveryItem BuildDeliveryRow(Delivery delivery, bool includeVat, Currency currency, Guid languageSystemId)
        {
            var deliveryCost = includeVat ? delivery.TotalDeliveryCostWithVat : delivery.TotalDeliveryCost;
            var model        = new OrderDetailsViewModel.DeliveryItem
            {
                DeliveryId           = delivery.ID,
                DeliveryMethodTitle  = delivery.DeliveryMethod.GetDisplayName(languageSystemId),
                DeliveryRowTotalCost = currency.Format(deliveryCost, true, CultureInfo.CurrentUICulture)
            };

            model.Address.MapFrom(delivery.Address);

            return(model);
        }