private OrderDetailsViewModel.OrderRowItem BuildOrderRow(OrderRow orderRow, bool includeVat, Currency currency, SalesOrder order)
        {
            var productModel = _productModelBuilder.BuildFromVariant(_variantService.Get(orderRow.ArticleNumber));

            var unitOfMeasurement             = _unitOfMeasurementService.Get(orderRow.UnitOfMeasurementSystemId.Value);
            var unitOfMeasurementFormatString = $"0.{new string('0', unitOfMeasurement?.DecimalDigits ?? 0)}";

            var campaignPrice = GetCampaignPrice(orderRow, order);
            var totalPrice    = GetTotalPrice(campaignPrice, includeVat, orderRow);

            var model = new OrderDetailsViewModel.OrderRowItem
            {
                DeliveryId     = orderRow.ShippingInfoSystemId is null ? Guid.Empty : orderRow.ShippingInfoSystemId.Value,
                Brand          = productModel == null ? null : _fieldDefinitionService.Get <ProductArea>("Brand")?.GetTranslation(productModel.GetValue <string>("Brand")),
                Name           = productModel == null ? orderRow.ArticleNumber : productModel.GetValue <string>(SystemFieldDefinitionConstants.Name),
                QuantityString = $"{orderRow.Quantity.ToString(unitOfMeasurementFormatString, CultureInfo.CurrentUICulture.NumberFormat)} {unitOfMeasurement?.Localizations.CurrentUICulture.Name}",
                PriceInfo      = new ProductPriceModel
                {
                    Price         = SetFormattedPrice(new ProductPriceModel.PriceItem(0, orderRow.UnitPriceExcludingVat, orderRow.VatRate, orderRow.UnitPriceExcludingVat * (1 + orderRow.VatRate)), includeVat, currency),
                    CampaignPrice = campaignPrice != null?SetFormattedPrice(campaignPrice, includeVat, currency) : null
                },
                TotalPrice = currency.Format(totalPrice, true, CultureInfo.CurrentUICulture),
                Link       = productModel?.SelectedVariant.MapTo <LinkModel>()
            };

            return(model);
        }
예제 #2
0
        private OrderDetailsViewModel.OrderRowItem BuildOrderRow(OrderRow orderRow, Currency currency)
        {
            var productModel           = _productModelBuilder.BuildFromVariant(_variantService.Get(orderRow.ArticleNumber));
            var shoppingCartIncludeVat = _requestModelAccessor.RequestModel.Cart.IncludeVAT;

            var unitOfMeasurement             = _unitOfMeasurementService.Get(orderRow.SKUCode);
            var unitOfMeasurementFormatString = $"0.{new string('0', unitOfMeasurement?.DecimalDigits ?? 0)}";

            var totalPrice = shoppingCartIncludeVat ? orderRow.TotalPriceWithVat : orderRow.TotalPrice;

            var campaign = orderRow.Campaign;
            var model    = new OrderDetailsViewModel.OrderRowItem
            {
                DeliveryId     = orderRow.DeliveryID,
                Brand          = productModel == null ? null : _fieldDefinitionService.Get <ProductArea>("Brand")?.GetTranslation(productModel.GetValue <string>("Brand")),
                Name           = productModel == null ? orderRow.ArticleNumber : productModel.GetValue <string>(SystemFieldDefinitionConstants.Name),
                QuantityString = $"{orderRow.Quantity.ToString(unitOfMeasurementFormatString, CultureInfo.CurrentUICulture.NumberFormat)} {unitOfMeasurement?.Localizations.CurrentUICulture.Name ?? orderRow.SKUCode}",
                PriceInfo      = new ProductPriceModel
                {
                    CampaignPrice = campaign == null ? null : SetFormattedPrice(new ProductPriceModel.CampaignPriceItem(0, orderRow.UnitCampaignPrice, orderRow.VATPercentage, orderRow.UnitCampaignPrice * (1 + orderRow.VATPercentage), campaign.ID), shoppingCartIncludeVat, currency),
                    Price         = SetFormattedPrice(new ProductPriceModel.PriceItem(0, orderRow.UnitListPrice, orderRow.VATPercentage, orderRow.UnitListPrice * (1 + orderRow.VATPercentage)), shoppingCartIncludeVat, currency)
                },
                TotalPrice = currency.Format(totalPrice, true, CultureInfo.CurrentUICulture),
                Link       = productModel?.SelectedVariant.MapTo <LinkModel>()
            };

            return(model);
        }
예제 #3
0
        private OrderRowViewModel BuildOrderRow(OrderRowCarrier orderRow, Currency currency, bool includeVat)
        {
            var variant     = _variantService.Get(orderRow.ArticleNumber);
            var baseProduct = _baseProductService.Get(variant?.BaseProductSystemId ?? Guid.Empty);

            var name  = variant?.Localizations.CurrentCulture.Name.NullIfWhiteSpace() ?? baseProduct?.Localizations.CurrentCulture.Name.NullIfWhiteSpace() ?? orderRow.ArticleNumber;
            var url   = variant == null ? null : _urlService.GetUrl(variant);
            var image = (variant?.Fields.GetValue <IList <Guid> >(SystemFieldDefinitionConstants.Images)?.FirstOrDefault()
                         ?? baseProduct?.Fields.GetValue <IList <Guid> >(SystemFieldDefinitionConstants.Images)?.FirstOrDefault())
                        .MapTo <ImageModel>();

            var price      = GetPriceModel(orderRow, currency, includeVat);
            var totalPrice = new ProductPriceModel.PriceItem(decimal.MinusOne, orderRow.TotalPrice, orderRow.VATPercentage, orderRow.TotalPriceWithVAT)
            {
                FormatPrice = b => currency.Format(includeVat ? orderRow.TotalPriceWithVAT : orderRow.TotalPrice, b, CultureInfo.CurrentUICulture)
            };

            var unitOfMeasurement             = _unitOfMeasurementService.Get(orderRow.SKUCode);
            var unitOfMeasurementFormatString = $"0.{new string('0', unitOfMeasurement?.DecimalDigits ?? 0)}";

            var model = new OrderRowViewModel
            {
                ArticleNumber  = orderRow.ArticleNumber,
                Name           = name,
                RowSystemId    = orderRow.ID,
                Quantity       = orderRow.Quantity,
                QuantityString = orderRow.Quantity.ToString(unitOfMeasurementFormatString, CultureInfo.CurrentUICulture.NumberFormat).Replace(",", "."),
                Url            = url,
                Image          = image?.GetUrlToImage(Size.Empty, new Size(200, 120)).Url,
                TotalPrice     = totalPrice.FormatPrice(true),
                Price          = price.Price.FormatPrice(true),
                CampaignPrice  = price.CampaignPrice?.FormatPrice(true),
                IsFreeGift     = orderRow.IsAutoGenerated
            };

            if (orderRow.CampaignID == Guid.Empty)
            {
                return(model);
            }

            var campaign = _moduleECommerce.Campaigns.GetCampaign(orderRow.CampaignID, _moduleECommerce.AdminToken);

            if (campaign == null)
            {
                return(model);
            }
            var requestModel = _requestModelAccessor.RequestModel;
            var channel      = campaign.Data.Channels.Find(x => x.ChannelId == requestModel.ChannelModel.SystemId);

            if (channel != null && channel.CampainPage != null && channel.CampainPage.EntitySystemId != Guid.Empty)
            {
                model.CampaignLink = channel.CampainPage.MapTo <LinkModel>()?.Href;
            }

            return(model);
        }
예제 #4
0
        private OrderRowViewModel BuildOrderRow(OrderRow orderRow, Currency currency, bool includeVat, SalesOrder salesOrder)
        {
            var variant     = _variantService.Get(orderRow.ArticleNumber);
            var baseProduct = _baseProductService.Get(variant?.BaseProductSystemId ?? Guid.Empty);

            var name  = variant?.Localizations.CurrentCulture.Name.NullIfWhiteSpace() ?? baseProduct?.Localizations.CurrentCulture.Name.NullIfWhiteSpace() ?? orderRow.ArticleNumber;
            var url   = variant == null ? null : _urlService.GetUrl(variant);
            var image = (variant?.Fields.GetValue <IList <Guid> >(SystemFieldDefinitionConstants.Images)?.FirstOrDefault()
                         ?? baseProduct?.Fields.GetValue <IList <Guid> >(SystemFieldDefinitionConstants.Images)?.FirstOrDefault())
                        .MapTo <ImageModel>();

            var price      = GetPriceModel(orderRow, currency, includeVat, salesOrder);
            var totalPrice = new ProductPriceModel.PriceItem(decimal.MinusOne, orderRow.TotalExcludingVat, orderRow.VatRate, orderRow.TotalIncludingVat)
            {
                FormatPrice = b => currency.Format(includeVat ? orderRow.TotalIncludingVat : orderRow.TotalExcludingVat, b, CultureInfo.CurrentUICulture)
            };

            var totalCampaignPrice = GetTotalCampaignPrice(price.CampaignPrice, currency, orderRow, includeVat);

            var unitOfMeasurement = orderRow.UnitOfMeasurementSystemId.HasValue
                ? _unitOfMeasurementService.Get(orderRow.UnitOfMeasurementSystemId.Value)
                : null;
            var unitOfMeasurementFormatString = $"0.{new string('0', unitOfMeasurement?.DecimalDigits ?? 0)}";

            var model = new OrderRowViewModel
            {
                ArticleNumber                  = orderRow.ArticleNumber,
                Name                           = name,
                RowSystemId                    = orderRow.SystemId,
                Quantity                       = orderRow.Quantity,
                QuantityString                 = orderRow.Quantity.ToString(unitOfMeasurementFormatString, CultureInfo.CurrentUICulture.NumberFormat).Replace(",", "."),
                Url                            = url,
                Image                          = image?.GetUrlToImage(Size.Empty, new Size(200, 120)).Url,
                TotalPrice                     = totalPrice.FormatPrice(true),
                TotalCampaignPrice             = totalCampaignPrice is null ? string.Empty : totalCampaignPrice.FormatPrice(true),
                Price                          = price.Price.FormatPrice(true),
                CampaignPrice                  = price.CampaignPrice?.FormatPrice(true),
                IsFreeGift                     = orderRow.OrderRowType == OrderRowType.Discount,
                TotalPriceIncludingVat         = totalPrice.PriceWithVat,
                TotalPriceExcludingVat         = totalPrice.Price,
                TotalCampaignPriceIncludingVat = totalCampaignPrice is null ? null : totalCampaignPrice.PriceWithVat,
                TotalCampaignPriceExcludingVat = totalCampaignPrice is null ? null : totalCampaignPrice.Price
            };

            return(model);
        }