I need idea on how to create a script for adding bulk attribute sets and attributes in magento2?
This is the script i have tried:
AttributeSetupscript.php
<?php
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('AttributeSet');
$bootstrap->run($app);
AttributeSet.php
<?php
use \Magento\Framework\App\Bootstrap;
//include('../app/bootstrap.php');
use Magento\Catalog\Api\CategoryRepositoryInterface;
class AttributeSet extends \Magento\Framework\App\Http implements \Magento\Framework\AppInterface
{
protected $_moduleDataSetup;
protected $_eavSetupFactory;
public function __construct( //not sure if i can include construct here
ObjectManagerInterface $objectManager,
ModuleDataSetupInterface $moduleDataSetup,
EavSetupFactory $eavSetupFactory,
) {
$this->_objectManager = $objectManager;
$this->_moduleDataSetup = $moduleDataSetup;
$this->_eavSetupFactory = $eavSetupFactory;
}
public function launch()
{
$eavSetup = $this->_eavSetupFactory->create([
'setup' => $this->_moduleDataSetup
]);
$defaultId = $eavSetup->getDefaultAttributeSetId(self::ENTITY_TYPE);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
//$entityTypeId = $objectManager->create('\Magento\Catalog\Model\Product');
$entityTypeId = $objectManager->create('Magento\Eav\Model\Config')
->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)
->getEntityTypeId(); // to get entity_type_id by entity_type_code
$model = $objectManager->create('Magento\Eav\Api\Data\AttributeSetInterface')
->setId(null)
->setEntityTypeId(4)
->setAttributeSetName($name);
$objectManager->create('Magento\Eav\Api\AttributeSetManagementInterface')
->create(self::ENTITY_TYPE, $model, $defaultId)
->save();
}
public function catchException(\Magento\Framework\App\Bootstrap $bootstrap, \Exception $exception)
{
return false;
}
}
I get Call to a member function sendResponse() on null in \Magento\Framework\App\Bootstrap.php on line 25
1) Is what i tried i construct() in scripts.
2) Or should i run InstallData Schmeas procedure.