Use this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php 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 =2, $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" ); createCategory( "Xyz" ,4,false, "description" , "m title" ); ?> |
Leave a Reply