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.
<?php
//creating categories in magento 2
//last verified Magento 2.2.0 27 Oct 2017
use \Magento\Framework\App\Bootstrap;
echo 'code by harshvardhanmalpani';
include('./app/bootstrap.php');
$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->setName($a);
$category->setParentId($b); // 1: root category.
$category->setIsActive($c);
$category->setCustomAttributes([
'description' => $d,
'meta_title' => $e,
'meta_keywords' => $f,
'meta_description' => $g,
]);
$objectManager->get('\Magento\Catalog\Api\CategoryRepositoryInterface')->save($category);
}
createCategory("Abc");
?>