Jump to content

PS 1.7 MainMenu automatic order


TheMic

Recommended Posts

Ok... I found a solution on StackOverflow: https://stackoverflow.com/questions/41846364/ordering-categories-alphabetically-in-prestashop-top-menu

we need to override the ps_mainmenu with this content:

use PrestaShop\PrestaShop\Core\Module\WidgetInterface;

class Ps_MainMenuOverride extends Ps_MainMenu implements WidgetInterface
{
    protected function generateCategoriesMenu($categories, $is_children = 0)
    {
        $categories = $this->sortCategories($categories);
        return parent::generateCategoriesMenu($categories, $is_children);
    }

    public function sortCategories($categories)
    {

        uasort($categories, 'cmpcat');

        foreach($categories as $k => $category)
        {
            if (isset($category['children']) && !empty($category['children'])) {
                $children = $this->sortCategories($category['children']);
                $categories[$k]['children'] = $children;
            }
        }
        return $categories;
    }
}

function cmpcat($a, $b) {
    return strcmp($a['name'], $b['name']);
}

 

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...