public static CatalogContentBase GetParent(this CatalogContentBase content)
        {
            if (content != null)
            {
                return(ContentLoader.Service.Get <CatalogContentBase>(content.ParentLink));
            }

            return(null);
        }
Exemple #2
0
        private NodeContent GetTopCategory(CatalogContentBase nodeContent)
        {
            var category = _contentLoader.Get <CatalogContentBase>(nodeContent.ParentLink);

            if (category.ContentType == CatalogContentType.Catalog)
            {
                return((NodeContent)nodeContent);
            }
            return(GetTopCategory(category));
        }
Exemple #3
0
        protected override Entry GenerateEntry(CatalogContentBase catalogContent)
        {
            var variationContent = catalogContent as FashionVariant;

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

            var product      = _contentLoader.Get <CatalogContentBase>(variationContent.GetParentProducts().FirstOrDefault()) as FashionProduct;
            var variantCode  = variationContent.Code;
            var defaultPrice = _pricingService.GetDefaultPrice(variantCode);

            var entry = new Entry
            {
                Id                    = variantCode,
                Title                 = variationContent.DisplayName,
                Description           = product?.Description.ToHtmlString(),
                Link                  = variationContent.GetUrl(),
                Condition             = "new",
                Availability          = "in stock",
                Brand                 = product?.Brand,
                MPN                   = string.Empty,
                GTIN                  = "725272730706",
                GoogleProductCategory = string.Empty,
                Shipping              = new List <Shipping>
                {
                    new Shipping
                    {
                        Price   = "1 USD",
                        Country = "US",
                        Service = "Standard"
                    }
                }
            };

            var image = variationContent.GetDefaultAsset <IContentImage>();

            if (!string.IsNullOrEmpty(image))
            {
                entry.ImageLink = Uri.TryCreate(new Uri(_siteUrl), image, out var imageUri) ? imageUri.ToString() : image;
            }

            if (defaultPrice != null)
            {
                var discountPrice = _pricingService.GetDiscountPrice(variantCode);

                entry.Price     = defaultPrice.UnitPrice.FormatPrice();
                entry.SalePrice = discountPrice != null?discountPrice.UnitPrice.FormatPrice() : string.Empty;

                entry.SalePriceEffectiveDate = $"{DateTime.UtcNow:yyyy-MM-ddThh:mm:ss}/{DateTime.UtcNow.AddDays(7):yyyy-MM-ddThh:mm:ss}";
            }

            return(entry);
        }
        private static bool IsSitemapPropertyEnabled(CatalogContentBase page)
        {
            var property = page.Property[PropertySEOSitemaps.PropertyName] as PropertySEOSitemaps;

            if (null != property && !property.Enabled)
            {
                return(false);
            }

            return(true);
        }
 public FacetPartialRoute(Func<ContentReference> routeStartingPoint, CatalogContentBase commerceRoot,
     bool supportSeoUri, IContentLoader contentLoader, IRoutingSegmentLoader routingSegmentLoader,
     IContentVersionRepository contentVersionRepository, IUrlSegmentRouter urlSegmentRouter,
     IContentLanguageSettingsHandler contentLanguageSettingsHandler,
     FacetUrlService facetUrlCreator)
     : base(
         routeStartingPoint, commerceRoot, supportSeoUri, contentLoader, routingSegmentLoader,
         contentVersionRepository, urlSegmentRouter, contentLanguageSettingsHandler)
 {
     _facetUrlCreator = facetUrlCreator;
 }
        private static bool IsSitemapPropertyEnabled(CatalogContentBase page)
        {
            var property = page.Property[PropertySEOSitemaps.PropertyName] as PropertySEOSitemaps;

            if (null != property && !property.Enabled)
            {
                return false;
            }

            return true;
        }
Exemple #7
0
        public static string DefaultCurrency(this CatalogContentBase content)
        {
            var catalogContent = content as CatalogContent;

            if (catalogContent != null)
            {
                return(catalogContent.DefaultCurrency);
            }

            return(null);
        }
        public ViewResult Index(CatalogContentBase currentContent, PageData currentPage)
        {
            var model       = CreateFashionCatalogViewModel(currentContent);
            var virtualPath = String.Format("~/Views/{0}/Index.cshtml", currentContent.GetOriginalType().Name);

            if (!System.IO.File.Exists(Request.MapPath(virtualPath)))
            {
                virtualPath = String.Format("~/Views/{0}/Index.cshtml", Enum.GetName(typeof(CatalogContentType), currentContent.ContentType));
            }
            return(View(virtualPath, model));
        }
        private ContentReference GetCategory(CatalogContentBase content)
        {
            if (content is NodeContent)
            {
                return content.ContentLink;
            }

            var category = _contentLoader.GetAncestors(content.ContentLink).Last(x => x is NodeContent);

            return category.ContentLink;
        }
Exemple #10
0
        public static IEnumerable <ContentReference> VariationLinks(this CatalogContentBase content)
        {
            var productContent = content as ProductContent;

            if (productContent == null)
            {
                return(Enumerable.Empty <ContentReference>());
            }

            return(productContent.GetVariants());
        }
 public FacetPartialRoute(Func <ContentReference> routeStartingPoint, CatalogContentBase commerceRoot,
                          bool supportSeoUri, IContentLoader contentLoader, IRoutingSegmentLoader routingSegmentLoader,
                          IContentVersionRepository contentVersionRepository, IUrlSegmentRouter urlSegmentRouter,
                          IContentLanguageSettingsHandler contentLanguageSettingsHandler,
                          FacetUrlService facetUrlCreator)
     : base(
         routeStartingPoint, commerceRoot, supportSeoUri, contentLoader, routingSegmentLoader,
         contentVersionRepository, urlSegmentRouter, contentLanguageSettingsHandler)
 {
     _facetUrlCreator = facetUrlCreator;
 }
        private static NodeContent GetTopCategory(CatalogContentBase nodeContent)
        {
            var contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>();
            var category      = contentLoader.Get <CatalogContentBase>(nodeContent.ParentLink);

            if (category.ContentType == CatalogContentType.Catalog)
            {
                return((NodeContent)nodeContent);
            }
            return(GetTopCategory(category));
        }
        /// <summary>
        /// Gets the name of the parent category for the product
        /// </summary>
        /// <param name="productContent">The product itself.</param>
        /// <param name="language">The language to use when getting the name.</param>
        /// <returns>The name of the immediate parent category.</returns>
        public static string GetCategoryName(this CatalogContentBase productContent, string language)
        {
            CatalogContentBase parentCategory =
                ContentLoader.Service.Get <CatalogContentBase>(productContent.ParentLink, new LanguageSelector(language));

            if (parentCategory != null)
            {
                return(parentCategory.Name);
            }
            return(string.Empty);
        }
        private ContentReference GetCategory(CatalogContentBase content)
        {
            if (content is NodeContent)
            {
                return(content.ContentLink);
            }

            var category = _contentLoader.GetAncestors(content.ContentLink).Last(x => x is NodeContent);

            return(category.ContentLink);
        }
Exemple #15
0
        public static string WeightBase(this CatalogContentBase content)
        {
            var catalogContent = content as CatalogContent;

            if (catalogContent != null)
            {
                return(catalogContent.WeightBase);
            }

            return(null);
        }
Exemple #16
0
        public static IEnumerable <ContentReference> ProductLinks(this CatalogContentBase content)
        {
            var variationContent = content as VariationContent;

            if (variationContent == null)
            {
                return(Enumerable.Empty <ContentReference>());
            }

            return(variationContent.GetParentProducts());
        }
        /// <summary>
        /// Gets all parent category names, including the whole category trees a product
        /// resides in.
        /// </summary>
        /// <remarks>
        /// This method will return parent categories recursively, and not just direct parents
        /// </remarks>
        /// <param name="productContent">The actual product.</param>
        /// <param name="language">The language to use when loading category names</param>
        /// <returns>A list of category names that this product resides on, directly or indirectly</returns>
        public static List <string> GetParentCategoryNames(this CatalogContentBase productContent, string language)
        {
            var           parentCategories = productContent.GetProductCategories(language);
            List <string> names            = new List <string>();

            foreach (var category in parentCategories)
            {
                names.Add(category.Name);
            }
            return(names);
        }
Exemple #18
0
        public static IEnumerable <Price> Prices(this CatalogContentBase content)
        {
            var pricing = content as IPricing;

            if (pricing == null)
            {
                return(Enumerable.Empty <Price>());
            }

            return(pricing.GetPrices() ?? Enumerable.Empty <Price>());
        }
Exemple #19
0
        public static IEnumerable <ContentReference> NodeLinks(this CatalogContentBase content)
        {
            var productContent = content as EPiServer.Commerce.Catalog.ContentTypes.ICategorizable;

            if (productContent == null)
            {
                return(Enumerable.Empty <ContentReference>());
            }

            return(productContent.GetNodeRelations().Select(x => x.Target));
        }
Exemple #20
0
        public static string ThumbnailPath(this CatalogContentBase content)
        {
            var assetContainer = content as IAssetContainer;

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

            return(ServiceLocator.Current.GetInstance <ThumbnailUrlResolver>()
                   .GetThumbnailUrl(assetContainer, "Thumbnail"));
        }
 public FacetPartialRoute(Func <ContentReference> routeStartingPoint, CatalogContentBase commerceRoot,
                          bool enableOutgoingSeoUri)
     : this(
         routeStartingPoint,
         commerceRoot,
         enableOutgoingSeoUri,
         ServiceLocator.Current.GetInstance <IContentLoader>(),
         ServiceLocator.Current.GetInstance <IRoutingSegmentLoader>(),
         ServiceLocator.Current.GetInstance <IContentVersionRepository>(),
         ServiceLocator.Current.GetInstance <IUrlSegmentRouter>(),
         ServiceLocator.Current.GetInstance <IContentLanguageSettingsHandler>(),
         ServiceLocator.Current.GetInstance <FacetUrlService>())
 {
 }
        /// <summary>
        /// Determine if the catalog item should be indexed.
        /// </summary>
        /// <param name="content">The catalog item.</param>
        /// <returns>True/False depending on if the catalog item should be indexed or not.</returns>
        private bool ShouldIndexCatalogData(CatalogContentBase content)
        {
            // Check if the content is published
            var shouldIndex = content.StopPublish > DateTime.Now && content.StartPublish < DateTime.Now && content.Status == VersionStatus.Published;

            // If the product should not be indexed, try to delete it if it exists in the index
            if (!shouldIndex)
            {
                IEnumerable <DeleteResult> result;
                ContentIndexer.Instance.TryDelete(content, out result);
            }

            return(shouldIndex);
        }
 public FacetPartialRoute(Func<ContentReference> routeStartingPoint, CatalogContentBase commerceRoot,
     bool enableOutgoingSeoUri)
     : this(
     routeStartingPoint, 
     commerceRoot, 
     enableOutgoingSeoUri,
     ServiceLocator.Current.GetInstance<IContentLoader>(),
     ServiceLocator.Current.GetInstance<IRoutingSegmentLoader>(),
     ServiceLocator.Current.GetInstance<IContentVersionRepository>(), 
     ServiceLocator.Current.GetInstance<IUrlSegmentRouter>(),
     ServiceLocator.Current.GetInstance<IContentLanguageSettingsHandler>(),
     ServiceLocator.Current.GetInstance<FacetUrlService>())
 {
 }
        //Injected<ReferenceConverter> _refConv;
        public override void SetDefaultValues(ContentType contentType)
        {
            base.SetDefaultValues(contentType);

            CatalogContentBase myParent = _loader.Service.Get <CatalogContentBase>(this.ParentLink);

            // Changed so the ServiceAPI works
            if (myParent.GetOriginalType() == typeof(NodeContent))
            {
                FashionNode fashionNode = (FashionNode)myParent;

                // sooo much easier now
                this.TaxCategoryId  = int.Parse(fashionNode.TaxCategories);
                this.theTaxCategory = CatalogTaxManager.GetTaxCategoryNameById(Int16.Parse(fashionNode.TaxCategories));
            }
        }
Exemple #25
0
        public static IEnumerable <Inventory> Inventories(this CatalogContentBase content)
        {
            var stockPlacement = content as VariationContent;

            if (stockPlacement == null)
            {
                return(Enumerable.Empty <Inventory>());
            }

            var warehouseInventoryService = ServiceLocator.Current.GetInstance <IWarehouseInventoryService>();

            return(warehouseInventoryService.ListAll()
                   .Where(x => x.CatalogKey.CatalogEntryCode == stockPlacement.Code)
                   .Select(x => new Inventory(x))
                   .ToArray());
        }
Exemple #26
0
        protected IEnumerable <CommerceMedia> MediaList(CatalogContentBase content)
        {
            var node = content as NodeContent;

            if (node != null)
            {
                return(node.CommerceMediaCollection);
            }
            var entry = content as EntryContentBase;

            if (entry != null)
            {
                return(node.CommerceMediaCollection);
            }
            return(Enumerable.Empty <CommerceMedia>());
        }
        private ContentReference GetCategoryOrPageLink(IContent content)
        {
            CatalogContentBase catalogContent = content as CatalogContentBase;

            if (catalogContent != null)
            {
                return(GetCategory(catalogContent));
            }

            if (content is PageData)
            {
                return(content.ContentLink);
            }

            return(null);
        }
Exemple #28
0
        public static IEnumerable <string> Categories(this CatalogContentBase content)
        {
            var productContent = content as EntryContentBase;

            if (productContent == null)
            {
                return(Enumerable.Empty <string>());
            }

            var contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>();
            var contentLinks  = productContent.GetNodeRelations().Select(x => x.Target);

            var contentItems = contentLoader.GetItems(contentLinks, content.Language);

            return(contentItems.Select(x => x.Name));
        }
        /// <summary>
        /// Gets the categories for the product and language. It will return all nodes that the product
        /// is part of (could be more than one) and also all parent categories indirectly.
        /// </summary>
        /// <remarks>
        /// Example:
        /// Root
        ///   Catalog
        ///     Category 1
        ///       Product A
        ///     Category 2
        ///       Category 2.1
        ///         Product A
        /// Returns: ["Category 1", "Category 2.1", "Category 2"]
        /// </remarks>
        /// <param name="productContent">The product to get categories for</param>
        /// <param name="language">The language to use</param>
        /// <returns>A list of Categories in the type of CatalogContentBase</returns>
        public static List <CatalogContentBase> GetProductCategories(this CatalogContentBase productContent, string language)
        {
            var allRelations = LinksRepository.Service.GetRelationsBySource(productContent.ContentLink);
            var categories   = allRelations.OfType <NodeRelation>().ToList();
            List <CatalogContentBase> parentCategories = new List <CatalogContentBase>();

            try
            {
                if (categories.Any())
                {
                    // Add all categories (nodes) that this product is part of
                    foreach (var nodeRelation in categories)
                    {
                        if (nodeRelation.Target != ReferenceConverter.Service.GetRootLink())
                        {
                            CatalogContentBase parentCategory =
                                ContentLoader.Service.Get <CatalogContentBase>(nodeRelation.Target,
                                                                               new LanguageSelector(language));
                            if (parentCategory != null && parentCategory.ContentType != CatalogContentType.Catalog)
                            {
                                parentCategories.Add(parentCategory);
                            }
                        }
                    }
                }

                var content = productContent;

                // Now walk the category tree until we hit the catalog node itself
                while (content.ParentLink != null && content.ParentLink != ReferenceConverter.Service.GetRootLink())
                {
                    CatalogContentBase parentCategory =
                        ContentLoader.Service.Get <CatalogContentBase>(content.ParentLink, new LanguageSelector(language));
                    if (parentCategory.ContentType != CatalogContentType.Catalog)
                    {
                        parentCategories.Add(parentCategory);
                    }
                    content = parentCategory;
                }
            }
            catch (Exception ex)
            {
                // TODO: Fix this empty catch, it is too greedy
                Log.Debug(string.Format("Failed to get categories from product {0}, Code: {1}.", productContent.Name, productContent.ContentLink), ex);
            }
            return(parentCategories.DistinctBy(a => a.ContentLink.ID).ToList());
        }
Exemple #30
0
        public static int MetaClassId(this CatalogContentBase content)
        {
            var nodeContent = content as NodeContent;

            if (nodeContent != null)
            {
                return(nodeContent.MetaClassId);
            }

            var entryContent = content as EntryContentBase;

            if (entryContent != null)
            {
                return(entryContent.MetaClassId);
            }

            return(default(int));
        }
Exemple #31
0
        public static double DefaultPrice(this CatalogContentBase content)
        {
            var pricing = content as IPricing;

            if (pricing == null)
            {
                return(default(double));
            }

            var price = pricing.GetDefaultPrice();

            if (price == null)
            {
                return(default(double));
            }

            return(Convert.ToDouble(price.UnitPrice.Amount));
        }
Exemple #32
0
        private EntryContentBase GetParent(CatalogContentBase content)
        {
            ILinksRepository linksRepository = ServiceLocator.Current.GetInstance <ILinksRepository>();
            IContentLoader   contentLoader   = ServiceLocator.Current.GetInstance <IContentLoader>();

            IEnumerable <Relation> parentRelations = linksRepository.GetRelationsByTarget(content.ContentLink);

            if (parentRelations.Any())
            {
                Relation firstRelation = parentRelations.FirstOrDefault();
                if (firstRelation != null)
                {
                    var parentProductContent = contentLoader.Get <EntryContentBase>(firstRelation.Source);
                    return(parentProductContent);
                }
            }
            return(null);
        }
Exemple #33
0
        public static string Code(this CatalogContentBase content)
        {
            var entryContentBase = content as EntryContentBase;

            if (entryContentBase != null)
            {
                return(entryContentBase.Code);
            }

            var nodeContent = content as NodeContent;

            if (nodeContent != null)
            {
                return(nodeContent.Code);
            }

            return(null);
        }
Exemple #34
0
        /// <summary>
        /// Creates a list of parent category names for a product
        /// </summary>
        /// <param name="productContent">Product to get parent category names from</param>
        /// <param name="language">Current language name</param>
        /// <returns>List of category names</returns>
        public static List <string> GetParentCategoryCodes(this CatalogContentBase productContent, string language)
        {
            var           parentCategories = productContent.GetProductCategories(language);
            List <string> names            = new List <string>();

            foreach (var category in parentCategories)
            {
                NodeContent node = category as NodeContent;
                if (node != null)
                {
                    string code = node.Code;
                    if (names.Contains(code) == false)
                    {
                        names.Add(code);
                    }
                }
            }
            return(names);
        }
 public void RegisterRoute(ContentReference pageLink, CatalogContentBase catalogContentBase, bool enableOutgoingSeoUri)
 {
     RouteTable.Routes.RegisterPartialRouter(new FacetPartialRoute(() => pageLink, catalogContentBase, enableOutgoingSeoUri));
 }
        private EntryContentBase GetParent(CatalogContentBase content)
        {
            ILinksRepository linksRepository = ServiceLocator.Current.GetInstance<ILinksRepository>();
            IContentLoader contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();

            IEnumerable<Relation> parentRelations = linksRepository.GetRelationsByTarget(content.ContentLink);
            if (parentRelations.Any())
            {
                Relation firstRelation = parentRelations.FirstOrDefault();
                if (firstRelation != null)
                {
                    var parentProductContent = contentLoader.Get<EntryContentBase>(firstRelation.Source);
                    return parentProductContent;
                }
            }
            return null;
        }
 private NodeContent GetTopCategory(CatalogContentBase nodeContent)
 {
     var category = _contentLoader.Get<CatalogContentBase>(nodeContent.ParentLink);
     if (category.ContentType == CatalogContentType.Catalog)
     { 
         return (NodeContent)nodeContent;
     }
     return GetTopCategory(category);
 }