private Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes GetContextItemType(string UrlItemPath)
        {
            //since this pipeline is being called before ite resolver, Sitecore.Context.Item has not been resolved, so we need to get the item by using item path.
            Item item = Sitecore.Context.Database.GetItem(UrlItemPath);

            if (item == null)
            {
                return(Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Unknown);
            }
            Template template = TemplateManager.GetTemplate(item);

            Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes itemTypes = Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Unknown;
            if (template.InheritsFrom(Sitecore.Commerce.XA.Foundation.Common.Constants.DataTemplates.CategoryPage.ID))
            {
                itemTypes = Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Category;
            }
            else if (template.InheritsFrom(Sitecore.Commerce.XA.Foundation.Common.Constants.DataTemplates.ProductPage.ID))
            {
                itemTypes = Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Product;
            }
            return(itemTypes);
        }
        public override void Process(HttpRequestArgs args)
        {
            try
            {
                if (this.SiteContext.CurrentCatalogItem != null)
                {
                    return;
                }
                Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes contextItemType = this.GetContextItemType(args.Url.ItemPath);

                switch (contextItemType)
                {
                case Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Category:
                case Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Product:
                    //get the catalog item id from sku passed in query string
                    string catalogItemIdFromUrl = this.GetCatalogItemIdFromUrl();
                    if (string.IsNullOrEmpty(catalogItemIdFromUrl))
                    {
                        break;
                    }
                    bool   isProduct = contextItemType == Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Product;
                    string catalog   = this.StorefrontContext.CurrentStorefront.Catalog;
                    Item   obj       = this.ResolveCatalogItem(catalogItemIdFromUrl, catalog, isProduct);
                    if (obj == null)
                    {
                        WebUtil.Redirect("~/");
                    }
                    this.SiteContext.CurrentCatalogItem = obj;
                    break;
                }
            }
            catch (Exception ex)
            {
                Diagnostics.Logger.Error("Error occured found for CatalogProductItemResolver method" + ex);
            }
        }
Exemplo n.º 3
0
 private bool IsCommerceCategoryItem(Item item)
 {
     Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes itemType = this.ItemTypeProvider.GetItemType(item);
     return(itemType == Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Category);
 }