예제 #1
0
        protected virtual void AddCommerceComponents(Customer.FoundationContact contact, CommerceHeaderViewModel viewModel)
        {
            if (_databaseMode.DatabaseMode == DatabaseMode.ReadOnly)
            {
                viewModel.MiniCart         = new MiniCartViewModel();
                viewModel.WishListMiniCart = new MiniWishlistViewModel();
                viewModel.SharedMiniCart   = new MiniCartViewModel();
                return;
            }

            viewModel.MiniCart = _cartViewModelFactory.CreateMiniCartViewModel(
                _cartService.LoadCart(_cartService.DefaultCartName, true)?.Cart);

            viewModel.WishListMiniCart = _cartViewModelFactory.CreateMiniWishListViewModel(
                _cartService.LoadCart(_cartService.DefaultWishListName, true)?.Cart);

            var organizationId = contact?.FoundationOrganization?.OrganizationId.ToString();

            if (!organizationId.IsNullOrEmpty())
            {
                viewModel.SharedMiniCart = _cartViewModelFactory.CreateMiniCartViewModel(
                    _cartService.LoadCart(_cartService.DefaultSharedCartName, organizationId, true)?.Cart, true);

                viewModel.ShowSharedCart = true;
            }
        }
예제 #2
0
        protected virtual T CreateViewModel <T>(IContent currentContent, CommerceHomePage homePage, Customer.FoundationContact contact, bool isBookmarked)
            where T : CommerceHeaderViewModel, new()
        {
            var menuItems  = new List <MenuItemViewModel>();
            var menuCached = CacheManager.Get(homePage.ContentLink.ID + Constant.CacheKeys.MenuItems) as List <MenuItemViewModel>;

            if (menuCached != null)
            {
                menuItems = menuCached;
            }
            else
            {
                var menuItemBlocks = homePage.MainMenu?.FilteredItems.GetContentItems <MenuItemBlock>() ?? new List <MenuItemBlock>();
                menuItems = menuItemBlocks?
                            .Select(_ => new MenuItemViewModel
                {
                    Name       = _.Name,
                    ButtonText = _.ButtonText,
                    TeaserText = _.TeaserText,
                    Uri        = _.Link == null ? string.Empty : _urlResolver.GetUrl(new UrlBuilder(_.Link.ToString()), new UrlResolverArguments()
                    {
                        ContextMode = ContextMode.Default
                    }),
                    ImageUrl   = !ContentReference.IsNullOrEmpty(_.MenuImage) ? _urlResolver.GetUrl(_.MenuImage) : "",
                    ButtonLink = _.ButtonLink?.Host + _.ButtonLink?.PathAndQuery,
                    ChildLinks = _.ChildItems?.ToList() ?? new List <GroupLinkCollection>()
                }).ToList() ?? new List <MenuItemViewModel>();

                var keyDependency = new List <string>();
                keyDependency.Add(_contentCacheKeyCreator.CreateCommonCacheKey(homePage.ContentLink)); // If The HomePage updates menu (remove MenuItems)

                foreach (var m in menuItemBlocks)
                {
                    keyDependency.Add(_contentCacheKeyCreator.CreateCommonCacheKey((m as IContent).ContentLink));
                }

                var eviction = new CacheEvictionPolicy(TimeSpan.FromDays(1), CacheTimeoutType.Sliding, keyDependency);
                CacheManager.Insert(homePage.ContentLink.ID + Constant.CacheKeys.MenuItems, menuItems, eviction);
            }

            return(new T
            {
                HomePage = homePage,
                CurrentContentLink = currentContent?.ContentLink,
                CurrentContentGuid = currentContent?.ContentGuid ?? Guid.Empty,
                UserLinks = new LinkItemCollection(),
                Name = contact?.FirstName ?? "",
                IsBookmarked = isBookmarked,
                MenuItems = menuItems,
                LoginViewModel = new LoginViewModel
                {
                    ResetPasswordPage = homePage.ResetPasswordPage
                },
                RegisterAccountViewModel = new RegisterAccountViewModel
                {
                    Address = new AddressModel()
                },
                MobileNavigation = homePage.MobileNavigationPages,
            });
        }
예제 #3
0
        protected virtual T CreateViewModel <T>(IContent currentContent, CommerceHomePage homePage, Customer.FoundationContact contact, bool isBookmarked)
            where T : CommerceHeaderViewModel, new()
        {
            var menuItems    = new List <MenuItemViewModel>();
            var homeLanguage = homePage.Language.DisplayName;

            menuItems = homePage.MainMenu?.FilteredItems.Select(x =>
            {
                var itemCached = CacheManager.Get(x.ContentLink.ID + homeLanguage + ":" + Constant.CacheKeys.MenuItems) as MenuItemViewModel;
                if (itemCached != null && !PageEditing.PageIsInEditMode)
                {
                    return(itemCached);
                }
                else
                {
                    var content = _contentLoader.Get <IContent>(x.ContentLink);
                    MenuItemBlock _;
                    MenuItemViewModel menuItem;
                    if (content is MenuItemBlock)
                    {
                        _        = content as MenuItemBlock;
                        menuItem = new MenuItemViewModel
                        {
                            Name       = _.Name,
                            ButtonText = _.ButtonText,
                            TeaserText = _.TeaserText,
                            Uri        = _.Link == null ? string.Empty : _urlResolver.GetUrl(new UrlBuilder(_.Link.ToString()), new UrlResolverArguments()
                            {
                                ContextMode = ContextMode.Default
                            }),
                            ImageUrl   = !ContentReference.IsNullOrEmpty(_.MenuImage) ? _urlResolver.GetUrl(_.MenuImage) : "",
                            ButtonLink = _.ButtonLink?.Host + _.ButtonLink?.PathAndQuery,
                            ChildLinks = _.ChildItems?.ToList() ?? new List <GroupLinkCollection>()
                        };
                    }
                    else
                    {
                        menuItem = new MenuItemViewModel
                        {
                            Name       = content.Name,
                            Uri        = _urlResolver.GetUrl(content.ContentLink),
                            ChildLinks = new List <GroupLinkCollection>()
                        };
                    }

                    if (!PageEditing.PageIsInEditMode)
                    {
                        var keyDependency = new List <string>();
                        keyDependency.Add(_contentCacheKeyCreator.CreateCommonCacheKey(homePage.ContentLink)); // If The HomePage updates menu (remove MenuItems)
                        keyDependency.Add(_contentCacheKeyCreator.CreateCommonCacheKey(x.ContentLink));

                        var eviction = new CacheEvictionPolicy(TimeSpan.FromDays(1), CacheTimeoutType.Sliding, keyDependency);
                        CacheManager.Insert(x.ContentLink.ID + homeLanguage + ":" + Constant.CacheKeys.MenuItems, menuItem, eviction);
                    }

                    return(menuItem);
                }
            }).ToList();

            return(new T
            {
                HomePage = homePage,
                CurrentContentLink = currentContent?.ContentLink,
                CurrentContentGuid = currentContent?.ContentGuid ?? Guid.Empty,
                UserLinks = new LinkItemCollection(),
                Name = contact?.FirstName ?? "",
                IsBookmarked = isBookmarked,
                IsReadonlyMode = _databaseMode.DatabaseMode == DatabaseMode.ReadOnly,
                MenuItems = menuItems ?? new List <MenuItemViewModel>(),
                LoginViewModel = new LoginViewModel
                {
                    ResetPasswordPage = homePage.ResetPasswordPage
                },
                RegisterAccountViewModel = new RegisterAccountViewModel
                {
                    Address = new AddressModel()
                },
            });
        }