Пример #1
0
        public virtual ProductItemViewModel Build(ProductModel productModel, bool inProductListPage = true)
        {
            var currency          = Cart.Currency;
            var websiteModel      = _requestModelAccessor.RequestModel.WebsiteModel;
            var productPriceModel = _productPriceModelBuilder.Build(productModel.SelectedVariant, currency, _requestModelAccessor.RequestModel.ChannelModel.Channel);

            return(new ProductItemViewModel
            {
                Id = productModel.SelectedVariant.Id,
                Price = productPriceModel,
                StockStatusDescription = _stockService.GetStockStatusDescription(productModel.SelectedVariant),
                Currency = currency,
                IsInStock = _stockService.HasStock(productModel.SelectedVariant),
                Images = productModel.GetValue <IList <Guid> >(SystemFieldDefinitionConstants.Images).MapTo <IList <ImageModel> >(),
                Color = _fieldDefinitionService.Get <ProductArea>("Color").GetTranslation(productModel.GetValue <string>("Color")),
                Size = _fieldDefinitionService.Get <ProductArea>("Size").GetTranslation(productModel.GetValue <string>("Size")),
                Brand = _fieldDefinitionService.Get <ProductArea>("Brand").GetTranslation(productModel.GetValue <string>("Brand")),
                Description = productModel.GetValue <string>(SystemFieldDefinitionConstants.Description),
                Name = productModel.GetValue <string>(SystemFieldDefinitionConstants.Name),
                Url = productModel.GetUrl(websiteModel.SystemId, channelSystemId: _requestModelAccessor.RequestModel.ChannelModel.SystemId),
                QuantityFieldId = Guid.NewGuid().ToString(),
                ShowBuyButton = websiteModel.GetValue <bool>(AcceleratorWebsiteFieldNameConstants.ShowBuyButton),
                ShowQuantityField = inProductListPage ? websiteModel.GetValue <bool>(AcceleratorWebsiteFieldNameConstants.ShowQuantityFieldProductList)
                                                      : websiteModel.GetValue <bool>(AcceleratorWebsiteFieldNameConstants.ShowQuantityFieldProductPage),
                UseVariantUrl = productModel.UseVariantUrl
            });
        }
        public virtual ProductItemViewModel Build(ProductModel productModel, bool inProductListPage = true)
        {
            var cartContext = _cartContextAccessor.CartContext;
            var currency    = (cartContext == null) ? _currencyService.Get(_requestModelAccessor.RequestModel.CountryModel.Country.CurrencySystemId)
                                                 : _currencyService.Get(cartContext.CurrencyCode);
            var country = (cartContext == null) ? _requestModelAccessor.RequestModel.CountryModel.Country
                                                : _countryService.Get(cartContext.CountryCode);
            var websiteModel      = _requestModelAccessor.RequestModel.WebsiteModel;
            var productPriceModel = _productPriceModelBuilder.Build(productModel.SelectedVariant, currency, _requestModelAccessor.RequestModel.ChannelModel.Channel, country);
            var images            = productModel.SelectedVariant.Fields.GetValue <IList <Guid> >(SystemFieldDefinitionConstants.Images).MapTo <IList <ImageModel> >();

            return(new ProductItemViewModel
            {
                SystemId = productModel.SelectedVariant.SystemId,
                Id = productModel.SelectedVariant.Id,
                Price = productPriceModel,
                FormattedPrice = productPriceModel.Price.FormatPrice(true),
                StockStatusDescription = _stockService.GetStockStatusDescription(productModel.SelectedVariant),
                Currency = currency,
                IsInStock = _stockService.HasStock(productModel.SelectedVariant),
                Images = images,
                ImageUrls = images.Select(image => image.GetUrlToImage(new System.Drawing.Size(220, 300), new System.Drawing.Size(280, 400)).Url).ToArray(),
                Color = _fieldDefinitionService.Get <ProductArea>("Color").GetTranslation(productModel.GetValue <string>("Color")),
                Size = _fieldDefinitionService.Get <ProductArea>("Size").GetTranslation(productModel.GetValue <string>("Size")),
                Brand = _fieldDefinitionService.Get <ProductArea>("Brand").GetTranslation(productModel.GetValue <string>("Brand")),
                Description = productModel.GetValue <string>(SystemFieldDefinitionConstants.Description),
                Name = productModel.GetValue <string>(SystemFieldDefinitionConstants.Name),
                Url = productModel.GetUrl(websiteModel.SystemId, channelSystemId: _requestModelAccessor.RequestModel.ChannelModel.SystemId),
                QuantityFieldId = Guid.NewGuid().ToString(),
                ShowBuyButton = websiteModel.GetValue <bool>(AcceleratorWebsiteFieldNameConstants.ShowBuyButton),
                ShowQuantityField = inProductListPage ? websiteModel.GetValue <bool>(AcceleratorWebsiteFieldNameConstants.ShowQuantityFieldProductList)
                                                      : websiteModel.GetValue <bool>(AcceleratorWebsiteFieldNameConstants.ShowQuantityFieldProductPage),
                UseVariantUrl = productModel.UseVariantUrl
            });
        }
Пример #3
0
        private void BuildPrices(VariantInfo pageModel, Variant entity, Currency currency, Guid channelSystemId)
        {
            var channel           = _channelService.Get(channelSystemId);
            var productPriceModel = _priceModelBuilder.Build(entity, currency, channel);

            if (productPriceModel.Price == null)
            {
                return;
            }
            pageModel.ListPrice            = productPriceModel.Price.Price;
            pageModel.VatPercentage        = productPriceModel.Price.VatPercentage;
            pageModel.CampaignPriceWithVat = productPriceModel.CampaignPrice.PriceWithVat;
        }
        private void BuildPrices(VariantInfo pageModel, Variant entity, Currency currency, Guid channelSystemId)
        {
            var channel     = _channelService.Get(channelSystemId);
            var cartContext = _cartContextAccessor.CartContext;
            var country     = (cartContext == null) ? _requestModelAccessor.RequestModel.CountryModel.Country
                                                : _countryService.Get(cartContext.CountryCode);
            var productPriceModel = _priceModelBuilder.Build(entity, currency, channel, country);

            if (productPriceModel.Price == null)
            {
                return;
            }
            pageModel.ListPrice            = productPriceModel.Price.Price;
            pageModel.VatPercentage        = productPriceModel.Price.VatPercentage;
            pageModel.CampaignPriceWithVat = productPriceModel.CampaignPrice.PriceWithVat;
        }