I have created a new category using the script below. Once I have created the category using the script, then added a subcategory through admin, The category checkbox tree will not load on the Catalog Price Rules page.

Marketing->Catalog Price Rules->Add New Rule->Conditions->(+)->Please Select a Condition to Add->Category->(...)->(open Chooser)(This is the option right next to the input field

It appears there is an error causing the script to reload the category in an infinite loop.

//creating categories in magento 2
//last verified Magento 2.2.0  27 Oct 2017
use \Magento\Framework\App\Bootstrap;
echo 'code by harshvardhanmalpani';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
function createCategory($a='',$b=1,$c=true,$d='',$e='',$f='',$g='') {
        global $objectManager;
        $category = $objectManager->get('\Magento\Catalog\Model\CategoryFactory')->create();
        $category->setParentId($b); // 1: root category.
'description' => $d,
'meta_title' => $e,
'meta_keywords' => $f,
'meta_description' => $g,
  • Looks like you are missing to set root category/parent category. – Prasanta Hatui Jun 1 '18 at 15:16
  • Is the root category id indeed of 1 ? Have a look at magento.stackexchange.com/a/36560/7773 to get it – nicolallias Jun 1 '18 at 15:52
  • The parent category is 1. I am adding a root category, and it will be for a new store, so there is no store at the time the category is created. I do link it to the store during the store creation process. – Joey Carder Jun 1 '18 at 17:12
  • I have looked into this a little further. In the file vendor/magento/module-catalog/view/adminhtml/web/js/category-checkbox-tree.js there is a for loop that increments the first few times, but gets stuck after that. – Joey Carder Jun 14 '18 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.