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); }
/// <summary> /// Build the product block view model /// </summary> /// <param name="blockModel">The current product block</param> /// <returns>Return the product block view model</returns> public virtual ProductBlockViewModel Build(BlockModel blockModel) { var data = blockModel.MapTo <ProductBlockViewModelData>(); var viewModel = new ProductBlockViewModel(); var channel = _requestModelAccessor.RequestModel.ChannelModel.Channel; if (data != null) { viewModel.FooterLinkText = data.LinkText; if (data.LinkToCategorySystemId != Guid.Empty) { viewModel.FooterLinkUrl = data.LinkToCategorySystemId.MapTo <Category>().GetUrl(_requestModelAccessor.RequestModel.ChannelModel.SystemId, true); } else if (!string.IsNullOrEmpty(data.LinkToPage.Href)) { viewModel.FooterLinkUrl = data.LinkToPage.Href; } viewModel.Title = data.Title; var products = new List <ProductModel>(); if (data.SectionProductsType == BlockProductsType.Products) { products.AddRange(data.ProductSystemIds.Select(x => _productModelBuilder.BuildFromVariant(_variantService.Get(x)) ?? _productModelBuilder.BuildFromBaseProduct(_baseProductService.Get(x), channel)).Where(x => x != null)); } else { var searchQuery = new SearchQuery { PageSize = data.NumberOfProducts }; switch (data.SectionProductsType) { case BlockProductsType.Category: searchQuery.CategoryShowRecursively = true; searchQuery.SortBy = data.ProductSorting; searchQuery.CategorySystemId = data.CategorySystemId; break; case BlockProductsType.ProductList: searchQuery.ProductListSystemId = data.ProductListSystemId; break; } var response = _productSearchService.Search(searchQuery); if (response?.Hits != null) { products.AddRange(_productSearchService .Transform(searchQuery, response) .Items .Value .OfType <ProductSearchResult>() .Select(x => x.Item)); } } viewModel.Products = products.Select(x => _productItemViewModelBuilder.Build(x)).ToList(); } return(viewModel); }
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); }
private IEnumerable <ProductModel> CreateProductModel(IReadOnlyCollection <IHit <ProductDocument> > hits, SearchQuery searchQuery, Guid channelSystemId) { if (hits.Count == 0) { yield break; } foreach (var hit in hits) { ProductModel model = null; var item = hit.Source; var variants = _variantService.Get(item.VariantSystemIds) .Where(x => !string.IsNullOrEmpty(_urlService.GetUrl(x, new ProductUrlArgs(channelSystemId)))) .OrderBy(x => x.SortIndex) .ToList(); if (variants.Count == 0) { continue; } if (item.IsBaseProduct) { var baseProduct = _baseProductService.Get(item.BaseProductSystemId); if (baseProduct == null) { continue; } model = CreateProductModel(searchQuery, baseProduct, variants, channelSystemId); } else if (variants.Count > 1) { model = CreateProductModel(searchQuery, null, variants, channelSystemId); } else { model = _productModelBuilder.BuildFromVariant(variants[0]); } if (model != null) { yield return(model); } } }
public ProductPageViewModel Build(Variant variant) { var productModel = _productModelBuilder.BuildFromVariant(variant); var viewModel = Build(productModel); viewModel.BundleProducts = GetBundles(variant); viewModel.MostSoldProducts = GetMostSoldProducts(variant.Id); SetFilters(viewModel, productModel, _requestModelAccessor.RequestModel.WebsiteModel.SystemId, _requestModelAccessor.RequestModel.ChannelModel.SystemId); return(viewModel); }
public virtual ProductItemViewModel Build(Variant variant) { var productModel = _productModelBuilder.BuildFromVariant(variant); return(productModel == null ? null : Build(productModel)); }