Example #1
0
 public static IEnumerable <VariationContent> VariationContents(this ProductContent productContent,
                                                                IContentLoader contentLoader, IRelationRepository relationRepository)
 {
     return
         (contentLoader.GetItems(productContent.GetVariants(relationRepository), productContent.Language)
          .OfType <VariationContent>());
 }
Example #2
0
        public IEnumerable <EntryContentBase> GetVariants(ProductContent content)
        {
            var variants     = content.GetVariants();
            var variantItems = _contentLoader.GetItems(variants, LanguageSelector.AutoDetect());

            return(FilterForVisitor.Filter(variantItems).OfType <EntryContentBase>());
        }
        public virtual ProductViewModel GetProductViewModel(ProductContent product)
        {
            var variations = _contentLoader.GetItems(product.GetVariants(), _preferredCulture).
                             Cast <VariationContent>()
                             .ToList();

            var variation = variations.FirstOrDefault();

            return(CreateProductViewModel(product, variation));
        }
        protected virtual TProduct BaseMap(ProductContent source)
        {
            var imageUrl            = source.CommerceMediaCollection.FirstOrDefault()?.AssetLink.GetUrl();
            var thumbnail           = UrlHelper.GetAsThumbnailUrl(imageUrl);
            var variantQuantity     = GetTotalInventoryByEntry(source.Code);
            var configurableOptions = GetProductConfigurableOptions(source).ToList();

            var productVariations = source.GetVariants();

            var productPrice = PriceService.GetDefaultPrice(source.ContentLink);

            var product = new TProduct
            {
                Id        = source.ContentLink.ID,
                Name      = source.DisplayName,
                UrlKey    = source.RouteSegment,
                UrlPath   = source.SeoUri,
                IsInStock = new VsfStock {
                    IsInStock = true, Quantity = (int)variantQuantity
                },
                Sku             = source.Code,
                TaxClassId      = null,
                MediaGallery    = GetGallery(source),
                Image           = imageUrl ?? "",
                Thumbnail       = thumbnail,
                FinalPrice      = productPrice,
                Price           = productPrice,
                TypeId          = "configurable",
                SpecialPrice    = null,
                NewsFromDate    = null,
                NewsToDate      = null,
                SpecialFromDate = null,
                SpecialToDate   = null,
                CategoryIds     = source.GetCategories().Select(x => x.ID.ToString()),
                Category        = source.GetCategories().Select(x =>
                                                                new CategoryListItem {
                    Id = x.ID, Name = ContentLoaderWrapper.Get <NodeContent>(x).DisplayName
                }),
                Status              = 1,
                Visibility          = source.Status.Equals(VersionStatus.Published) ? 4 : 0,
                Weight              = 1,
                HasOptions          = configurableOptions.Count > 1 ? "1" : "0",
                RequiredOptions     = "0",
                ConfigurableOptions = configurableOptions,
                UpdatedAt           = source.Changed,
                CreatedAt           = source.Created
            };

            product.ConfigurableChildren = productVariations
                                           .Select(v => MapVariant(product, ContentLoaderWrapper.Get <VariationContent>(v))).ToList();
            return(product);
        }
        public virtual MyProductVM GetProductViewModel(ProductContent product)
        {
            var variations = _contentLoader.GetItems(product.GetVariants(), _preferredCulture).
                             Cast <VariationContent>()
                             .ToList();

            var variation = variations.FirstOrDefault();
            var productVM = new MyProductVM();

            productVM.Name = variation.Name;
            productVM.Link = variation.GetUrl();
            return(productVM);
        }
 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 = (x as IAssetContainer).DefaultImageUrl()
     }));
 }
 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,
         ContentReference = ReferenceConverter.Value.GetContentLink(x.Code).ToString(),
         LanguageId = productContent.Language.Name,
         Name = x.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);
        }
        protected virtual IEnumerable <ConfigurableOption> GetProductConfigurableOptions(ProductContent product)
        {
            var options  = new List <ConfigurableOption>();
            var variants = product.GetVariants();

            var index = 0;

            foreach (var variant in variants)
            {
                var variantProperties = ContentLoaderWrapper.GetVariantVsfProperties(variant);

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

                    var optionValue   = MapConfigurableOptionValue(variantProperty, order: index);
                    var currentOption = options.FirstOrDefault(x => x.Label.Equals(variantProperty.Name));
                    if (currentOption == null)
                    {
                        var position = options.Count;
                        var values   = new List <ConfigurableOptionValue>
                        {
                            optionValue
                        };
                        options.Add(MapConfigurableOption(variantProperty, position, product.ContentLink.ID, values));
                    }
                    else
                    {
                        var isValue = currentOption.Values.FirstOrDefault(x => x.Label == variantProperty.Value.ToString()) != null;
                        if (isValue)
                        {
                            continue;
                        }
                        optionValue.Order = currentOption.Values.Count + 1;
                        currentOption.Values.Add(optionValue);
                    }

                    index = index + 1;
                }
            }

            return(options);
        }
        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);
        }
        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);
        }
Example #13
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);
        }
        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());
                        }
                    }
                }
            }
        }
        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 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);
        }
Example #17
0
        public virtual T GetFirstVariant <T>(ProductContent currentContent) where T : VariationContent
        {
            var firstVariantLink = currentContent.GetVariants(_relationRepository).FirstOrDefault();

            return(ContentReference.IsNullOrEmpty(firstVariantLink) ? null : _contentLoader.Get <T>(firstVariantLink));
        }
Example #18
0
 public virtual IEnumerable <T> GetVariants <T>(ProductContent currentContent) where T : VariationContent
 {
     return(GetVariants <T>(currentContent.GetVariants(_relationRepository), _languageResolver.GetPreferredCulture()));
 }
Example #19
0
 public IEnumerable <VariationContent> GetVariants(ProductContent currentContent) => GetAvailableVariants(currentContent.GetVariants(_relationRepository));
 public static IEnumerable <VariationContent> VariationContents(this ProductContent productContent)
 {
     return(ContentLoader.Value
            .GetItems(productContent.GetVariants(RelationRepository.Value), productContent.Language)
            .OfType <VariationContent>());
 }
Example #21
0
        public virtual ProductViewModel GetProductViewModel(ProductContent product)
        {
            var variations = _contentLoader.GetItems(product.GetVariants(), _preferredCulture).
                                            Cast<VariationContent>()
                                           .ToList();

            var variation = variations.FirstOrDefault();
            return CreateProductViewModel(product, variation);
        }