Magento provides the add product attribute set from the backend, but there is no way to add multiple attribute sets at once because, in the backend, we have to add one by one, so here I’m sharing the script for adding numerous sets at once.
Here is the script which is directly use from Magento root path:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
<?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/app/bootstrap.php'; $params = $_SERVER; $bootstrap = Bootstrap::create(BP, $params); $obj = $bootstrap->getObjectManager(); $state = $obj->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $resourceConnection = $objectManager->create('\Magento\Framework\App\ResourceConnection'); $attributeSet = $objectManager->create('\Magento\Eav\Model\Entity\Attribute\Set'); $entity_type = $objectManager->create('\Magento\Eav\Model\Entity\Type'); $productFactory = $objectManager->create('\Magento\Catalog\Model\ProductFactory'); $setsArray = array("Cup", "Size", "BandSize", "Color"); //You have to put here your require attribute sets if (!empty($setsArray)) { $sortOrder = 200; foreach ($setsArray as $checkSet) { $connection = $resourceConnection->getConnection(); $select = "SELECT * from eav_attribute_set WHERE attribute_set_name = '" . $checkSet . "'"; $result = $connection->fetchAll($select); if (count($result) == 0) { $entityType = $entity_type->loadByCode('catalog_product'); $defaultSetId = $productFactory->create()->getDefaultAttributeSetid(); $data = [ 'attribute_set_name' => $checkSet, 'entity_type_id' => $entityType->getId(), 'sort_order' => $sortOrder, ]; $attributeSet->setData($data); $attributeSet->validate(); $attributeSet->save(); $attributeSet->initFromSkeleton($defaultSetId); $attributeSet->save(); } $sortOrder++; } echo 'Attribute Sets Process Finished'; } |
First, prepare the above script in any PHP file of your Magento root then run that PHP file by CLI, and script execution will be started.
After finishing the file execution you can clean the Magento cache and see the result in the backend. All attribute sets will get successfully added.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-6287648078bf2203734148/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...