Beispiel #1
0
        protected virtual void AddMyAccountMenu(CommerceHomePage homePage, CommerceHeaderViewModel viewModel)
        {
            if (HttpContext.Current != null && !HttpContext.Current.Request.IsAuthenticated)
            {
                viewModel.UserLinks = new LinkItemCollection();
                return;
            }

            var menuItems = new LinkItemCollection();
            var filter    = new FilterContentForVisitor();
            var contact   = _customerService.GetCurrentContact();

            if (contact != null && contact.FoundationOrganization != null)
            {
                var orgLink = new LinkItem
                {
                    Href  = _urlResolver.GetUrl(homePage.OrganizationMainPage),
                    Text  = _localizationService.GetString("My Organization", "My Organization"),
                    Title = _localizationService.GetString("My Organization", "My Organization")
                };
                //orgLink.Attributes.Add("css", "fa-sign-out");
                menuItems.Add(orgLink);
            }

            foreach (var linkItem in homePage.MyAccountCommerceMenu ?? new LinkItemCollection())
            {
                if (!UrlResolver.Current.TryToPermanent(linkItem.Href, out var linkUrl))
                {
                    continue;
                }

                if (linkUrl.IsNullOrEmpty())
                {
                    continue;
                }

                var urlBuilder = new UrlBuilder(linkUrl);
                var content    = _urlResolver.Route(urlBuilder);
                if (content == null || filter.ShouldFilter(content))
                {
                    continue;
                }

                linkItem.Title = linkItem.Text;
                menuItems.Add(linkItem);
            }

            var signoutText = _localizationService.GetString("/Header/Account/SignOut", "Sign Out");
            var link        = new LinkItem
            {
                Href  = "/publicapi/signout",
                Text  = signoutText,
                Title = signoutText
            };

            link.Attributes.Add("css", "fa-sign-out");
            menuItems.Add(link);

            viewModel.UserLinks.AddRange(menuItems);
        }
Beispiel #2
0
        protected virtual void AddAnonymousComponents(CommerceHomePage homePage, CommerceHeaderViewModel viewModel)
        {
            if (HttpContext.Current != null && !HttpContext.Current.Request.IsAuthenticated)
            {
                viewModel.LoginViewModel = new LoginViewModel
                {
                    ResetPasswordPage = homePage.ResetPasswordPage
                };

                viewModel.RegisterAccountViewModel = new RegisterAccountViewModel
                {
                    Address = new AddressModel
                    {
                        CountryRegion = new CountryRegionViewModel
                        {
                            SelectClass  = "select-menu-small",
                            TextboxClass = "textbox-small"
                        }
                    }
                };

                _addressBookService.LoadAddress(viewModel.RegisterAccountViewModel.Address);
                viewModel.RegisterAccountViewModel.Address.Name = _localizationService.GetString("/Shared/Address/DefaultAddressName", "Default Address");
            }
        }
Beispiel #3
0
        protected virtual void AddMarketViewModel(IContent currentContent, CommerceHeaderViewModel viewModel)
        {
            var marketsViewModel = CacheManager.Get(Constant.CacheKeys.MarketViewModel) as MarketViewModel;

            if (marketsViewModel != null)
            {
                viewModel.Markets = marketsViewModel;
            }
            else
            {
                var currentMarket = _currentMarket.GetCurrentMarket();
                var markets       = _marketService.GetAllMarkets().Where(x => x.IsEnabled).OrderBy(x => x.MarketName)
                                    .Select(x => new MarketItem
                {
                    Selected = false,
                    Text     = x.MarketName,
                    Value    = x.MarketId.Value,
                    FlagUrl  = GetFlagUrl(x.MarketId)
                });
                marketsViewModel = new MarketViewModel
                {
                    Markets       = markets,
                    MarketId      = currentMarket != null ? currentMarket.MarketId.Value : string.Empty,
                    CurrentMarket = currentMarket != null ? new MarketItem
                    {
                        Selected = false,
                        Text     = currentMarket.MarketName,
                        Value    = currentMarket.MarketId.Value,
                        FlagUrl  = GetFlagUrl(currentMarket.MarketId)
                    } : null,
                    ContentLink = currentContent?.ContentLink ?? ContentReference.EmptyReference
                };
                viewModel.Markets = marketsViewModel;

                CacheManager.Insert(Constant.CacheKeys.MarketViewModel, marketsViewModel, new CacheEvictionPolicy(TimeSpan.FromDays(7), CacheTimeoutType.Sliding));
            }
        }
Beispiel #4
0
        protected virtual void AddCommerceComponents(Customer.FoundationContact contact, CommerceHeaderViewModel viewModel)
        {
            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;
            }
        }