public void GetGiftCardViewModel_should_set_ParentCategoryId_and_ParentCategoryId_if_UrlContainsCategory(Database db)
        {
            //arrange
            string categoryIdTest   = "categoryIdTest";
            string categoryNameTest = "parentCategoryNameTest";

            Item fakeItem = BuildFakeItem(db, categoryNameTest);

            Category categoryTest = new Category(fakeItem);

            _catalogManagerMock.GetCategory(categoryIdTest).Returns(categoryTest);

            MockContexts(db, $"http://local/{categoryIdTest}/Id");

            var rep = new GiftCardRepository(_accountManagerMock, _contactFactoryMock, _catalogManagerMock);

            rep.CurrentSiteContext.UrlContainsCategory = true;

            // act
            var product = rep.GetGiftCardViewModel(BuildFakeItem(db), new Rendering());

            // assert
            product.ParentCategoryId.Should().Be(categoryIdTest);
            product.ParentCategoryName.Should().Be(categoryNameTest);
        }
Esempio n. 2
0
        public NavigationViewModel GetNavigationProductBar(Item dataSource, Rendering currentRendering)
        {
            Category currentCategory = _catalogManager.GetCategory(dataSource);

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

            var viewModel = GetNavigationViewModel(currentCategory.InnerItem, dataSource, currentRendering);

            return(viewModel);
        }
Esempio n. 3
0
        private ProductViewModel GetProductViewModel(Item productItem, Rendering rendering)
        {
            if (this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] != null)
            {
                return((ProductViewModel)this.CurrentSiteContext.Items[CurrentProductViewModelKeyName]);
            }

            var variants = new List <VariantViewModel>();

            if (productItem != null && productItem.HasChildren)
            {
                foreach (Item item in productItem.Children)
                {
                    var v = new VariantViewModel(item);
                    variants.Add(v);
                }
            }

            var productViewModel = new ProductViewModel(productItem);

            productViewModel.Initialize(rendering, variants);
            productViewModel.ProductName = productViewModel.DisplayName;

            if (this.CurrentSiteContext.UrlContainsCategory)
            {
                productViewModel.ParentCategoryId = CatalogUrlManager.ExtractCategoryNameFromCurrentUrl();
                var category = _catalogManager.GetCategory(productViewModel.ParentCategoryId);

                if (category != null)
                {
                    productViewModel.ParentCategoryName = category.DisplayName;
                }
            }

            _catalogManager.GetProductPrice(this.CurrentVisitorContext, productViewModel);
            productViewModel.CustomerAverageRating = _catalogManager.GetProductRating(productItem);
            this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] = productViewModel;

            return(productViewModel);
        }