How to (re)Enable Category Sorting in PrestaShop’s Back Office

In this quick tip we will see how to take the movement arrows back for the category list in the back office of Prestashop 1.5.6 and up

Watch The Screencast:

Text version

If you just uploaded to a Prestashop version higher 1.5.6, you will have noticed you can’t move categories anymore from the back office. Actually, this is only half true, you can move categories… if you do what Prestashop wants.

How to Move categories again in Prestashop's back office

By default, to make the shy arrows pop out, you have to sort by position ascendant, by clicking the button highlighted in the next picture. Boring, huh? If you hit reset, they will vanish again.

Sort categories in Prestashop's Back Office

To take them back by default, we therefore need to tell Prestashop to sort by position (ascendant) if no sorting parameter is passed. Open up AdminCategoriesController, that you can find in controllers/admin. You can use an override if you prefer, I will go ahead and edit the core file. Locate”

	public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
	{
		parent::getList($id_lang, $order_by, $order_way, $start, $limit, Context::getContext()->shop->id);
		// Check each row to see if there are combinations and get the correct action in consequence

		$nb_items = count($this->_list);
		for ($i = 0; $i < $nb_items; $i++)
		{
			$item = &$this->_list[$i];
			$category_tree = Category::getChildren((int)$item['id_category'], $this->context->language->id);
			if (!count($category_tree))
				$this->addRowActionSkipList('view', array($item['id_category']));
		}
	}

At the very beginning, add:

	public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
	{
		if(!Tools::getValue('categoryOrderby'))
			$order_by = 'position';
		if(!Tools::getValue('categoryOrderway'))
			$order_way = 'asc';
	}

Explanation: we are simply telling Prestashop to use order by position adcendant if no category order parameter is passed (aka: we didn’t click anything or tried to input any filter).

The final method:

	public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
	{

		if(!Tools::getValue('categoryOrderby'))
			$order_by = 'position';
		if(!Tools::getValue('categoryOrderway'))
			$order_way = 'asc';

		parent::getList($id_lang, $order_by, $order_way, $start, $limit, Context::getContext()->shop->id);
		// Check each row to see if there are combinations and get the correct action in consequence

		$nb_items = count($this->_list);
		for ($i = 0; $i < $nb_items; $i++)
		{
			$item = &$this->_list[$i];
			$category_tree = Category::getChildren((int)$item['id_category'], $this->context->language->id);
			if (!count($category_tree))
				$this->addRowActionSkipList('view', array($item['id_category']));
		}
	}

Refresh the back office, reset all filters, and you will have the arrows back

Need Prestashop Modules? Have a look at my Prestashop Addons Store!

Looking for quality PrestaShop Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , | Posted under PrestaShop, Video | RSS 2.0

Author Spotlight

Fabio Porta

Fabio Porta

Fabio has been involved in web development and design since 2005, when launched his first website at the age of 16. He’s now highly skilled in both client and server side development, along with design, and since August 2012 runs a successful website about PrestaShop tutorials and Prestashop Modules called Nemo’s Post Scriptum, at http://nemops.com

Leave a Reply

Your email address will not be published. Required fields are marked *


3 × 7 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>