public void When_HasNoSeoRecords_Expect_Null()
        {
            var product = new catalogModel.Product
            {
            };

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

            Assert.Null(result);
        }
示例#2
0
        private catalogDto.Product AddProduct(catalogDto.Catalog catalog, string productId, params string[] slugs)
        {
            var result = new catalogDto.Product
            {
                Id        = productId,
                CatalogId = catalog.Id,
                Outlines  = new List <catalogDto.Outline>()
            };

            _products.Add(result);
            _catalogSeoRecords.AddRange(slugs.Select(s => CreateSeoInfo("CatalogProduct", productId, s)));

            return(result);
        }
        public void When_HasCategorySeoRecords_Expect_LongPath()
        {
            var product = new catalogModel.Product
            {
                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"
                                    },
                                },
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "CatalogProduct",
                                SeoInfos      = new List <catalogModel.SeoInfo>
                                {
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "product1"
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "product2"
                                    },
                                },
                            },
                        },
                    },
                },
            };

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

            Assert.Equal("category2/product2", result);
        }
示例#4
0
        public virtual Product ToProduct(catalogDto.Product productDto, Language currentLanguage, Currency currentCurrency, Store store)
        {
            var result = new Product(currentCurrency, currentLanguage)
            {
                Id                     = productDto.Id,
                CatalogId              = productDto.CatalogId,
                CategoryId             = productDto.CategoryId,
                DownloadExpiration     = productDto.DownloadExpiration,
                DownloadType           = productDto.DownloadType,
                EnableReview           = productDto.EnableReview ?? false,
                Gtin                   = productDto.Gtin,
                HasUserAgreement       = productDto.HasUserAgreement ?? false,
                IsActive               = productDto.IsActive ?? false,
                IsBuyable              = productDto.IsBuyable ?? false,
                ManufacturerPartNumber = productDto.ManufacturerPartNumber,
                MaxNumberOfDownload    = productDto.MaxNumberOfDownload ?? 0,
                MaxQuantity            = productDto.MaxQuantity ?? 0,
                MeasureUnit            = productDto.MeasureUnit,
                MinQuantity            = productDto.MinQuantity ?? 0,
                Name                   = productDto.Name,
                PackageType            = productDto.PackageType,
                ProductType            = productDto.ProductType,
                ShippingType           = productDto.ShippingType,
                TaxType                = productDto.TaxType,
                TrackInventory         = productDto.TrackInventory ?? false,
                VendorId               = productDto.Vendor,
                WeightUnit             = productDto.WeightUnit,
                Weight                 = (decimal?)productDto.Weight,
                Height                 = (decimal?)productDto.Height,
                Width                  = (decimal?)productDto.Width,
                Length                 = (decimal?)productDto.Length,
                Sku                    = productDto.Code,
                Outline                = productDto.Outlines.GetOutlinePath(store.Catalog),
                Url                    = "~/" + productDto.Outlines.GetSeoPath(store, currentLanguage, "product/" + productDto.Id),
            };

            if (productDto.Properties != null)
            {
                result.Properties = productDto.Properties
                                    .Where(x => string.Equals(x.Type, "Product", StringComparison.InvariantCultureIgnoreCase))
                                    .Select(p => ToProperty(p, currentLanguage))
                                    .ToList();

                result.VariationProperties = productDto.Properties
                                             .Where(x => string.Equals(x.Type, "Variation", StringComparison.InvariantCultureIgnoreCase))
                                             .Select(p => ToProperty(p, currentLanguage))
                                             .ToList();
            }

            if (productDto.Images != null)
            {
                result.Images       = productDto.Images.Select(ToImage).ToArray();
                result.PrimaryImage = result.Images.FirstOrDefault();
            }

            if (productDto.Assets != null)
            {
                result.Assets = productDto.Assets.Select(ToAsset).ToList();
            }

            if (productDto.Variations != null)
            {
                result.Variations = productDto.Variations.Select(v => ToProduct(v, currentLanguage, currentCurrency, store)).ToList();
            }

            if (!productDto.Associations.IsNullOrEmpty())
            {
                result.Associations.AddRange(productDto.Associations.Select(ToAssociation).Where(x => x != null));
            }

            if (!productDto.SeoInfos.IsNullOrEmpty())
            {
                var seoInfoDto = productDto.SeoInfos.Select(x => x.JsonConvert <coreDto.SeoInfo>())
                                 .GetBestMatchingSeoInfos(store, currentLanguage)
                                 .FirstOrDefault();

                if (seoInfoDto != null)
                {
                    result.SeoInfo = seoInfoDto.ToSeoInfo();
                }
            }

            if (result.SeoInfo == null)
            {
                result.SeoInfo = new SeoInfo
                {
                    Title    = productDto.Id,
                    Language = currentLanguage,
                    Slug     = productDto.Code
                };
            }

            if (productDto.Reviews != null)
            {
                result.Descriptions = productDto.Reviews.Where(r => !string.IsNullOrEmpty(r.Content)).Select(r => new EditorialReview
                {
                    Language   = new Language(r.LanguageCode),
                    ReviewType = r.ReviewType,
                    Value      = Markdown.ToHtml(r.Content, _markdownPipeline)
                }).Where(x => x.Language.Equals(currentLanguage)).ToList();
                result.Description = result.Descriptions.FindWithLanguage(currentLanguage, x => x.Value, null);
            }

            return(result);
        }
示例#5
0
 public static Product ToProduct(this catalogDto.Product productDto, Language currentLanguage, Currency currentCurrency, Store store)
 {
     return(CatalogConverterInstance.ToProduct(productDto, currentLanguage, currentCurrency, store));
 }
示例#6
0
        private catalogDto.Outline CreateOutline(catalogDto.Catalog catalog, catalogDto.Category[] categories, catalogDto.Product product = null)
        {
            var result = new catalogDto.Outline
            {
                Items = new List <catalogDto.OutlineItem> {
                    CreateOutlineItem("Catalog", catalog.Id)
                }
            };

            result.Items.AddRange(categories.Select(c => CreateOutlineItem("Category", c.Id, c.CatalogId != catalog.Id)));

            if (product != null)
            {
                result.Items.Add(CreateOutlineItem("CatalogProduct", product.Id));
            }

            return(result);
        }
        public void When_MissingAnyParentSeoRecord_Expect_Null()
        {
            var product = new catalogModel.Product
            {
                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"
                                    },
                                },
                            },
                            new catalogModel.OutlineItem
                            {
                                SeoObjectType = "CatalogProduct",
                                SeoInfos      = new List <catalogModel.SeoInfo>
                                {
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "en-US", SemanticUrl = "product1"
                                    },
                                    new catalogModel.SeoInfo {
                                        StoreId = "Store1", LanguageCode = "ru-RU", SemanticUrl = "product2"
                                    },
                                },
                            },
                        },
                    },
                },
            };

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

            Assert.Null(result);
        }
        public static Product ToProduct(this catalogDto.Product productDto, Language currentLanguage, Currency currentCurrency, Store store)
        {
            var result = new Product(currentCurrency, currentLanguage)
            {
                Id                     = productDto.Id,
                TitularItemId          = productDto.TitularItemId,
                CatalogId              = productDto.CatalogId,
                CategoryId             = productDto.CategoryId,
                DownloadExpiration     = productDto.DownloadExpiration,
                DownloadType           = productDto.DownloadType,
                EnableReview           = productDto.EnableReview ?? false,
                Gtin                   = productDto.Gtin,
                HasUserAgreement       = productDto.HasUserAgreement ?? false,
                IsActive               = productDto.IsActive ?? false,
                IsBuyable              = productDto.IsBuyable ?? false,
                ManufacturerPartNumber = productDto.ManufacturerPartNumber,
                MaxNumberOfDownload    = productDto.MaxNumberOfDownload ?? 0,
                MaxQuantity            = productDto.MaxQuantity ?? 0,
                MeasureUnit            = productDto.MeasureUnit,
                MinQuantity            = productDto.MinQuantity ?? 0,
                Name                   = productDto.Name,
                PackageType            = productDto.PackageType,
                ProductType            = productDto.ProductType,
                ShippingType           = productDto.ShippingType,
                TaxType                = productDto.TaxType,
                TrackInventory         = productDto.TrackInventory ?? false,
                VendorId               = productDto.Vendor,
                WeightUnit             = productDto.WeightUnit,
                Weight                 = (decimal?)productDto.Weight,
                Height                 = (decimal?)productDto.Height,
                Width                  = (decimal?)productDto.Width,
                Length                 = (decimal?)productDto.Length,
                Sku                    = productDto.Code,
                Outline                = productDto.Outlines.GetOutlinePath(store.Catalog),
                SeoPath                = productDto.Outlines.GetSeoPath(store, currentLanguage, null),
            };

            result.Url = "/" + (result.SeoPath ?? "product/" + result.Id);

            if (productDto.Properties != null)
            {
                result.Properties = new MutablePagedList <CatalogProperty>(productDto.Properties
                                                                           .Where(x => string.Equals(x.Type, "Product", StringComparison.InvariantCultureIgnoreCase))
                                                                           .Select(p => ToProperty(p, currentLanguage))
                                                                           .ToList());

                result.VariationProperties = new MutablePagedList <CatalogProperty>(productDto.Properties
                                                                                    .Where(x => string.Equals(x.Type, "Variation", StringComparison.InvariantCultureIgnoreCase))
                                                                                    .Select(p => ToProperty(p, currentLanguage))
                                                                                    .ToList());
            }

            if (productDto.Images != null)
            {
                result.Images       = productDto.Images.Select(ToImage).ToArray();
                result.PrimaryImage = result.Images.FirstOrDefault();
            }

            if (productDto.Assets != null)
            {
                result.Assets = productDto.Assets.Select(ToAsset).ToList();
            }

            if (productDto.Variations != null)
            {
                result.Variations = productDto.Variations.Select(v => ToProduct(v, currentLanguage, currentCurrency, store)).ToList();
            }

            if (!productDto.SeoInfos.IsNullOrEmpty())
            {
                var seoInfoDto = productDto.SeoInfos.Select(x => x.JsonConvert <coreDto.SeoInfo>())
                                 .GetBestMatchingSeoInfos(store, currentLanguage)
                                 .FirstOrDefault();

                if (seoInfoDto != null)
                {
                    result.SeoInfo = seoInfoDto.ToSeoInfo();
                }
            }

            if (result.SeoInfo == null)
            {
                result.SeoInfo = new SeoInfo
                {
                    Title    = productDto.Id,
                    Language = currentLanguage,
                    Slug     = productDto.Code
                };
            }

            if (productDto.Reviews != null)
            {
                // Reviews for currentLanguage (or Invariant language as fall-back) for each ReviewType
                var descriptions = productDto.Reviews
                                   .Where(r => !string.IsNullOrEmpty(r.Content))
                                   .Select(r => new EditorialReview
                {
                    Language   = new Language(r.LanguageCode),
                    ReviewType = r.ReviewType,
                    Value      = Markdown.ToHtml(r.Content, _markdownPipeline)
                });
                //Select only best matched description for current language in the each description type
                var tmpDescriptionList = new List <EditorialReview>();
                foreach (var descriptionGroup in descriptions.GroupBy(x => x.ReviewType))
                {
                    var description = descriptionGroup.FindWithLanguage(currentLanguage);
                    if (description != null)
                    {
                        tmpDescriptionList.Add(description);
                    }
                }
                result.Descriptions = new MutablePagedList <EditorialReview>(tmpDescriptionList);
                result.Description  = (result.Descriptions.FirstOrDefault(x => x.ReviewType.EqualsInvariant("FullReview")) ?? result.Descriptions.FirstOrDefault())?.Value;
            }


            return(result);
        }
示例#9
0
        public virtual Product ToProduct(catalogDto.Product productDto, Language currentLanguage, Currency currentCurrency, Store store)
        {
            var retVal = ServiceLocator.Current.GetInstance <CatalogFactory>().CreateProduct(currentCurrency, currentLanguage);

            retVal.InjectFrom <NullableAndEnumValueInjecter>(productDto);
            retVal.Weight   = (decimal?)productDto.Weight;
            retVal.Height   = (decimal?)productDto.Height;
            retVal.Width    = (decimal?)productDto.Width;
            retVal.Length   = (decimal?)productDto.Length;
            retVal.Sku      = productDto.Code;
            retVal.VendorId = productDto.Vendor;
            retVal.Outline  = productDto.Outlines.GetOutlinePath(store.Catalog);
            retVal.Url      = "~/" + productDto.Outlines.GetSeoPath(store, currentLanguage, "product/" + productDto.Id);

            if (productDto.Properties != null)
            {
                retVal.Properties = productDto.Properties
                                    .Where(x => string.Equals(x.Type, "Product", StringComparison.InvariantCultureIgnoreCase))
                                    .Select(p => p.ToProperty(currentLanguage))
                                    .ToList();

                retVal.VariationProperties = productDto.Properties
                                             .Where(x => string.Equals(x.Type, "Variation", StringComparison.InvariantCultureIgnoreCase))
                                             .Select(p => p.ToProperty(currentLanguage))
                                             .ToList();
            }

            if (productDto.Images != null)
            {
                retVal.Images       = productDto.Images.Select(ToImage).ToArray();
                retVal.PrimaryImage = retVal.Images.FirstOrDefault(x => string.Equals(x.Url, productDto.ImgSrc, StringComparison.InvariantCultureIgnoreCase));
            }

            if (productDto.Assets != null)
            {
                retVal.Assets = productDto.Assets.Select(ToAsset).ToList();
            }

            if (productDto.Variations != null)
            {
                retVal.Variations = productDto.Variations.Select(v => ToProduct(v, currentLanguage, currentCurrency, store)).ToList();
            }

            if (!productDto.Associations.IsNullOrEmpty())
            {
                retVal.Associations.AddRange(productDto.Associations.Select(ToAssociation).Where(x => x != null));
            }

            if (!productDto.SeoInfos.IsNullOrEmpty())
            {
                var seoInfoDto = productDto.SeoInfos.Select(x => x.JsonConvert <coreDto.SeoInfo>())
                                 .GetBestMatchingSeoInfos(store, currentLanguage)
                                 .FirstOrDefault();

                if (seoInfoDto != null)
                {
                    retVal.SeoInfo = seoInfoDto.ToSeoInfo();
                }
            }

            if (retVal.SeoInfo == null)
            {
                retVal.SeoInfo = new SeoInfo
                {
                    Title    = productDto.Id,
                    Language = currentLanguage,
                    Slug     = productDto.Code
                };
            }

            if (productDto.Reviews != null)
            {
                retVal.Descriptions = productDto.Reviews.Select(r => new EditorialReview
                {
                    Language   = new Language(r.LanguageCode),
                    ReviewType = r.ReviewType,
                    Value      = Markdown.ToHtml(r.Content, _markdownPipeline)
                }).Where(x => x.Language.Equals(currentLanguage)).ToList();
                retVal.Description = retVal.Descriptions.FindWithLanguage(currentLanguage, x => x.Value, null);
            }

            return(retVal);
        }