Jump to content

How to Display products in disabled categories?


skinbasis

Recommended Posts

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 by skinbasis (see edit history)
Link to comment
Share on other sites

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

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

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

  • 1 year later...

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

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 by Joos (see edit history)
Link to comment
Share on other sites

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

Of course, you actually broke the code in the second :D

 

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...