private SubNavigationLinkModel CreateProductFilterNavigation(ProductPageData productCatalogData)
        {
            var category = _categoryService.Get(productCatalogData.CategorySystemId.Value);

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

            _selectedStructureId     = category.GetParents().Select(x => x.SystemId).ToList();
            _currentCategorySystemId = category.SystemId;
            _selectedStructureId.Add(category.SystemId);

            var market = _marketService.Get(_channel.Channel.MarketSystemId.Value);
            var firstLevelCategories = _categoryService.GetChildCategories(Guid.Empty, market.AssortmentSystemId)
                                       .Where(x => x.IsPublished(_channel.SystemId) &&
                                              _authorizationService.HasOperation <Category>(Operations.Entity.Read, x.SystemId) &&
                                              _renderingValidators.Validate(x));

            var currentCategoryParentSystemId = category.ParentCategorySystemId;

            return(new SubNavigationLinkModel
            {
                IsSelected = true,
                Name = _website.Texts.GetValue("ProductCategories") ?? "Product Categories",
                Links = firstLevelCategories
                        .Where(x => currentCategoryParentSystemId == Guid.Empty || _selectedStructureId.Contains(x.SystemId))
                        .Select(x =>
                {
                    var showAll = currentCategoryParentSystemId == Guid.Empty && _selectedStructureId.Contains(x.SystemId);
                    return new SubNavigationLinkModel
                    {
                        IsSelected = _selectedStructureId.Contains(x.SystemId),
                        Name = x.Localizations.CurrentCulture.Name,
                        Url = x.GetUrl(_channel.SystemId),
                        Links = _selectedStructureId.Contains(x.SystemId) ?
                                GetChildLinks(x, showAll, showAll ? 0 : 1).ToList() :
                                (x.GetChildren().Any() ? new List <SubNavigationLinkModel>() : null)
                    };
                }).ToList()
            });
        }
Exemplo n.º 2
0
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var siteSettingViewModel = request.Headers.GetSiteSettingViewModel();

            if (siteSettingViewModel != null)
            {
                var url            = request.RequestUri;
                var channel        = _channelService.Get(siteSettingViewModel.ChannelSystemId);
                var domainNameLink = channel?.DomainNameLinks.FirstOrDefault();

                _routeRequestLookupInfoAccessor.RouteRequestLookupInfo = new RouteRequestLookupInfo
                {
                    AbsolutePath       = HttpUtility.UrlDecode(url.AbsolutePath),
                    IsSecureConnection = _secureConnectionResolver.IsUsingSecureConnection(),
                    QueryString        = url.ParseQueryString(),
                    RawUrl             = url.PathAndQuery,
                    Uri                = url,
                    Channel            = channel,
                    DomainNameLink     = domainNameLink,
                    DomainName         = _domainNameService.Get(domainNameLink?.DomainNameSystemId ?? Guid.Empty),
                    IsInAdministration = siteSettingViewModel.PreviewPageData != null,
                    PreviewPageData    = siteSettingViewModel.PreviewPageData
                };

                if (siteSettingViewModel.CurrentPageSystemId != Guid.Empty)
                {
                    var page = _pageService.Get(siteSettingViewModel.CurrentPageSystemId);
                    if (page != null)
                    {
                        var fieldTemplate = _fieldTemplateService.Get <PageFieldTemplate>(page.FieldTemplateSystemId);
                        _routeRequestInfoAccessor.RouteRequestInfo = new RouteRequestInfo
                        {
                            PageSystemId     = siteSettingViewModel.CurrentPageSystemId,
                            TemplateFileName = fieldTemplate.TemplatePath,
                            DataPath         = _urlService.GetUrl(page, new PageUrlArgs(channel.SystemId))
                        };
                    }
                }

                if (siteSettingViewModel.ProductCategorySystemId != null)
                {
                    if (!(_routeRequestInfoAccessor.RouteRequestInfo.Data is ProductPageData productData))
                    {
                        _routeRequestInfoAccessor.RouteRequestInfo.Data = productData = new ProductPageData();
                    }
                    productData.CategorySystemId = siteSettingViewModel.ProductCategorySystemId.Value;
                }

                _requestModelAccessor.RequestModel = new RequestModelImpl(_cartAccessor)
                {
                    _channelModel     = new Lazy <ChannelModel>(() => channel.MapTo <ChannelModel>()),
                    _searchQuery      = new Lazy <SearchQuery>(() => request.MapTo <SearchQuery>()),
                    _currentPageModel = new Lazy <PageModel>(() => siteSettingViewModel.CurrentPageSystemId.MapTo <PageModel>()),
                };

                CultureInfo.CurrentUICulture = _languageService.Get(channel.WebsiteLanguageSystemId.GetValueOrDefault())?.CultureInfo;
                CultureInfo.CurrentCulture   = _languageService.Get(channel.ProductLanguageSystemId.GetValueOrDefault())?.CultureInfo ?? CultureInfo.CurrentUICulture;
                request.RegisterForDispose(new AccessorCleanup(_requestModelAccessor, _routeRequestLookupInfoAccessor, _routeRequestInfoAccessor));
            }

            return(base.SendAsync(request, cancellationToken));
        }
Exemplo n.º 3
0
        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var routeRequestLookupInfo = _routeRequestLookupInfoAccessor.RouteRequestLookupInfo;

            if (routeRequestLookupInfo != null)
            {
                _requestModelAccessor.RequestModel = new RequestModelImpl(filterContext.HttpContext.GetCartContext(), _countryService)
                {
                    _channelModel         = new Lazy <ChannelModel>(() => routeRequestLookupInfo.Channel.MapTo <ChannelModel>()),
                    _searchQuery          = new Lazy <SearchQuery>(() => filterContext.HttpContext.MapTo <SearchQuery>()),
                    _currentPageModel     = new Lazy <PageModel>(() => _routeRequestInfoAccessor.RouteRequestInfo.PageSystemId.MapTo <PageModel>()),
                    _currentCategoryModel = new Lazy <CategoryModel>(() => (_routeRequestInfoAccessor.RouteRequestInfo?.Data as ProductPageData)?.CategorySystemId.MapTo <CategoryModel>()),
                    _currentProductModel  = new Lazy <ProductModel>(()
                                                                    => (_routeRequestInfoAccessor.RouteRequestInfo?.Data as ProductPageData)?.VariantSystemId.MapTo <Variant>()?.MapTo <ProductModel>()
                                                                    ?? (_routeRequestInfoAccessor.RouteRequestInfo?.Data as ProductPageData)?.BaseProductSystemId.MapTo <BaseProduct>()?.MapTo <ProductModel>()),
                };
            }
            else
            {
                var siteSettingViewModel = filterContext.HttpContext.Request.Headers.GetSiteSettingViewModel();
                if (siteSettingViewModel != null)
                {
                    var url            = filterContext.HttpContext.Request.ToUri();
                    var channel        = _channelService.Get(siteSettingViewModel.ChannelSystemId);
                    var domainNameLink = channel?.DomainNameLinks.FirstOrDefault();

                    _routeRequestLookupInfoAccessor.RouteRequestLookupInfo = new RouteRequestLookupInfo
                    {
                        AbsolutePath       = WebUtility.UrlDecode(url.AbsolutePath),
                        IsSecureConnection = _secureConnectionResolver.IsUsingSecureConnection(),
                        QueryString        = new QueryCollection(filterContext.HttpContext.Request),
                        RawUrl             = url.PathAndQuery,
                        Uri                = url,
                        Channel            = channel,
                        DomainNameLink     = domainNameLink,
                        DomainName         = _domainNameService.Get(domainNameLink?.DomainNameSystemId ?? Guid.Empty),
                        IsInAdministration = siteSettingViewModel.PreviewPageData != null,
                        PreviewPageData    = siteSettingViewModel.PreviewPageData
                    };

                    if (siteSettingViewModel.CurrentPageSystemId != Guid.Empty)
                    {
                        var page = _pageService.Get(siteSettingViewModel.CurrentPageSystemId);
                        if (page != null)
                        {
                            var fieldTemplate = _fieldTemplateService.Get <PageFieldTemplate>(page.FieldTemplateSystemId);
                            _routeRequestInfoAccessor.RouteRequestInfo = new RouteRequestInfo
                            {
                                PageSystemId     = siteSettingViewModel.CurrentPageSystemId,
                                TemplateFileName = fieldTemplate.TemplatePath,
                                DataPath         = _urlService.GetUrl(page, new PageUrlArgs(channel.SystemId))
                            };
                        }
                    }

                    if (siteSettingViewModel.ProductCategorySystemId != null)
                    {
                        if (!(_routeRequestInfoAccessor.RouteRequestInfo.Data is ProductPageData productData))
                        {
                            _routeRequestInfoAccessor.RouteRequestInfo.Data = productData = new ProductPageData();
                        }
                        productData.CategorySystemId = siteSettingViewModel.ProductCategorySystemId.Value;
                    }

                    _requestModelAccessor.RequestModel = new RequestModelImpl(filterContext.HttpContext.GetCartContext(), _countryService)
                    {
                        _channelModel         = new Lazy <ChannelModel>(() => channel.MapTo <ChannelModel>()),
                        _searchQuery          = new Lazy <SearchQuery>(() => filterContext.HttpContext.MapTo <SearchQuery>()),
                        _currentPageModel     = new Lazy <PageModel>(() => siteSettingViewModel.CurrentPageSystemId.MapTo <PageModel>()),
                        _currentCategoryModel = new Lazy <CategoryModel>(() => (_routeRequestInfoAccessor.RouteRequestInfo?.Data as ProductPageData)?.CategorySystemId.MapTo <CategoryModel>()),
                        _currentProductModel  = new Lazy <ProductModel>(()
                                                                        => (_routeRequestInfoAccessor.RouteRequestInfo?.Data as ProductPageData)?.VariantSystemId.MapTo <Variant>()?.MapTo <ProductModel>()
                                                                        ?? (_routeRequestInfoAccessor.RouteRequestInfo?.Data as ProductPageData)?.BaseProductSystemId.MapTo <BaseProduct>()?.MapTo <ProductModel>()),
                    };

                    CultureInfo.CurrentUICulture = _languageService.Get(channel.WebsiteLanguageSystemId.GetValueOrDefault())?.CultureInfo;
                    CultureInfo.CurrentCulture   = _languageService.Get(channel.ProductLanguageSystemId.GetValueOrDefault())?.CultureInfo ?? CultureInfo.CurrentUICulture;
                }
            }
        }