Month: November 2018

Magento 2 admin catalog product edit form – categories order

I have recently been doing some developments in Magento 2 and have found out some inconsistency in the product edit form in the admin section.

The desired sort order of the category should be the default position one. However in the product edit admin catalog product edit form, the sort order is not defined therefore, it appears in the way it is returned from the database. This is not very user-friendly especially if you have about 4000 categories to deal with.

Magento 2 admin product edit form category sort order - backend Magento 2 natural - original  category sort order - frontend
admin catalog product edit form – categories order categories order on frontend

Thus to obtain same layout, we have made changed in following pre. You can also create pre pool and add the pre there, but this is a quick fix

My Magento version is community 2.2.6



Go to line 375 and add the following code


Make sure to add this line before

foreach ($collection as $category) {.

So the final code should look like as follows


        foreach ($collection as $category) {
            foreach ([$category->getId(), $category->getParentId()] as $categoryId) {
                if (!isset($categoryById[$categoryId])) {
                    $categoryById[$categoryId] = ['value' => $categoryId];

            $categoryById[$category->getId()]['is_active'] = $category->getIsActive();
            $categoryById[$category->getId()]['label'] = $category->getName();
            $categoryById[$category->getParentId()]['optgroup'][] = &$categoryById[$category->getId()];

            self::CATEGORY_TREE_ID . '_' . $filter,

        return $categoryById[CategoryModel::TREE_ROOT_ID]['optgroup'];

Thus my final version looks as following


Magento 2 quick check list before going live

Hello all

I have been working on Magento2 from quiet a while and getting my hands on its development & deployment. I know it always happens when you develop or customise something and keep on refreshing the page, but you does not get the desired results.

Therefore I have created a quick checklist to make sure all boxes are ticked before you go live. I have also included the commands so that its handy to run them in order

Production mode is enabled

php bin/magento deploy:mode:set production

Cache is first flushed and then enabled

php bin/magento cache:clean
php bin/magento cache:enable

Static contents have been deployed

 php bin/magento setup:static-content:deploy

var folder persmissions

chmod -R 777 var

pub folder persmissions

chmod -R 777 pub

Static contents have been deployed

 php bin/magento setup:static-content:deploy

Catalog has been reindexed

 php bin/magento indexer:reindex