Jump to content

[Class] Manually sort or order category for prestashop 1.2.1 final


Recommended Posts

Hi everyone, it's my first code contribution so please be nice :)

I've been looking for this and the usual answer is to put numbers in front of the category name. Well, no thanks.
I considered making a separate module to do this to avoid breaking classes, but ultimately modifying the classes result in better integration.

Tested on 1.2.1 final ONLY.
USE AT YOUR OWN RISK
Common sense applies: make backups, don't test on production site, etc

HOW-TO
---------

Step 1. Modify your ps_category table
------------------------------------------
ALTER TABLE `ps_category`
ADD `position` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'
AFTER `level_depth`


Step 2. Copy the files
------------------------
AdminCategories.php -> /admin/tabs/AdminCategories.php
Category.php -> /classes/Category.php
blockcategories.php -> /modules/blockcategories/blockcategories.php

Step 3. Manually edit your database
----------------------------------------
Edit the ps_category table to manually order the categories within every id_parent
Taking for example the installed sample database

Change this

id_category  id_parent  position
    1           0         0
    2           1         0
    3           1         0
    4           1         0



to this

id_category  id_parent  position
    1           0         0
    2           1         0
    3           1         1
    4           1         2



You must start at 0 for every id_parent.

That's it, enjoy!


To-do/wish list:
-----------------
1. sql script to automatically number the positions, so you don't have to do step 3 manually
2. drag & drop reordering doesn't work in admin.

I'm unlikely to do either, as the script is currently good enough for my purpose. Some help would be much appreciated.

Category.php

AdminCategories.php

blockcategories.php

Share this post


Link to post
Share on other sites
  • 7 months later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More