Exemple #1
0
        private ProductTileViewModel CreateProductViewModelForVariant(ProductContent product, VariationContent variant)
        {
            if (variant == null)
            {
                return(null);
            }

            var viewModel = CreateProductViewModelForEntry(variant);

            viewModel.Brand = product is FashionProduct ? ((FashionProduct)product).Brand : string.Empty;

            return(viewModel);
        }
Exemple #2
0
 public static IEnumerable <VariationModel> VariationModels(this ProductContent productContent)
 {
     return(_contentRepository.Value
            .GetItems(productContent.GetVariants(RelationRepository.Value), productContent.Language)
            .OfType <VariationContent>()
            .Select(x => new VariationModel
     {
         Code = x.Code,
         LanguageId = productContent.Language.Name,
         Name = x.DisplayName,
         DefaultAssetUrl = (x as IAssetContainer).DefaultImageUrl()
     }));
 }
        public static string TopCategory(this ProductContent productContent)
        {
            var parent = _contentLoader.Service.Get <NodeContent>(productContent.ParentLink);

            if (parent == null)
            {
                return(null);
            }

            var topParent = _contentLoader.Service.Get <NodeContent>(parent.ParentLink);

            return(topParent?.DisplayName);
        }
 public static IEnumerable <VariationModel> VariationModels(this ProductContent productContent)
 {
     return(ContentLoader.Value
            .GetItems(productContent.GetVariants(RelationRepository.Value), productContent.Language)
            .OfType <VariationContent>()
            .Select(x => new VariationModel
     {
         Code = x.Code,
         LanguageId = productContent.Language.Name,
         Name = x.DisplayName,
         DefaultAssetUrl = UrlResolver.Value.GetUrl((x as IAssetContainer).CommerceMediaCollection.FirstOrDefault()?.AssetLink)
     }));
 }
        /// <summary>
        /// Converts the <param name="content"></param> to an <see cref="Boilerplate.Web.Mvc.OpenGraph.OpenGraphProductItem"/>.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <returns>The <see cref="Boilerplate.Web.Mvc.OpenGraph.OpenGraphProductItem"/> for the <param name="content"></param>.</returns>
        /// <exception cref="T:System.Web.HttpException">The Web application is running under IIS 7 in Integrated mode.</exception>
        /// <exception cref="T:System.ArgumentNullException">The variants are <see langword="null" />.</exception>
        /// <exception cref="T:System.InvalidOperationException">The current <see cref="T:System.Uri" /> instance is not an absolute instance.</exception>
        /// <exception cref="T:System.ArgumentException">The specified <see cref="UriPartial.Authority"/> is not valid.</exception>
        /// <exception cref="T:System.NotSupportedException">The query collection is read-only.</exception>
        /// <exception cref="T:System.MemberAccessException">The <see cref="T:System.Lazy`1" /> instance is initialized to use the default constructor of the type that is being lazily initialized, and permissions to access the constructor are missing.</exception>
        /// <exception cref="T:System.MissingMemberException">The <see cref="T:System.Lazy`1" /> instance is initialized to use the default constructor of the type that is being lazily initialized, and that type does not have a public, parameterless constructor.</exception>
        public static OpenGraphProductItem ToOpenGraphProductItem(this ProductContent content)
        {
            ContentReference variantReference = content.GetVariants().FirstOrDefault();

            VariationContent variation;

            if (ContentLoader.Value.TryGet(contentLink: variantReference, content: out variation))
            {
                return(variation.ToOpenGraphProductItem(openGraphCondition: OpenGraphCondition.New));
            }

            Log.Debug($"[Social Tags] Product with id '{content.ContentLink.ID}' has no variations.");
            return(null);
        }
Exemple #6
0
        public IEnumerable <CartItem> GetCartItems()
        {
            if (CartHelper.IsEmpty)
            {
                return(Enumerable.Empty <CartItem>());
            }

            var cartItems = new List <CartItem>();
            var lineItems = CartHelper.Cart.GetAllLineItems();

            // In order to show the images for the items in the cart, we need to load the variants
            var variants = _contentLoader.GetItems(lineItems.Select(x => _referenceConverter.GetContentLink(x.Code)),
                                                   _preferredCulture).OfType <VariationContent>();

            foreach (var lineItem in lineItems)
            {
                VariationContent variant = variants.FirstOrDefault(x => x.Code == lineItem.Code);
                ProductContent   product = _contentLoader.Get <ProductContent>(variant.GetParentProducts().FirstOrDefault());
                CartItem         item    = new CartItem
                {
                    Code          = lineItem.Code,
                    DisplayName   = lineItem.DisplayName,
                    ImageUrl      = variant.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "",
                    ExtendedPrice = lineItem.ToMoney(lineItem.ExtendedPrice + lineItem.OrderLevelDiscountAmount),
                    PlacedPrice   = lineItem.ToMoney(lineItem.PlacedPrice),
                    DiscountPrice = lineItem.ToMoney(Math.Round(((lineItem.PlacedPrice * lineItem.Quantity) - lineItem.Discounts.Cast <LineItemDiscount>().Sum(x => x.DiscountValue)) / lineItem.Quantity, 2)),
                    Quantity      = lineItem.Quantity,
                    Url           = lineItem.GetUrl(),
                    Variant       = variant,
                    Discounts     = lineItem.Discounts.Cast <LineItemDiscount>().Select(x => new OrderDiscountModel
                    {
                        Discount    = new Money(x.DiscountAmount, new Currency(CartHelper.Cart.BillingCurrency)),
                        Displayname = x.DisplayMessage
                    })
                };

                if (product is FashionProduct)
                {
                    var fashionProduct = (FashionProduct)product;
                    var fashionVariant = (FashionVariant)variant;
                    item.Brand = fashionProduct.Brand;
                    var variations = _productService.GetVariations(fashionProduct);
                    item.AvailableSizes = variations.Where(x => x.Color == fashionVariant.Color).Select(x => x.Size);
                }

                cartItems.Add(item);
            }

            return(cartItems);
        }
Exemple #7
0
        public static List <Price> ListingPrices(this ProductContent productContent)
        {
            var originalPrices   = productContent.OriginalPriceValues();
            var discountedPrices = new List <Price>();

            foreach (var originalPrice in originalPrices)
            {
                var discountedPrice = _promotionService.Service.GetDiscountPrice(originalPrice.CatalogKey,
                                                                                 originalPrice.MarketId, originalPrice.UnitPrice.Currency);
                discountedPrices.Add(new Price(discountedPrice));
            }
            return
                (discountedPrices);
        }
        private static List <string> GetNodes(ProductContent currentContent)
        {
            var nodeList = new List <string>();

            foreach (var nodeRelation in currentContent.GetCategories())
            {
                var currentNode = _contentLoader.Value.Get <NodeContent>(nodeRelation);
                if (currentNode != null)
                {
                    AddParentNodes(currentNode, nodeList);
                }
            }

            return(nodeList);
        }
        public static Price DefaultPrice(this ProductContent productContent, ReadOnlyPricingLoader pricingLoader, IRelationRepository relationRepository)
        {
            var maxPrice = new Price();

            var variationLinks = productContent.GetVariants(relationRepository);

            foreach (var variationLink in variationLinks)
            {
                var defaultPrice = pricingLoader.GetDefaultPrice(variationLink);
                if (defaultPrice.UnitPrice.Amount > maxPrice.UnitPrice.Amount)
                {
                    maxPrice = defaultPrice;
                }
            }

            return(maxPrice);
        }
Exemple #10
0
 public static List <ProductContent> Restore(this IEnumerable <ProductContentSnapshot> items, Action <object> applier)
 {
     return(items.Select(x =>
     {
         var content = new ProductContent(applier);
         content.Route(
             new Events.V1.ContentAddedToProduct(
                 x.ProductId,
                 x.ProductContentId,
                 x.Description,
                 x.VariantValue.VariantTypeValueId,
                 x.Status,
                 x.VariantValue.VariantType)
             );
         return content;
     }).ToList());
 }
Exemple #11
0
        private IList <string> TagsForProduct(ProductContent product)
        {
            var result = new List <string>();
            var link   = product.ParentLink;

            if (_contentLoader.TryGet(link, out NodeContent category))
            {
                result.Add(category.Code.SanitizeKey());
                result.AddRange(ParentTagsForCategory(category));
            }
            else
            {
                _log.Warning("Parent link is not linking to a category as expected");
            }

            return(result);
        }
        public void AddToList_AddStreamingContentObject()
        {
            Repo productRepo = new Repo();
            List <ProductContent> content = productRepo.GetProductList();

            ProductContent contents   = new ProductContent("Black Bread", "Sally", 16, 20.0m, BakeType.Bread);
            ProductContent contentTwo = new ProductContent("Blue Bread", "Silly Billy", 10, 10.0m, BakeType.Bread);

            int expected = 2;

            productRepo.AddToList(contents);
            productRepo.AddToList(contentTwo);

            int actual = content.Count;

            Assert.AreEqual(expected, actual);
        }
        public ProductListViewModel(ProductContent content,
                                    IMarket currentMarket,
                                    CustomerContact currentContact)
            : this()
        {
            ImageUrl     = content.GetDefaultImage();
            IsVariation  = false;
            AllImageUrls = content.AssetUrls();

            PopulateCommonData(content, currentMarket, currentContact);

            var variation = content.GetFirstVariation();

            if (variation != null)
            {
                PopulatePrices(variation, currentMarket);
            }
        }
        public override QuicksilverVsfProduct Map(ProductContent source)
        {
            if (source.GetOriginalType() == typeof(FashionProduct))
            {
                var fashionContent = (FashionProduct)source;
                var product        = BaseMap(source);

                product.Description = fashionContent.Description.ToString();

                var configurableOptions = product.ConfigurableOptions;
                product.ColorOptions = configurableOptions.FirstOrDefault(o => o.Label == "Color")?.Values.Select(x => x.ValueIndex);
                product.SizeOptions  = configurableOptions.FirstOrDefault(o => o.Label == "Size")?.Values.Select(x => x.ValueIndex);

                return(product);
            }

            throw new ArgumentException("Source not supported");
        }
        private ProductTileViewModel CreateProductViewModelForVariant(ProductContent product, VariationContent variant)
        {
            if (variant == null)
            {
                return(null);
            }

            var viewModel = CreateProductViewModelForEntry(variant);

            if (product == null)
            {
                return(viewModel);
            }

            viewModel.Brand = product is GenericProduct baseProduct ? baseProduct.Brand : string.Empty;

            return(viewModel);
        }
        public void RemoveProductContentsFromListTest()
        {
            Repo productRepo = new Repo();
            List <ProductContent> content = productRepo.GetProductList();

            ProductContent contents   = new ProductContent("Black Bread", "Sally", 16, 20.0m, BakeType.Bread);
            ProductContent contentTwo = new ProductContent("Blue Bread", "Silly Billy", 10, 10.0m, BakeType.Bread);

            int expected = 1;

            productRepo.AddToList(contents);
            productRepo.AddToList(contentTwo);

            productRepo.RemoveProductContentFromList("Sally");

            int actual = content.Count;

            Assert.AreEqual(expected, actual);
        }
Exemple #17
0
        public static IEnumerable <string> GetParentBlackListACL(this ProductContent productContent)
        {
            var parents = productContent.ParentNodeRelations();

            if (parents == null || !parents.Any())
            {
                return(Enumerable.Empty <string>());
            }

            return(parents.SelectMany(p =>
            {
                var parent = _contentLoader.Service.Get <BaseNode>(p);
                if (parent == null)
                {
                    return Enumerable.Empty <string>();
                }

                return parent.ACLBlackList?.Split(',') ?? Enumerable.Empty <string>();
            }));
        }
        public static Money DefaultPrice(this ProductContent productContent)
        {
            var pricingLoader      = ServiceLocator.Current.GetInstance <ReadOnlyPricingLoader>();
            var relationRepository = ServiceLocator.Current.GetInstance <IRelationRepository>();

            var maxPrice = new Price();

            var variationLinks = productContent.GetVariants(relationRepository);

            foreach (var variationLink in variationLinks)
            {
                var defaultPrice = pricingLoader.GetDefaultPrice(variationLink);
                if (defaultPrice.UnitPrice.Amount > maxPrice.UnitPrice.Amount)
                {
                    maxPrice = defaultPrice;
                }
            }

            return(maxPrice.UnitPrice);
        }
        private ProductViewModel CreateProductViewModel(ProductContent product, VariationContent variation)
        {
            if (variation == null)
            {
                return(null);
            }

            ContentReference productContentReference;

            if (product != null)
            {
                productContentReference = product.ContentLink;
            }
            else
            {
                productContentReference = variation.GetParentProducts(_relationRepository).FirstOrDefault();
                if (ContentReference.IsNullOrEmpty(productContentReference))
                {
                    return(null);
                }
            }
            var market   = _currentMarket.GetCurrentMarket();
            var currency = _currencyService.GetCurrentCurrency();

            var originalPrice   = _pricingService.GetCurrentPrice(variation.Code);
            var discountedPrice = originalPrice.HasValue ? GetDiscountPrice(variation, market, currency, originalPrice.Value) : (Money?)null;

            var image = variation.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "";
            var brand = product is FashionProduct ? ((FashionProduct)product).Brand : string.Empty;

            return(new ProductViewModel
            {
                DisplayName = product != null ? product.DisplayName : variation.DisplayName,
                PlacedPrice = originalPrice.HasValue ? originalPrice.Value : new Money(0, currency),
                DiscountedPrice = discountedPrice,
                ImageUrl = image,
                Url = variation.GetUrl(),
                Brand = brand,
                IsAvailable = originalPrice.HasValue
            });
        }
Exemple #20
0
        public ProductContent SingleProductPage(int PK)
        {
            ProductContent   pc             = new ProductContent();          //ModelVue
            OneProductEntity oneProductPage = _getOneProductRepo.GetOne(PK); //Récupération mon entity

            pc.Quantite        = oneProductPage.Quantite;
            pc.Type            = oneProductPage.Type;
            pc.Title           = oneProductPage.NomProduit;
            pc.Bio             = oneProductPage.Bio;
            pc.DatePeremption  = oneProductPage.DatePeremption;
            pc.Image           = oneProductPage.Photo;
            pc.Text            = oneProductPage.Description;
            pc.Etat            = oneProductPage.Etat;
            pc.DateProposition = oneProductPage.DateProposition;
            pc.Marque          = oneProductPage.Marque;
            pc.IdProduit       = oneProductPage.IdProduit;
            pc.Prenom          = oneProductPage.Prenom;
            pc.Nom             = oneProductPage.Nom;

            return(pc);
        }
Exemple #21
0
        public void OnProductContent(NodeContent parent, ProductContent productContent)
        {
            _categoryTreeBuilder.AddProductCount(parent);

            var vsfProduct = _productMapper.Map(productContent);

            _indexingService.AddForIndexing(vsfProduct);

            var productVariations = productContent
                                    .GetVariants()
                                    .ToList();

            foreach (var variantContent in productVariations)
            {
                var variant          = _contentLoaderWrapper.Get <VariationContent>(variantContent);
                var vsfProductSimple = _simpleProductMapper.Map(variant);

                _indexingService.AddForIndexing(vsfProductSimple);
            }

            _contentPropertyLoader.ReadProperties(productContent);
        }
Exemple #22
0
        public void ExportProduct(ProductContent product, string deletedVariantCode)
        {
            var configuration = KachingConfiguration.Instance;

            _log.Information("ExportProduct: " + product.Code);

            // Bail if not published
            if (!_publishedStateAssessor.IsPublished(product))
            {
                _log.Information("Skipped product export because it's not yet published");
                return;
            }

            // Since Ka-ching uses tags for category hierachy we need to go
            // up the tree of nodes to find the correct tags for the product
            var tags           = TagsForProduct(product);
            var kachingProduct = _productFactory.BuildKaChingProduct(product, tags, configuration, deletedVariantCode);
            var products       = new List <Product>();

            products.Add(kachingProduct);
            PostKachingProducts(products, _configuration.ProductsImportUrl);
        }
        public void ReadProperties(ProductContent product)
        {
            var variants = product.GetVariants();

            foreach (var variant in variants)
            {
                var variantProperties = _contentLoaderWrapper.GetVariantVsfProperties(variant);
                foreach (var variantProperty in variantProperties)
                {
                    if (variantProperty.Value == null)
                    {
                        continue;
                    }

                    var existingProperty = _epiContentProperties.FirstOrDefault(x => x.Id == variantProperty.PropertyDefinitionID);

                    if (existingProperty == null)
                    {
                        _epiContentProperties.Add(new EpiContentProperty
                        {
                            Name   = variantProperty.Name,
                            Id     = variantProperty.PropertyDefinitionID,
                            Values = new List <string>()
                            {
                                variantProperty.Value.ToString()
                            }
                        });
                    }
                    else
                    {
                        if (!existingProperty.Values.Contains(variantProperty.Value))
                        {
                            existingProperty.Values.Add(variantProperty.Value.ToString());
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Gets inventory for all of the variations for a given product
        /// </summary>
        /// <remarks>
        /// If none of the variations has stock, then 0 is returned.
        /// </remarks>
        /// <param name="content">The content.</param>
        /// <returns>The sum of all variation's stock</returns>
        public static decimal GetStock(this ProductContent content)
        {
            if (content == null)
            {
                return(0);
            }

            var varitions = content.GetVaritions();

            if (varitions == null)
            {
                return(0);
            }

            decimal stock = 0;

            foreach (VariationContent varition in varitions)
            {
                stock += varition.GetStock();
            }

            return(stock);
        }
Exemple #25
0
        public List <ProductContent> GetProductModelByPage(int page, string searchString, string type, string sortOrder)
        {
            List <ProductContent>            lpc = new List <ProductContent>();                                                                                             //ModelVue
            List <GetSixLatestPrductsEntity> allProductsFromDb = ((GetSixLatestProductsRepository)_getSixRepo).GetProductEntityByPage(page, searchString, type, sortOrder); //Récupération mon entity

            foreach (GetSixLatestPrductsEntity prod in allProductsFromDb)
            {
                ProductContent pc = new ProductContent();
                pc.Title          = prod.NomProduit;
                pc.Text           = prod.Description;
                pc.DatePeremption = prod.DatePeremption;
                pc.Bio            = prod.Bio;
                pc.Quantite       = prod.Quantite;
                pc.Nom            = prod.Nom;
                pc.Prenom         = prod.Prenom;
                pc.Type           = prod.Type;
                pc.IdProduit      = prod.IdProduit;
                pc.Image          = prod.Photo;

                lpc.Add(pc);
            }
            return(lpc);
        }
Exemple #26
0
        //List<ProductContent> lpc = new List<ProductContent>(); //ModelVue
        //List<ProductEntity> productsFromDb = _productRepo.Get();//Récupération mon entity
        //List<UtilisateurEntity> usersFromDb = _utilisateurRepo.Get();//Récupération mon entity
        //List<TypeEntity> typesFromDb = _typeRepo.Get();//Récupération mon entity

        //foreach (ProductEntity produit in productsFromDb)
        //{
        //    ProductContent pc = new ProductContent();
        //    pc.Title = produit.Nom;
        //    pc.Text = produit.Description;
        //    pc.DatePeremption = produit.DatePeremption;
        //    pc.Bio = produit.Bio;
        //    pc.Quantite = produit.Quantite;

        //    foreach (UtilisateurEntity utilisateur in usersFromDb)
        //    {
        //    pc.Nom = utilisateur.Nom;
        //    pc.Prenom = utilisateur.Prenom;
        //    }
        //    foreach (TypeEntity type in typesFromDb)
        //    {
        //    pc.Type = type.Label;
        //    }
        //    lpc.Add(pc);
        //    }

        //return lpc;
        //}
        public List <ProductContent> GetSixLatestProducts()
        {
            List <ProductContent>            lpc = new List <ProductContent>();     //ModelVue
            List <GetSixLatestPrductsEntity> sixProductsFromDb = _getSixRepo.Get(); //Récupération mon entity

            foreach (GetSixLatestPrductsEntity prod in sixProductsFromDb)
            {
                ProductContent pc = new ProductContent();
                pc.Title          = prod.NomProduit;
                pc.Text           = prod.Description;
                pc.DatePeremption = prod.DatePeremption;
                pc.Bio            = prod.Bio;
                pc.Quantite       = prod.Quantite;
                pc.Nom            = prod.Nom;
                pc.Prenom         = prod.Prenom;
                pc.Type           = prod.Type;
                pc.IdProduit      = prod.IdProduit;
                pc.Image          = prod.Photo;

                lpc.Add(pc);
            }
            return(lpc);
        }
        protected virtual IEnumerable <Media> GetGallery(ProductContent content)
        {
            if (content == null)
            {
                return(null);
            }

            var result   = new List <Media>();
            var variants = content.GetVariants();

            foreach (var variant in variants)
            {
                var imageReference = ContentLoaderWrapper.Get <VariationContent>(variant).CommerceMediaCollection
                                     .Select(x => x.AssetLink).FirstOrDefault();

                result.Add(new Media
                {
                    Image = imageReference.GetUrl()
                });
            }

            return(result);
        }
        public void ProductContentObject()
        {
            ProductContent content = new ProductContent();

            content.CustomerName = "Ben";
            string expected = "Ben";

            Assert.AreEqual(expected, content.CustomerName);

            ProductContent contentTwo = new ProductContent("Blue Bread", "Ben", 16, 20.0m, BakeType.Bread);

            string   expectedProduct   = "Blue Bread";
            string   expectedName      = "Ben";
            int      expectedOrderSize = 16;
            decimal  expectedCost      = 20.0m;
            BakeType expectedType      = BakeType.Bread;

            Assert.AreEqual(expectedProduct, contentTwo.ProductName);
            Assert.AreEqual(expectedName, contentTwo.CustomerName);
            Assert.AreEqual(expectedOrderSize, contentTwo.OrderBatchSize);
            Assert.AreEqual(expectedCost, contentTwo.OrderCost);
            Assert.AreEqual(expectedType, contentTwo.Type);
        }
Exemple #29
0
        private static List <IPriceValue> OriginalPriceValues(this ProductContent productContent)
        {
            var validPrices =
                productContent.Prices()
                .Where(x => x.ValidFrom <= DateTime.Now && (x.ValidUntil == null || x.ValidUntil >= DateTime.Now));

            var originalPrices = new List <IPriceValue>();

            foreach (var marketPrices in validPrices.GroupBy(x => x.MarketId))
            {
                foreach (var currencyPrices in marketPrices.GroupBy(x => x.UnitPrice.Currency))
                {
                    var topPrice = currencyPrices.OrderByDescending(x => x.UnitPrice).FirstOrDefault();
                    if (topPrice == null)
                    {
                        continue;
                    }

                    originalPrices.Add(topPrice);
                }
            }

            return(originalPrices);
        }
        public static Money DiscountPrice(this ProductContent productContent)
        {
            var pricingLoader      = ServiceLocator.Current.GetInstance <ReadOnlyPricingLoader>();
            var promotionService   = ServiceLocator.Current.GetInstance <IPromotionService>();
            var referenceConverter = ServiceLocator.Current.GetInstance <ReferenceConverter>();
            var appContext         = ServiceLocator.Current.GetInstance <AppContextFacade>();
            var relationRepository = ServiceLocator.Current.GetInstance <IRelationRepository>();

            var maxPrice = new Price();
            ContentReference maxPriceVariant = null;
            var variationLinks = productContent.GetVariants(relationRepository);

            foreach (var variationLink in variationLinks)
            {
                var defaultPrice = pricingLoader.GetDefaultPrice(variationLink);
                if (defaultPrice.UnitPrice.Amount > maxPrice.UnitPrice.Amount)
                {
                    maxPrice        = defaultPrice;
                    maxPriceVariant = variationLink;
                }
            }

            return(promotionService.GetDiscountPrice(new CatalogKey(appContext.ApplicationId, referenceConverter.GetCode(maxPriceVariant)), maxPrice.MarketId, maxPrice.UnitPrice.Currency).UnitPrice);
        }
        public List<VariationContent> GetVariants(ProductContent product)
        {
            var linksRepository = ServiceLocator.Current.GetInstance<ILinksRepository>();
            var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
            CultureInfo cultureInfo = product.Language;

            IEnumerable<Relation> relationsBySource = linksRepository.GetRelationsBySource(product.ContentLink).OfType<ProductVariation>();
            List<VariationContent> productVariants = relationsBySource.Select(x => contentLoader.Get<VariationContent>(x.Target, new LanguageSelector(cultureInfo.Name))).ToList();
            return productVariants;
        }
        public virtual ProductViewModel GetProductViewModel(ProductContent product)
        {
            var variations = _contentLoader.GetItems(product.GetVariants(), _preferredCulture).
                                            Cast<VariationContent>()
                                           .ToList();

            var variation = variations.FirstOrDefault();
            return CreateProductViewModel(product, variation);
        }
        private ProductViewModel CreateProductViewModel(ProductContent product, VariationContent variation)
        {
            if (variation == null)
            {
                return null;
            }

            ContentReference productContentReference;
            if (product != null)
            {
                productContentReference = product.ContentLink;
            }
            else
            {
                productContentReference = variation.GetParentProducts(_relationRepository).FirstOrDefault();
                if (ContentReference.IsNullOrEmpty(productContentReference))
                {
                    return null;
                }
            }
            var market = _currentMarket.GetCurrentMarket();
            var currency = _currencyService.GetCurrentCurrency();

            var originalPrice = _pricingService.GetCurrentPrice(variation.Code);
            var discountedPrice = originalPrice.HasValue ? GetDiscountPrice(variation, market, currency, originalPrice.Value) : (Money?)null;

            var image = variation.GetAssets<IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "";
            var brand = product is FashionProduct ? ((FashionProduct)product).Brand : string.Empty;

            return new ProductViewModel
            {
                DisplayName = product != null ? product.DisplayName : variation.DisplayName,
                PlacedPrice = originalPrice.HasValue ? originalPrice.Value : new Money(0, currency),
                DiscountedPrice = discountedPrice,
                ImageUrl = image,
                Url = variation.GetUrl(),
                Brand = brand,
                IsAvailable = originalPrice.HasValue
            };
        }