Exemplo n.º 1
0
        public static Category ToWebModel(this catalogModel.Category category, Language currentLanguage, Store store, catalogModel.Product[] products = null)
        {
            var retVal = new Category();

            retVal.InjectFrom <NullableAndEnumValueInjecter>(category);

            retVal.SeoInfo = category.SeoInfos.GetBestMatchedSeoInfo(store, currentLanguage).ToWebModel();
            retVal.Url     = "~/" + category.Outlines.GetSeoPath(store, currentLanguage, "category/" + category.Id);

            if (category.Images != null)
            {
                retVal.Images       = category.Images.Select(i => i.ToWebModel()).ToArray();
                retVal.PrimaryImage = retVal.Images.FirstOrDefault();
            }

            if (category.Properties != null)
            {
                retVal.Properties = category.Properties
                                    .Where(x => string.Equals(x.Type, "Category", StringComparison.OrdinalIgnoreCase))
                                    .Select(p => p.ToWebModel(currentLanguage))
                                    .ToList();
            }

            return(retVal);
        }
Exemplo n.º 2
0
        public void When_HasNoSeoRecords_Expect_Null()
        {
            var category = new catalogModel.Category();

            var result = category.Outlines.GetSeoPath(_store, new Language("en-US"), null);

            Assert.Null(result);
        }
Exemplo n.º 3
0
        public void When_MissingAnyParentSeoRecord_Expect_Null()
        {
            var category = new catalogModel.Category
            {
                Outlines = new List <catalogModel.Outline>
                {
                    new catalogModel.Outline
                    {
                        Items = new List <catalogModel.OutlineItem>
                        {
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Catalog",
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Category",
                                SeoInfos      = new List <catalogModel.SeoInfo>(),
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Category",
                                SeoInfos      = new List <catalogModel.SeoInfo>
                                {
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "parent1"
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "parent2"
                                    },
                                }
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Category",
                                SeoInfos      = new List <catalogModel.SeoInfo>
                                {
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "category1"
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "category2"
                                    },
                                },
                            },
                        },
                    },
                },
            };

            var result = category.Outlines.GetSeoPath(_store, new Language("ru-RU"), null);

            Assert.Null(result);
        }
Exemplo n.º 4
0
        public void When_HasSeoRecords_Expect_ShortPath()
        {
            var category = new catalogModel.Category
            {
                Outlines = new List <catalogModel.Outline>
                {
                    new catalogModel.Outline
                    {
                        Items = new List <catalogModel.OutlineItem>
                        {
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Catalog",
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Category",
                                SeoInfos      = new List <catalogModel.SeoInfo>
                                {
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "category1"
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "category2"
                                    },
                                },
                            }
                        },
                    },
                },
            };

            var result = category.Outlines.GetSeoPath(_store, new Language("ru-RU"), null);

            Assert.Equal("category2", result);
        }
Exemplo n.º 5
0
        public void When_HasVirtualParent_Expect_SkipLinkedPhysicalParent()
        {
            var category = new catalogModel.Category
            {
                Outlines = new List <catalogModel.Outline>
                {
                    new catalogModel.Outline
                    {
                        Items = new List <catalogModel.OutlineItem>
                        {
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Catalog",
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Category",
                                SeoInfos      = new List <catalogModel.SeoInfo>
                                {
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "virtual-parent1"
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "virtual-parent2"
                                    },
                                }
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType    = "Category",
                                HasVirtualParent = true,
                                SeoInfos         = new List <catalogModel.SeoInfo>
                                {
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "physical-parent1"
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "physical-parent2"
                                    },
                                }
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Category",
                                SeoInfos      = new List <catalogModel.SeoInfo>
                                {
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "category1"
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "category2"
                                    },
                                },
                            },
                        },
                    },
                },
            };

            var result = category.Outlines.GetSeoPath(_store, new Language("ru-RU"), null);

            Assert.Equal("virtual-parent2/category2", result);
        }
Exemplo n.º 6
0
        public void When_HasInactiveSeoRecords_Expect_OnlyActiveRecords()
        {
            var category = new catalogModel.Category
            {
                Outlines = new List <catalogModel.Outline>
                {
                    new catalogModel.Outline
                    {
                        Items = new List <catalogModel.OutlineItem>
                        {
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Catalog",
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Category",
                                SeoInfos      = new List <catalogModel.SeoInfo>
                                {
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "inactive-parent1", IsActive = false
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "active-parent1", IsActive = true
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "inactive-parent2", IsActive = false
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "active-parent2", IsActive = true
                                    },
                                }
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "Category",
                                SeoInfos      = new List <catalogModel.SeoInfo>
                                {
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "inactive-category1", IsActive = false
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "active-category1", IsActive = true
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "inactive-category2", IsActive = false
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "active-category2", IsActive = true
                                    },
                                },
                            },
                        },
                    },
                },
            };

            var result = category.Outlines.GetSeoPath(_store, new Language("ru-RU"), null);

            Assert.Equal("active-parent2/active-category2", result);
        }