Skip to content

Instantly share code, notes, and snippets.

@Luxato
Created February 10, 2021 14:53
Show Gist options
  • Save Luxato/8658667bfd193afa3ec1cf455d19e952 to your computer and use it in GitHub Desktop.
Save Luxato/8658667bfd193afa3ec1cf455d19e952 to your computer and use it in GitHub Desktop.
Magento 1 - How to add attribute to the attribute set
<?php
require_once 'app/Mage.php';
Mage::app();
$attributeSetName = 'Electric scooters'; // Name of the attribute set
//$groupName = 'Frontend';
$code = 'my_attribute_code';
try {
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$attributeSetId = $setup->getAttributeSetId('catalog_product', $attributeSetName);
$attributeGroupId = $setup->getAttributeGroupId('catalog_product', $attributeSetId, null);
$attributeId = $setup->getAttributeId('catalog_product', $code);
$setup->addAttributeToSet($entityTypeId = 'catalog_product', $attributeSetId, $attributeGroupId, $attributeId);
echo 'Added Attribute to SET ' . $attributeSetName . ' (' . $code . ')';
} catch (Exception $e) {
echo 'ERROR when added Attribute to SET ' . $attributeSetName . ' (' . $code . ')';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment