skinbasis Posted October 25, 2013 Share Posted October 25, 2013 (edited) Hi all, For a few days now I'm searching for something like this but seems like no one has tried it before. What I want to do is to have a category or subcategory disabled, and still access it by url and have the products there. Disabled categories don't show products. In category.tpl you have the $category->active query and delete it, but I can not find where the function that prevents products to be displayed in a disabled categories is? Has anyone done this? Thanks a lot! Hi all, For a few days now I'm searching for something like this but seems like no one has tried it before. What I want to do is to have a category or subcategory disabled, and still access it by url and have the products there. Disabled categories don't show products. In category.tpl you have the $category->active query and delete it, but I can not find where the function that prevents products to be displayed in a disabled categories is? Has anyone done this? Thanks a lot! Edited October 25, 2013 by skinbasis (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted October 26, 2013 Share Posted October 26, 2013 Please forgive my rudeness, but what is the point of having it disabled... if it's still being displayed? Link to comment Share on other sites More sharing options...
skinbasis Posted October 26, 2013 Author Share Posted October 26, 2013 There's no problem and you are right but I need the category to be accessible only by url, also it's good for SEO. I want to make categories based on products brands, like layered module does, but the url that layered module generates are long, seo unfriendly and also they have #. So, in other words, I need the disable categories with products shown to be access by url. Link to comment Share on other sites More sharing options...
NemoPS Posted October 28, 2013 Share Posted October 28, 2013 I see, you so you want them to be removed from the breadcrumbs of a product's page? But that is not good for seo Link to comment Share on other sites More sharing options...
skinbasis Posted October 28, 2013 Author Share Posted October 28, 2013 Let's say like this: domain/120_shorts ... will trigger the caregory "Men Shorts" that is disabled and will state: "Sorry, this category is unavailable." But, if you go to category.tpl and remove the "AND $category->active" the page will state "There are no products in this category." So, again, my question is - How to show the products in a disabled category. Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 28, 2013 Share Posted October 28, 2013 You may need to modify/override file CategoryController.php in public function assignProductList() and force the inactive category became active if(!$this->category->active) $this->category->active = true; Also modify/override CategoryController.php in public function init() because the inactive (disabled) category will return header('HTTP/1.1 404 Not Found'); Link to comment Share on other sites More sharing options...
Joos Posted January 23, 2015 Share Posted January 23, 2015 Hey, Im want to achieve the same, but i dont understand what i'm supposed to change Link to comment Share on other sites More sharing options...
NemoPS Posted January 24, 2015 Share Posted January 24, 2015 As gonebdg said, you must override the category controller. Once you force it to active it should return products Link to comment Share on other sites More sharing options...
Joos Posted January 24, 2015 Share Posted January 24, 2015 Ok,, and how to i override it? exactly? Link to comment Share on other sites More sharing options...
Joos Posted January 26, 2015 Share Posted January 26, 2015 Where exactly am i supposed to put what? I found the public function init() in the categorycontroller.php public function init() { // Get category ID $id_category = (int)Tools::getValue('id_category'); if (!$id_category || !Validate::isUnsignedId($id_category)) $this->errors[] = Tools::displayError('Missing category ID'); // Instantiate category $this->category = new Category($id_category, $this->context->language->id); parent::init(); //check if the category is active and return 404 error if is disable. if (!$this->category->active) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } //check if category can be accessible by current customer and return 403 if not if (!$this->category->checkAccess($this->context->customer->id)) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); $this->errors[] = Tools::displayError('You do not have access to this category.'); $this->customer_access = false; } } and i found the product list $this->productSort(); // Product sort must be called before assignProductList() $this->assignScenes(); $this->assignSubcategories(); $this->assignProductList(); $this->context->smarty->assign(array( 'category' => $this->category, 'description_short' => Tools::truncateString($this->category->description, 350), 'products' => (isset($this->cat_products) && $this->cat_products) ? $this->cat_products : null, 'id_category' => (int)$this->category->id, 'id_category_parent' => (int)$this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->name), 'path' => Tools::getPath($this->category->id), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'categorySize' => Image::getSize(ImageType::getFormatedName('category')), 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), 'thumbSceneSize' => Image::getSize(ImageType::getFormatedName('m_scene')), 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'allow_oosp' => (int)Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'), 'suppliers' => Supplier::getSuppliers(), 'body_classes' => array($this->php_self.'-'.$this->category->id, $this->php_self.'-'.$this->category->link_rewrite) )); } Link to comment Share on other sites More sharing options...
NemoPS Posted January 26, 2015 Share Posted January 26, 2015 Try adding this at the beginning of the init method, right after the $this->category assignment $this->category->active = 1; Link to comment Share on other sites More sharing options...
Joos Posted January 26, 2015 Share Posted January 26, 2015 (edited) I've added it , but it doesnt work. Cleared cache of prestashop and my browser. See the code, did i add it wrong? public function init() { // Get category ID $id_category = (int)Tools::getValue('id_category'); if (!$id_category || !Validate::isUnsignedId($id_category)) $this->errors[] = Tools::displayError('Missing category ID'); // Instantiate category $this->category = new Category($id_category, $this->context->language->id);$this->category->active = 1; parent::init(); Edited January 26, 2015 by Joos (see edit history) Link to comment Share on other sites More sharing options...
Joos Posted January 27, 2015 Share Posted January 27, 2015 I've also tried this, but didnt work either public function init() { // Get category ID $id_category = (int)Tools::getValue('id_category'); if (!$id_category || !Validate::isUnsignedId($id_category)) $this->errors[] = Tools::displayError('Missing category ID'); // Instantiate category $this->category = new Category($id_category, $this->context->language->id); parent::init(); //check if the category is active and return 404 error if is disable. if (!$this->category->active) $this->category->active = 1; { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); Link to comment Share on other sites More sharing options...
NemoPS Posted January 28, 2015 Share Posted January 28, 2015 Of course, you actually broke the code in the second before the if, right before it, on its own line. It should have worked the first time though. You are not using overrides, are you? $this->category->active = 1; if (.... let us know what you get Link to comment Share on other sites More sharing options...
Joos Posted January 29, 2015 Share Posted January 29, 2015 public function init() { // Get category ID $id_category = (int)Tools::getValue('id_category'); if (!$id_category || !Validate::isUnsignedId($id_category)) $this->errors[] = Tools::displayError('Missing category ID'); // Instantiate category $this->category->active = 1; $this->category = new Category($id_category, $this->context->language->id); parent::init(); //check if the category is active and return 404 error if is disable. if (!$this->category->active) Am not using any overides as far as i know of. It's still not working. Showing 3 products while the inactive category has about 935. You can check it out on http://goo.gl/PYqMdA if needed Link to comment Share on other sites More sharing options...
NemoPS Posted January 30, 2015 Share Posted January 30, 2015 Ah, it shows up then. Are those other products enabled? Since the category doesn't kick you out, that fix does work and you need to look somewhere else Link to comment Share on other sites More sharing options...
Joos Posted January 30, 2015 Share Posted January 30, 2015 Then I have no idea what's going wrong. Because it's showing up on one categorie but not in the rest. And only 3 products form the 900. Im lost... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now