Example #1
0
        public Accessory(int accessoryId, bool lightVer = true)
        {
            ICategoryService categoryService = EngineContext.Current.Resolve <ICategoryService>();

            this.id = accessoryId;
            Category category = categoryService.GetCategoryById(accessoryId);

            this.Name             = category.Name;
            this.parentCategoryId = category.ParentCategoryId;
            ICatalogModelFactory        catalogModelFactory         = EngineContext.Current.Resolve <ICatalogModelFactory>();
            CatalogPagingFilteringModel catalogPagingFilteringModel = new CatalogPagingFilteringModel();

            catalogPagingFilteringModel.PageSize = 1;
            CategoryModel categoryModel = catalogModelFactory.PrepareCategoryModel(category, catalogPagingFilteringModel);

            this.SeName = categoryModel.SeName;
            IPictureService pictureService = EngineContext.Current.Resolve <IPictureService>();

            this.mainPicturePath = pictureService.GetPictureUrl(category.PictureId);

            if (lightVer == false)
            {
                this.PagingFilteringContext = catalogPagingFilteringModel;
                this.Name                      = categoryModel.Name;
                this.Description               = categoryModel.Description;
                this.MetaKeywords              = categoryModel.MetaKeywords;
                this.MetaDescription           = categoryModel.MetaDescription;
                this.MetaTitle                 = categoryModel.MetaTitle;
                this.PictureModel              = categoryModel.PictureModel;
                this.PagingFilteringContext    = categoryModel.PagingFilteringContext;
                this.DisplayCategoryBreadcrumb = categoryModel.DisplayCategoryBreadcrumb;
                this.CategoryBreadcrumb        = categoryModel.CategoryBreadcrumb;
                this.SubCategories             = categoryModel.SubCategories;
                this.FeaturedProducts          = categoryModel.FeaturedProducts;
                this.Products                  = categoryModel.Products;
            }

            ICacheManager cacheManager = EngineContext.Current.Resolve <ICacheManager>();

            DataView accessoryDataView = cacheManager.Get("categoryAccessory" + accessoryId, 60, () => {
                Dictionary <string, Object> accessoryDic = new Dictionary <string, Object>();
                accessoryDic.Add("@CategoryId", accessoryId);

                string accessoryDataQuery       = "EXEC usp_SelectGBSCrossSellAccessory @categoryId";
                DataView innerAccessoryDataView = manager.GetParameterizedDataView(accessoryDataQuery, accessoryDic);
                return(innerAccessoryDataView);
            });

            if (accessoryDataView.Count > 0)
            {
                this.parentCategoryId = category.ParentCategoryId;
                this.h1 = !string.IsNullOrEmpty(accessoryDataView[0]["H1"].ToString()) ? accessoryDataView[0]["H1"].ToString() : this.Name;
                this.mainPicturePath = !string.IsNullOrEmpty(this.mainPicturePath) ? this.mainPicturePath : _mainPicturePath;
                int featuredId;
                this.featuredProductId = Int32.TryParse(accessoryDataView[0]["FeaturedProductId"].ToString(), out featuredId) ? featuredId : _featuredProductId;
                this.isFeatured        = accessoryDataView[0]["IsFeatured"] != null && accessoryDataView[0]["IsFeatured"] != DBNull.Value ? (Convert.ToBoolean(accessoryDataView[0]["IsFeatured"]) == true ? true : false) : _isFeatured;
                int order;
                this.displayOrder = Int32.TryParse(accessoryDataView[0]["DisplayOrder"].ToString(), out order) ? order : _displayOrder;
            }
        }
Example #2
0
 public CategoryModel()
 {
     SubCategories = new List<CategoryModel>();
     Products = new List<ProductOverviewModel>();
     PagingFilteringContext = new CatalogPagingFilteringModel();
     PictureModel = new PictureModel();
 }
Example #3
0
        public virtual IActionResult Vendor(int vendorId, CatalogPagingFilteringModel command)
        {
            var vendor = _vendorService.GetVendorById(vendorId);

            if (vendor == null || vendor.Deleted || !vendor.Active)
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            _genericAttributeService.SaveAttribute(_workContext.CurrentCustomer,
                                                   NopCustomerDefaults.LastContinueShoppingPageAttribute,
                                                   _webHelper.GetThisPageUrl(false),
                                                   _storeContext.CurrentStore.Id);

            //display "edit" (manage) link
            if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageVendors))
            {
                DisplayEditLink(Url.Action("Edit", "Vendor", new { id = vendor.Id, area = AreaNames.Admin }));
            }

            //model
            var model = _catalogModelFactory.PrepareVendorModel(vendor, command);

            return(View(model));
        }
Example #4
0
 public CategoryModel()
 {
     SubCategories          = new List <CategoryModel>();
     Products               = new List <ProductOverviewModel>();
     PagingFilteringContext = new CatalogPagingFilteringModel();
     PictureModel           = new PictureModel();
 }
Example #5
0
        public virtual async Task <IActionResult> Vendor(string vendorId, CatalogPagingFilteringModel command)
        {
            var vendor = await _vendorService.GetVendorById(vendorId);

            if (vendor == null || vendor.Deleted || !vendor.Active)
            {
                return(InvokeHttp404());
            }

            //Vendor is active?
            if (!vendor.Active)
            {
                return(InvokeHttp404());
            }

            var customer = _workContext.CurrentCustomer;

            //'Continue shopping' URL
            await SaveLastContinueShoppingPage(customer);

            //display "edit" (manage) link
            if (await _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel, customer) && await _permissionService.Authorize(StandardPermissionProvider.ManageManufacturers, customer))
            {
                DisplayEditLink(Url.Action("Edit", "Vendor", new { id = vendor.Id, area = "Admin" }));
            }

            var model = await _catalogViewModelService.PrepareVendor(vendor, command);

            //review
            model.VendorReviewOverview = _vendorViewModelService.PrepareVendorReviewOverviewModel(vendor);

            return(View(model));
        }
        public virtual ActionResult Category(int categoryId, CatalogPagingFilteringModel command)
        {
            var category = _categoryService.GetCategoryById(categoryId);

            if (category == null || category.Deleted)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //published?
                !category.Published ||
                //ACL (access control list)
                !_aclService.Authorize(category) ||
                //Store mapping
                !_storeMappingService.Authorize(category);

            //Check whether the current user has a "Manage categories" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            if (notAvailable && !_permissionService.Authorize(StandardPermissionProvider.ManageCategories))
            {
                return(InvokeHttp404());
            }

            var searchCatModel = new List <SearchCategoriesModel>
            {
                new SearchCategoriesModel {
                    Id = categoryId, Selected = true
                }
            };

            return(Search(
                       new SearchModel {
                SelectedCategories = searchCatModel
            },
                       command
                       ));

            ////'Continue shopping' URL
            //_genericAttributeService.SaveAttribute(_workContext.CurrentCustomer,
            //    SystemCustomerAttributeNames.LastContinueShoppingPage,
            //    _webHelper.GetThisPageUrl(false),
            //    _storeContext.CurrentStore.Id);

            ////display "edit" (manage) link
            //if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageCategories))
            //    DisplayEditLink(Url.Action("Edit", "Category", new { id = category.Id, area = "Admin" }));

            ////activity log
            //_customerActivityService.InsertActivity("PublicStore.ViewCategory", _localizationService.GetResource("ActivityLog.PublicStore.ViewCategory"), category.Name);

            ////model
            //var model = _catalogModelFactory.PrepareCategoryModel(category, command);

            ////template
            //var templateViewPath = _catalogModelFactory.PrepareCategoryTemplateViewPath(category.CategoryTemplateId);
            //return View(templateViewPath, model);
        }
Example #7
0
 public CategoryModel()
 {
     PictureModel           = new PictureModel();
     FeaturedProducts       = new List <ProductOverviewModel>();
     Products               = new List <ProductOverviewModel>();
     PagingFilteringContext = new CatalogPagingFilteringModel();
     SubCategories          = new List <SubCategoryModel>();
     CategoryBreadcrumb     = new List <CategoryModel>();
 }
Example #8
0
        //////[GrandHttpsRequirement(SslRequirement.No)]
        public virtual IActionResult Category(string categoryId, CatalogPagingFilteringModel command)
        {
            var category = _categoryService.GetCategoryById(categoryId);

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

            //Check whether the current user has a "Manage catalog" permission
            //It allows him to preview a category before publishing
            if (!category.Published && !_permissionService.Authorize(StandardPermissionProvider.ManageCategories))
            {
                return(InvokeHttp404());
            }

            //ACL (access control list)
            if (!_aclService.Authorize(category))
            {
                return(InvokeHttp404());
            }

            //Store mapping
            if (!_storeMappingService.Authorize(category))
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            _genericAttributeService.SaveAttribute(_workContext.CurrentCustomer,
                                                   SystemCustomerAttributeNames.LastContinueShoppingPage,
                                                   _webHelper.GetThisPageUrl(false),
                                                   _storeContext.CurrentStore.Id);

            //display "edit" (manage) link
            if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageCategories))
            {
                DisplayEditLink(Url.Action("Edit", "Category", new { id = category.Id, area = "Admin" }));
            }

            //activity log
            _customerActivityService.InsertActivity("PublicStore.ViewCategory", category.Id, _localizationService.GetResource("ActivityLog.PublicStore.ViewCategory"), category.Name);



            //tbh
            //_customerActionEventService.Viewed(_workContext.CurrentCustomer, Request.Url.ToString(), Request.UrlReferrer != null ? Request.UrlReferrer.ToString() : "");

            //model
            var model = _catalogWebService.PrepareCategory(category, command);

            //template
            var templateViewPath = _catalogWebService.PrepareCategoryTemplateViewPath(category.CategoryTemplateId);

            return(View(templateViewPath, model));
        }
Example #9
0
        public virtual IActionResult Search(SearchModel model, CatalogPagingFilteringModel command)
        {
            if (model == null)
            {
                model = new SearchModel();
            }

            model = _catalogModelFactory.PrepareSearchModel(model, command);
            return(View(model));
        }
        public virtual IActionResult Search(SearchModel model, CatalogPagingFilteringModel command)
        {
            //'Continue shopping' URL
            SaveLastContinueShoppingPage(_workContext.CurrentCustomer);

            //Prepare model
            var searchmodel = _catalogViewModelService.PrepareSearch(model, command);

            return(View(searchmodel));
        }
        // prepareCategoryModel converts CategorySimpleModel --> categoryModel (comsplex model with images)
        private CategoryModel prepareCategoryModel(Category category, CategoryModel tempCategoryModel)
        {
            CatalogPagingFilteringModel catalogPagingFilteringModel = new CatalogPagingFilteringModel();
            var currentcategoryModel = _catalogModelFactory.PrepareCategoryModel(category, catalogPagingFilteringModel);

            tempCategoryModel = currentcategoryModel;
            tempCategoryModel.PictureModel.ImageUrl = _pictureService.GetPictureUrl(category.PictureId);

            return(tempCategoryModel);
        }
        private void GetJsonResult(GsaSetting gsaSetting, string request, CatalogPagingFilteringModel command, out ElasticSearchResultModel modelRes)
        {
            var model = new ElasticSearchResultModel();

            modelRes = model;

            var settings       = new ConnectionSettings(new Uri(gsaSetting.ElasticHost)).DefaultIndex(gsaSetting.SearchIndex);
            var client         = new ElasticClient(settings);
            var searchResponse = client.Search <Product>(s => s
                                                         .Size(0)
                                                         .Query(q => q
                                                                .MultiMatch(m => m
                                                                            .Fields(f => f.Field(p => p.pagetext).Field(p => p.name))
                                                                            .Query(request)
                                                                            )
                                                                )
                                                         .Aggregations(a => a
                                                                       .Terms("unique_results", c => c
                                                                              .Field(f => f.nopid)
                                                                              .Aggregations(ag => ag
                                                                                            .TopHits("top_unique_result", th => th
                                                                                                     .Source(src => src
                                                                                                             .Includes(fs => fs
                                                                                                                       .Field(f => f.name)
                                                                                                                       .Field(f => f.nopid)
                                                                                                                       .Field(f => f.pagetext)
                                                                                                                       .Field(f => f.page_number)
                                                                                                                       )
                                                                                                             )
                                                                                                     .Size(1)
                                                                                                     .TrackScores()
                                                                                                     )
                                                                                            )
                                                                              )
                                                                       )
                                                         );

            model.SearchKeyword        = request;
            model.ElastigRequestResult = null;
            model.TotalResult          = 0;
            model.TotalPages           = 0;

            if (searchResponse.IsValid)
            {
                var results = searchResponse.Aggs.Terms("unique_results");
                model.ElastigRequestResult = results;

                if (results == null || results == null)
                {
                    return;
                }
                model.TotalResult = results.Buckets.Count;
                model.TotalPages  = (results.Buckets.Count <= gsaSetting.EResultsPerPage ? 1 : (results.Buckets.Count / gsaSetting.EResultsPerPage) + 1);
            }
        }
Example #13
0
        public virtual async Task <IActionResult> Search(SearchModel model, CatalogPagingFilteringModel command)
        {
            //'Continue shopping' URL
            await SaveLastContinueShoppingPage(_workContext.CurrentCustomer);

            //Prepare model
            var isSearchTermSpecified = HttpContext?.Request?.Query.ContainsKey("q");
            var searchmodel           = await _catalogViewModelService.PrepareSearch(model, command, isSearchTermSpecified.HasValue?isSearchTermSpecified.Value : false);

            return(View(searchmodel));
        }
        public virtual IActionResult Category(int categoryId, CatalogPagingFilteringModel command)
        {
            var category = _categoryService.GetCategoryById(categoryId);

            if (category == null || category.Deleted)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //published?
                !category.Published ||
                //ACL (access control list)
                !_aclService.Authorize(category) ||
                //Store mapping
                !_storeMappingService.Authorize(category);

            //Check whether the current user has a "Manage categories" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            if (notAvailable && !_permissionService.Authorize(StandardPermissionProvider.ManageCategories))
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            _genericAttributeService.SaveAttribute(_workContext.CurrentCustomer,
                                                   NopCustomerDefaults.LastContinueShoppingPageAttribute,
                                                   _webHelper.GetThisPageUrl(false),
                                                   _storeContext.CurrentStore.Id);

            //display "edit" (manage) link
            if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageCategories))
            {
                DisplayEditLink(Url.Action("Edit", "Category", new { id = category.Id, area = AreaNames.Admin }));
            }

            //activity log
            _customerActivityService.InsertActivity("PublicStore.ViewCategory",
                                                    string.Format(_localizationService.GetResource("ActivityLog.PublicStore.ViewCategory"), category.Name), category);

            //model
            var model = _catalogModelFactory.PrepareCategoryModel(category, command);

            //Link to product if category only contains single product
            if (model.Products.Count == 1)
            {
                return(Redirect("/" + model.Products[0].SeName));
            }

            //template
            var templateViewPath = _catalogModelFactory.PrepareCategoryTemplateViewPath(category.CategoryTemplateId);

            return(View(templateViewPath, model));
        }
Example #15
0
        public virtual IActionResult Manufacturer(string manufacturerId, CatalogPagingFilteringModel command)
        {
            var manufacturer = _manufacturerService.GetManufacturerById(manufacturerId);

            if (manufacturer == null)
            {
                return(InvokeHttp404());
            }

            var customer = _workContext.CurrentCustomer;

            //Check whether the current user has a "Manage catalog" permission
            //It allows him to preview a manufacturer before publishing
            if (!manufacturer.Published && !_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers, customer))
            {
                return(InvokeHttp404());
            }

            //ACL (access control list)
            if (!_aclService.Authorize(manufacturer, customer))
            {
                return(InvokeHttp404());
            }

            //Store mapping
            if (!_storeMappingService.Authorize(manufacturer))
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            _genericAttributeService.SaveAttribute(customer,
                                                   SystemCustomerAttributeNames.LastContinueShoppingPage,
                                                   _webHelper.GetThisPageUrl(false),
                                                   _storeContext.CurrentStore.Id);

            //display "edit" (manage) link
            if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel, customer) && _permissionService.Authorize(StandardPermissionProvider.ManageManufacturers, customer))
            {
                DisplayEditLink(Url.Action("Edit", "Manufacturer", new { id = manufacturer.Id, area = "Admin" }));
            }

            //activity log
            _customerActivityService.InsertActivity("PublicStore.ViewManufacturer", manufacturer.Id, _localizationService.GetResource("ActivityLog.PublicStore.ViewManufacturer"), manufacturer.Name);
            _customerActionEventService.Viewed(customer, this.HttpContext.Request.Path.ToString(), this.Request.Headers[HeaderNames.Referer].ToString() != null ? Request.Headers[HeaderNames.Referer].ToString() : "");

            //model
            var model = _catalogWebService.PrepareManufacturer(manufacturer, command);

            //template
            var templateViewPath = _catalogWebService.PrepareManufacturerTemplateViewPath(manufacturer.ManufacturerTemplateId);

            return(View(templateViewPath, model));
        }
Example #16
0
        public virtual IActionResult Search(SearchModel model, CatalogPagingFilteringModel command)
        {
            //'Continue shopping' URL
            _genericAttributeService.SaveAttribute(_workContext.CurrentCustomer,
                                                   SystemCustomerAttributeNames.LastContinueShoppingPage,
                                                   _webHelper.GetThisPageUrl(false),
                                                   _storeContext.CurrentStore.Id);

            var searchmodel = _catalogWebService.PrepareSearch(model, command);

            return(View(searchmodel));
        }
Example #17
0
        public virtual async Task <IActionResult> Category(string categoryId, CatalogPagingFilteringModel command)
        {
            var category = await _catalogViewModelService.GetCategoryById(categoryId);

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

            var customer = _workContext.CurrentCustomer;

            //Check whether the current user has a "Manage catalog" permission
            //It allows him to preview a category before publishing
            if (!category.Published && !await _permissionService.Authorize(StandardPermissionProvider.ManageCategories, customer))
            {
                return(InvokeHttp404());
            }

            //ACL (access control list)
            if (!_aclService.Authorize(category, customer))
            {
                return(InvokeHttp404());
            }

            //Store mapping
            if (!_storeMappingService.Authorize(category))
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            await SaveLastContinueShoppingPage(customer);

            //display "edit" (manage) link
            if (await _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel, customer) && await _permissionService.Authorize(StandardPermissionProvider.ManageCategories, customer))
            {
                DisplayEditLink(Url.Action("Edit", "Category", new { id = category.Id, area = "Admin" }));
            }

            //activity log
            await _customerActivityService.InsertActivity("PublicStore.ViewCategory", category.Id, _localizationService.GetResource("ActivityLog.PublicStore.ViewCategory"), category.Name);

            await _customerActionEventService.Viewed(customer, this.HttpContext.Request.Path.ToString(), this.Request.Headers[HeaderNames.Referer].ToString() != null?Request.Headers["Referer"].ToString() : "");

            //model
            var model = await _catalogViewModelService.PrepareCategory(category, command);

            //template
            var templateViewPath = await _catalogViewModelService.PrepareCategoryTemplateViewPath(category.CategoryTemplateId);

            return(View(templateViewPath, model));
        }
        public virtual IActionResult ProductsByTagName(string seName, CatalogPagingFilteringModel command, [FromServices] IProductTagService productTagService)
        {
            var productTag = productTagService.GetProductTagBySeName(seName);

            if (productTag == null)
            {
                return(InvokeHttp404());
            }

            var model = _catalogViewModelService.PrepareProductsByTag(productTag, command);

            return(View("ProductsByTag", model));
        }
Example #19
0
        public virtual ActionResult ArticlesByTag(int articleTagId, CatalogPagingFilteringModel command)
        {
            var articleTag = _articleTagService.GetArticleTagById(articleTagId);

            if (articleTag == null)
            {
                return(InvokeHttp404());
            }

            var model = _catalogModelFactory.PrepareArticlesByTagModel(articleTag, command);

            return(View(model));
        }
        public virtual IActionResult ProductsByTag(int productTagId, CatalogPagingFilteringModel command)
        {
            var productTag = _productTagService.GetProductTagById(productTagId);

            if (productTag == null)
            {
                return(InvokeHttp404());
            }

            var model = _catalogModelFactory.PrepareProductsByTagModel(productTag, command);

            return(View(model));
        }
Example #21
0
        public virtual async Task <IActionResult> ProductsByTag(string productTagId, CatalogPagingFilteringModel command, [FromServices] IProductTagService productTagService)
        {
            var productTag = await productTagService.GetProductTagById(productTagId);

            if (productTag == null)
            {
                return(InvokeHttp404());
            }

            var model = await _catalogViewModelService.PrepareProductsByTag(productTag, command);

            return(View(model));
        }
Example #22
0
        public ActionResult Search(SearchModel model, CatalogPagingFilteringModel command)
        {
            if (model == null)
            {
                model = new SearchModel();
            }

            if (command.PageSize == 0)
            {
                command.PageSize = 8;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            if (model.Q == null)
            {
                model.Q = "";
            }
            model.Q = model.Q.Trim();

            IPagedList <Product> products = new PagedList <Product>(new List <Product>(), 0, 1);

            // only search if query string search keyword is set (used to avoid searching or displaying search term min length error message on /search page load)
            if (Request.Params["Q"] != null)
            {
                if (model.Q.Length < _catalogSettings.ProductSearchTermMinimumLength)
                {
                    model.Warning = string.Format(_localizationService.GetResource("Search.SearchTermMinimumLengthIsNCharacters"), _catalogSettings.ProductSearchTermMinimumLength);
                }
                else
                {
                    //products
                    products = _productService.SearchProducts(
                        storeId: _storeContext.CurrentStore.Id,
                        visibleIndividuallyOnly: true,
                        keywords: model.Q,
                        languageId: _workContext.WorkingLanguage.Id,
                        pageIndex: command.PageNumber - 1,
                        pageSize: command.PageSize);
                    model.Products = PrepareProductOverviewModels(products).ToList();

                    model.NoResults = !model.Products.Any();
                }
            }

            model.PagingFilteringContext.LoadPagedList(products);

            return(View("~/Plugins/Misc.FacebookShop/Views/MiscFacebookShop/Search.cshtml", model));
        }
Example #23
0
        public virtual async Task <IActionResult> Category(int categoryId, CatalogPagingFilteringModel command)
        {
            var category = await _categoryService.GetCategoryByIdAsync(categoryId);

            if (category == null || category.Deleted)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //published?
                !category.Published ||
                //ACL (access control list)
                !await _aclService.AuthorizeAsync(category) ||
                //Store mapping
                !await _storeMappingService.AuthorizeAsync(category);

            //Check whether the current user has a "Manage categories" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            var hasAdminAccess = await _permissionService.AuthorizeAsync(StandardPermissionProvider.AccessAdminPanel) && await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCategories);

            if (notAvailable && !hasAdminAccess)
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            await _genericAttributeService.SaveAttributeAsync(await _workContext.GetCurrentCustomerAsync(),
                                                              NopCustomerDefaults.LastContinueShoppingPageAttribute,
                                                              _webHelper.GetThisPageUrl(false),
                                                              (await _storeContext.GetCurrentStoreAsync()).Id);

            //display "edit" (manage) link
            if (await _permissionService.AuthorizeAsync(StandardPermissionProvider.AccessAdminPanel) && await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCategories))
            {
                DisplayEditLink(Url.Action("Edit", "Category", new { id = category.Id, area = AreaNames.Admin }));
            }

            //activity log
            await _customerActivityService.InsertActivityAsync("PublicStore.ViewCategory",
                                                               string.Format(await _localizationService.GetResourceAsync("ActivityLog.PublicStore.ViewCategory"), category.Name), category);

            //model
            var model = await _catalogModelFactory.PrepareCategoryModelAsync(category, command);

            //template
            var templateViewPath = await _catalogModelFactory.PrepareCategoryTemplateViewPathAsync(category.CategoryTemplateId);

            return(View(templateViewPath, model));
        }
Example #24
0
        public GBSProductCategory(int productCategoryId)
        {
            //nop category data
            ICategoryService categoryService = EngineContext.Current.Resolve <ICategoryService>();

            this.id = productCategoryId;
            Category                    category                    = categoryService.GetCategoryById(productCategoryId);
            ICatalogModelFactory        catalogModelFactory         = EngineContext.Current.Resolve <ICatalogModelFactory>();
            CatalogPagingFilteringModel catalogPagingFilteringModel = new CatalogPagingFilteringModel();

            catalogPagingFilteringModel.PageSize = 1;
            this.PagingFilteringContext          = catalogPagingFilteringModel;
            CategoryModel categoryModel = catalogModelFactory.PrepareCategoryModel(category, catalogPagingFilteringModel);

            this.Name                      = categoryModel.Name;
            this.Description               = categoryModel.Description;
            this.MetaKeywords              = categoryModel.MetaKeywords;
            this.MetaDescription           = categoryModel.MetaDescription;
            this.MetaTitle                 = categoryModel.MetaTitle;
            this.SeName                    = categoryModel.SeName;
            this.PictureModel              = categoryModel.PictureModel;
            this.PagingFilteringContext    = categoryModel.PagingFilteringContext;
            this.DisplayCategoryBreadcrumb = categoryModel.DisplayCategoryBreadcrumb;
            this.CategoryBreadcrumb        = categoryModel.CategoryBreadcrumb;
            this.SubCategories             = categoryModel.SubCategories;
            this.FeaturedProducts          = categoryModel.FeaturedProducts;
            this.Products                  = categoryModel.Products;

            //datalook up via category(product category) id from gbscategory table
            Dictionary <string, Object> productCategoryDic = new Dictionary <string, Object>();

            productCategoryDic.Add("@CategoryId", productCategoryId);

            string   productCategoryDataQuery = "EXEC usp_SelectGBSCustomCategoryData @CategoryId";
            DataView productCategoryDataView  = manager.GetParameterizedDataView(productCategoryDataQuery, productCategoryDic);

            if (productCategoryDataView.Count > 0)
            {
                //product category specific data
                this.parentCategoryId = category.ParentCategoryId;
                this.h1              = !string.IsNullOrEmpty(productCategoryDataView[0]["H1"].ToString()) ? productCategoryDataView[0]["H1"].ToString() : this.Name;
                this.h2              = !string.IsNullOrEmpty(productCategoryDataView[0]["H2"].ToString()) ? productCategoryDataView[0]["H2"].ToString() : _h2;
                this.topText         = !string.IsNullOrEmpty(productCategoryDataView[0]["UpperText"].ToString()) ? productCategoryDataView[0]["UpperText"].ToString() : _topText;
                this.bottomText      = !string.IsNullOrEmpty(productCategoryDataView[0]["LowerText"].ToString()) ? productCategoryDataView[0]["LowerText"].ToString() : _bottomText;
                this.backgroundImage = !string.IsNullOrEmpty(productCategoryDataView[0]["BackgroundPicturePath"].ToString()) ? productCategoryDataView[0]["BackgroundPicturePath"].ToString() : _backgroundImage;
                this.foregroundImage = !string.IsNullOrEmpty(productCategoryDataView[0]["ForegroundPicturePath"].ToString()) ? productCategoryDataView[0]["ForegroundPicturePath"].ToString() : _foregroundImage;
                this.backgroundColor = !string.IsNullOrEmpty(productCategoryDataView[0]["BackgroundColor"].ToString()) ? productCategoryDataView[0]["BackgroundColor"].ToString() : _backgroundColor;
                this.mainPicturePath = !string.IsNullOrEmpty(productCategoryDataView[0]["MainPicturePath"].ToString()) ? productCategoryDataView[0]["MainPicturePath"].ToString() : _mainPicturePath;
            }
        }
        public virtual IActionResult Manufacturer(int manufacturerId, CatalogPagingFilteringModel command)
        {
            var manufacturer = _manufacturerService.GetManufacturerById(manufacturerId);

            if (manufacturer == null || manufacturer.Deleted)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //published?
                !manufacturer.Published ||
                //ACL (access control list)
                !_aclService.Authorize(manufacturer) ||
                //Store mapping
                !_storeMappingService.Authorize(manufacturer);
            //Check whether the current user has a "Manage categories" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            var hasAdminAccess = _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageManufacturers);

            if (notAvailable && !hasAdminAccess)
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            _genericAttributeService.SaveAttribute(_workContext.CurrentCustomer,
                                                   NopCustomerDefaults.LastContinueShoppingPageAttribute,
                                                   _webHelper.GetThisPageUrl(false),
                                                   _storeContext.CurrentStore.Id);

            //display "edit" (manage) link
            if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageManufacturers))
            {
                DisplayEditLink(Url.Action("Edit", "Manufacturer", new { id = manufacturer.Id, area = AreaNames.Admin }));
            }

            //activity log
            _customerActivityService.InsertActivity("PublicStore.ViewManufacturer",
                                                    string.Format(_localizationService.GetResource("ActivityLog.PublicStore.ViewManufacturer"), manufacturer.Name), manufacturer);

            //model
            var model = _catalogModelFactory.PrepareManufacturerModel(manufacturer, command);

            //template
            var templateViewPath = _catalogModelFactory.PrepareManufacturerTemplateViewPath(manufacturer.ManufacturerTemplateId);

            return(View(templateViewPath, model));
        }
        public virtual IActionResult Search(SearchModel model, CatalogPagingFilteringModel command)
        {
            //'Continue shopping' URL
            _genericAttributeService.SaveAttribute(_workContext.CurrentCustomer,
                                                   NopCustomerDefaults.LastContinueShoppingPageAttribute,
                                                   _webHelper.GetThisPageUrl(true),
                                                   _storeContext.CurrentStore.Id);

            if (model == null)
            {
                model = new SearchModel();
            }

            model = _catalogModelFactory.PrepareSearchModel(model, command);
            return(View(model));
        }
        public virtual ActionResult Destination(int destinationId, CatalogPagingFilteringModel command)
        {
            var destination = _destinationService.GetDestinationById(destinationId);

            if (destination == null || destination.Deleted)
            {
                return(InvokeHttp404());
            }

            var notAvailable =
                //published?
                !destination.Published ||
                //ACL (access control list)
                !_aclService.Authorize(destination) ||
                //Store mapping
                !_storeMappingService.Authorize(destination);

            //Check whether the current user has a "Manage categories" permission (usually a store owner)
            //We should allows him (her) to use "Preview" functionality
            if (notAvailable && !_permissionService.Authorize(StandardPermissionProvider.ManageDestinations))
            {
                return(InvokeHttp404());
            }

            //'Continue shopping' URL
            _genericAttributeService.SaveAttribute(_workContext.CurrentCustomer,
                                                   SystemCustomerAttributeNames.LastContinueShoppingPage,
                                                   _webHelper.GetThisPageUrl(false),
                                                   _storeContext.CurrentStore.Id);

            //display "edit" (manage) link
            if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageDestinations))
            {
                DisplayEditLink(Url.Action("Edit", "Destination", new { id = destination.Id, area = "Admin" }));
            }

            //activity log
            _customerActivityService.InsertActivity("PublicStore.ViewDestination", _localizationService.GetResource("ActivityLog.PublicStore.ViewDestination"), destination.Name);

            //model
            var model = _catalogModelFactory.PrepareDestinationModel(destination, command);

            //template
            var templateViewPath = _catalogModelFactory.PrepareDestinationTemplateViewPath(destination.DestinationTemplateId);

            return(View(templateViewPath, model));
        }
Example #28
0
        public virtual void PrepareSortingOptions(CatalogPagingFilteringModel pagingFilteringModel, CatalogPagingFilteringModel command)
        {
            if (pagingFilteringModel == null)
            {
                throw new ArgumentNullException("pagingFilteringModel");
            }

            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var allDisabled = _catalogSettings.ProductSortingEnumDisabled.Count == Enum.GetValues(typeof(ProductSortingEnum)).Length;

            pagingFilteringModel.AllowProductSorting = _catalogSettings.AllowProductSorting && !allDisabled;

            var activeOptions = Enum.GetValues(typeof(ProductSortingEnum)).Cast <int>()
                                .Except(_catalogSettings.ProductSortingEnumDisabled)
                                .Select((idOption) =>
            {
                int order;
                return(new KeyValuePair <int, int>(idOption, _catalogSettings.ProductSortingEnumDisplayOrder.TryGetValue(idOption, out order) ? order : idOption));
            })
                                .OrderBy(x => x.Value);

            if (command.OrderBy == null)
            {
                command.OrderBy = allDisabled ? 0 : activeOptions.First().Key;
            }

            if (pagingFilteringModel.AllowProductSorting)
            {
                foreach (var option in activeOptions)
                {
                    var currentPageUrl = _webHelper.GetThisPageUrl(true);
                    var sortUrl        = _webHelper.ModifyQueryString(currentPageUrl, "orderby=" + (option.Key).ToString(), null);

                    var sortValue = ((ProductSortingEnum)option.Key).GetLocalizedEnum(_localizationService, _workContext);
                    pagingFilteringModel.AvailableSortOptions.Add(new SelectListItem
                    {
                        Text     = sortValue,
                        Value    = sortUrl,
                        Selected = option.Key == command.OrderBy
                    });
                }
            }
        }
Example #29
0
        public virtual IActionResult Category(int id, string title, CatalogPagingFilteringModel command)
        {
            var category = _categoryService.GetCategoryById(id);

            if (category == null || category.Deleted)
            {
                return(InvokeHttp404());
            }

            //model
            var model = _catalogModelFactory.PrepareCategoryModel(category, command);

            //template
            var templateViewPath = _catalogModelFactory.PrepareCategoryTemplateViewPath(category.CategoryTemplateId);

            return(View(templateViewPath, model));
        }
Example #30
0
        public virtual async Task <IActionResult> Search(SearchModel model, CatalogPagingFilteringModel command)
        {
            //'Continue shopping' URL
            await _genericAttributeService.SaveAttributeAsync(await _workContext.GetCurrentCustomerAsync(),
                                                              NopCustomerDefaults.LastContinueShoppingPageAttribute,
                                                              _webHelper.GetThisPageUrl(true),
                                                              (await _storeContext.GetCurrentStoreAsync()).Id);

            if (model == null)
            {
                model = new SearchModel();
            }

            model = await _catalogModelFactory.PrepareSearchModelAsync(model, command);

            return(View(model));
        }
        public ActionResult Search(CatalogPagingFilteringModel command)
        {
            var request    = Request.Params["q"];
            var gsaSetting = _settingService.LoadSetting <GsaSetting>();
            var langId     = _workContext.WorkingLanguage.LanguageCulture;

            if (gsaSetting.isGsa)
            {
                var searchResult = _gsaService.Search(request, gsaSetting, langId, command);
                return(View("~/Plugins/GSA/Views/GsaSearch/Search.cshtml", searchResult));
            }
            else if (gsaSetting.IsElastic)
            {
                //if (_elasticSearchResult == null || !_elasticSearchResult.SearchKeyword.Equals(request))
                //{
                //    if (Session["elasticSearchResult"] == null)
                //    {
                //        _elasticSearchResult = _elasticSearch.Search(request, gsaSetting, langId, command);
                //        Session["elasticSearchResult"] = _elasticSearchResult;
                //    }
                //    else
                //        _elasticSearchResult = Session["elasticSearchResult"] as ElasticSearchResultModel;
                //}

                if (Session["elasticSearchResult"] != null && Session["SearchReques"].ToString().Equals(request))
                {
                    _elasticSearchResult = Session["elasticSearchResult"] as ElasticSearchResultModel;
                }
                else
                {
                    _elasticSearchResult           = _elasticSearch.Search(request, gsaSetting, langId, command);
                    Session["elasticSearchResult"] = _elasticSearchResult;
                    Session["SearchReques"]        = request;
                }


                _elasticSearchResult.Data.Results = GetResults(command, gsaSetting);

                return(View("~/Plugins/GSA/Views/GsaSearch/ElasticSearch.cshtml", _elasticSearchResult.Data));
            }
            else
            {
                return(View("~/Plugins/GSA/Views/GsaSearch/NoSearchEngine.cshtml"));
            }
        }
        public ActionResult Category(int categoryId, CatalogPagingFilteringModel command)
        {
            var category = _categoryService.GetCategoryById(categoryId);
            if (category == null || category.Deleted)
                return Content("");

            //Check whether the current user has a "Manage catalog" permission
            //It allows him to preview a category before publishing
            if (!category.Published && !_permissionService.Authorize(StandardPermissionProvider.ManageCategories))
                return Content("");

            //ACL (access control list)
            if (!_aclService.Authorize(category))
                return Content("");

            //Store mapping
            if (!_storeMappingService.Authorize(category))
                return Content("");

            if (category.PageSizeOptions != null)
            {
                var pageSizes= category.PageSizeOptions
                    .Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                int temp = 0;
                if (int.TryParse(pageSizes.FirstOrDefault(), out temp))
                {
                    if (temp > 0)
                    {
                        command.PageSize = temp;
                    }
                }
            }
            if (command.PageSize == 0)
            {
                command.PageSize = 8;
            }
            if (command.PageNumber <= 0) command.PageNumber = 1;

            var model = new CategoryModel()
            {
                Id = category.Id,
                Name = category.GetLocalized(x => x.Name),
                SeName = category.GetSeName(),
                Description = category.GetLocalized(x => x.Description)
            };

            //subcategories
            model.SubCategories = _categoryService
                .GetAllCategoriesByParentCategoryId(categoryId)
                .Select(x =>
                {
                    var subCatName = x.GetLocalized(y => y.Name);
                    var subCatModel = new CategoryModel()
                    {
                        Id = x.Id,
                        Name = subCatName,
                        SeName = x.GetSeName(),
                    };

                    //prepare picture model
                    int pictureSize = 125;
                    var picture = _pictureService.GetPictureById(x.PictureId);
                    subCatModel.PictureModel = new PictureModel()
                        {
                            FullSizeImageUrl = _pictureService.GetPictureUrl(picture),
                            ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize),
                            Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), subCatName),
                            AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), subCatName)
                        };

                    return subCatModel;
                })
                .ToList();

            var categoryIds = new List<int>();
            if (categoryId > 0)
            {
                categoryIds.Add(categoryId);
            }
            //products
            IList<int> filterableSpecificationAttributeOptionIds = null;
            var products = _productService.SearchProducts(out filterableSpecificationAttributeOptionIds,
                categoryIds: categoryIds,
                storeId: _storeContext.CurrentStore.Id,
                visibleIndividuallyOnly: true,
                featuredProducts: null,
                orderBy: ProductSortingEnum.Position,
                pageIndex: command.PageNumber - 1,
                pageSize: command.PageSize);
            model.Products = PrepareProductOverviewModels(products).ToList();

            model.PagingFilteringContext.LoadPagedList(products);

            return PartialView("Nop.Plugin.Misc.FacebookShop.Views.MiscFacebookShop.Category", model);
        }
Example #33
0
 public SearchModel()
 {
     PagingFilteringContext = new CatalogPagingFilteringModel();
     Products = new List<ProductOverviewModel>();
 }
        public ActionResult Search(SearchModel model, CatalogPagingFilteringModel command)
        {
            if (model == null)
                model = new SearchModel();

            if (command.PageSize == 0)
            {
                command.PageSize = 8;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            if (model.Q == null)
                model.Q = "";
            model.Q = model.Q.Trim();

            IPagedList<Product> products = new PagedList<Product>(new List<Product>(), 0, 1);
            // only search if query string search keyword is set (used to avoid searching or displaying search term min length error message on /search page load)
            if (Request.Params["Q"] != null)
            {
                if (model.Q.Length < _catalogSettings.ProductSearchTermMinimumLength)
                {
                    model.Warning = string.Format(_localizationService.GetResource("Search.SearchTermMinimumLengthIsNCharacters"), _catalogSettings.ProductSearchTermMinimumLength);
                }
                else
                {
                    //products
                    products = _productService.SearchProducts(
                        storeId: _storeContext.CurrentStore.Id,
                        visibleIndividuallyOnly: true,
                        keywords: model.Q,
                        languageId: _workContext.WorkingLanguage.Id,
                        pageIndex: command.PageNumber - 1,
                        pageSize: command.PageSize);
                    model.Products = PrepareProductOverviewModels(products).ToList();

                    model.NoResults = !model.Products.Any();
                }
            }

            model.PagingFilteringContext.LoadPagedList(products);

            return View("~/Plugins/Misc.FacebookShop/Views/MiscFacebookShop/Search.cshtml", model);
        }