Exemple #1
0
        public ActionResult Display(CategoryPathModel category)
        {
            var categoryBase = _catalogClient.GetCategoryById(category.Category);

            if (categoryBase != null && categoryBase.IsActive)
            {
                // set the context variable
                var set = UserHelper.CustomerSession.GetCustomerTagSet();
                set.Add(ContextFieldConstants.CategoryId, new Tag(categoryBase.CategoryId));
                UserHelper.CustomerSession.CategoryId = categoryBase.CategoryId;

                var model = CatalogHelper.CreateCategoryModel(categoryBase);

                if (SiteMaps.Current != null)
                {
                    var node = SiteMaps.Current.CurrentNode;

                    if (Request.UrlReferrer != null &&
                        Request.UrlReferrer.AbsoluteUri.StartsWith(Request.Url.GetLeftPart(UriPartial.Authority)))
                    {
                        if (node != null)
                        {
                            node.RootNode.Attributes["ShowBack"] = true;
                        }

                        if (Request.UrlReferrer.AbsoluteUri.Equals(Request.Url.AbsoluteUri))
                        {
                            UserHelper.CustomerSession.LastShoppingPage = Url.Content("~/");
                        }
                        else
                        {
                            UserHelper.CustomerSession.LastShoppingPage = Request.UrlReferrer.AbsoluteUri;
                        }
                    }

                    if (node != null)
                    {
                        //if (node.ParentNode != null && model.CatalogOutline !=null)
                        //{

                        //    node.Attributes["Outline"] = new BrowsingOutline(model.CatalogOutline);
                        //}

                        node.Title = model.DisplayName;
                    }
                }

                // display category
                return(View(GetDisplayTemplate(TargetTypes.Category, categoryBase), model));
            }

            throw new HttpException(404, "Category not found");
        }
Exemple #2
0
        /// <summary>
        /// Creates the item model.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="propertySet">The property set.</param>
        /// <returns>ItemModel.</returns>
        /// <exception cref="System.ArgumentNullException">item</exception>
        public static ItemModel CreateItemModel(Item item, PropertySet propertySet = null)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            var model = new ItemModel { Item = item };
            model.InjectFrom(item);

            model.ItemAssets = new List<ItemAsset>(item.ItemAssets).ToArray();
            var reviews = item.EditorialReviews;
            model.EditorialReviews = new List<EditorialReview>(reviews.Where(x => string.IsNullOrEmpty(x.Locale) 
                ||  string.Equals(x.Locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase)
                || (string.Equals(x.Locale, StoreHelper.GetDefaultLanguageCode(), StringComparison.InvariantCultureIgnoreCase)
                    && !reviews.Any(val => val.Source == x.Source && string.Equals(val.Locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase))))).ToArray();

            model.AssociationGroups = new List<AssociationGroup>(item.AssociationGroups).ToArray();

            if (propertySet != null && item.ItemPropertyValues != null)
            {
                var values = item.ItemPropertyValues;
                var properties = propertySet.PropertySetProperties.SelectMany(x => values.Where(v => v.Name == x.Property.Name
                    && !x.Property.PropertyAttributes.Any(pa => pa.PropertyAttributeName.Equals("Hidden", StringComparison.OrdinalIgnoreCase)) //skip hidden
                    && (!x.Property.IsLocaleDependant // if not localized ok
                    || string.Equals(v.Locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase) //if current locale match value locale ok
                    || (string.Equals(v.Locale, StoreHelper.GetDefaultLanguageCode(), StringComparison.InvariantCultureIgnoreCase) //if default locale match value locale and values does not contain locale for current property ok
                    && !values.Any(val => val.Name == x.Property.Name && string.Equals(val.Locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase))))),
                    (r, v) => CreatePropertyModel(r.Priority, r.Property, v, item)).ToArray();

                model.Properties = new PropertiesModel(properties);
            }

            //Find item category
            if (item.CategoryItemRelations != null)
            {
                string categoryId = null;
                foreach (var rel in item.CategoryItemRelations)
                {
                    if (rel.CatalogId == UserHelper.CustomerSession.CatalogId)
                    {
                        categoryId = rel.CategoryId;
                        break;
                    }

                    var category = CatalogClient.GetCategoryById(rel.CategoryId);

                    if (category == null)
                        continue;

                    var linkedCategory = category.LinkedCategories.FirstOrDefault(
                        link => link.CatalogId == UserHelper.CustomerSession.CatalogId);

                    if (linkedCategory == null)
                        continue;

                    categoryId = linkedCategory.CategoryId;
                    break;
                }

                if (!string.IsNullOrEmpty(categoryId))
                {
                    var category = CatalogClient.GetCategoryById(categoryId);
                    var cat = category as Category;
                    if (cat != null)
                    {
                        model.CategoryName = cat.Name.Localize();
                    }
                }
            }

            return model;
        }