Created
April 14, 2018 22:47
-
-
Save keithgreer/bb9c6db921f3f14c68546bce6142073a to your computer and use it in GitHub Desktop.
Magento Code: Bulk add a new product attribute to all store attribute sets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'app/Mage.php'; | |
umask(0); | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
$attSet = Mage::getModel('eav/entity_type')->getCollection()->addFieldToFilter('entity_type_code','catalog_product')->getFirstItem(); | |
$attSetCollection = Mage::getModel('eav/entity_type')->load($attSet->getId())->getAttributeSetCollection(); | |
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection') | |
->setCodeFilter('**ATTRIBUTE CODE**') | |
->getFirstItem(); | |
$attCode = $attributeInfo->getAttributeCode(); | |
$attId = $attributeInfo->getId(); | |
foreach ($attSetCollection as $a) { | |
$set = Mage::getModel('eav/entity_attribute_set')->load($a->getId()); | |
$setId = $set->getId(); | |
$group = Mage::getModel('eav/entity_attribute_group')->getCollection()->addFieldToFilter('attribute_set_id',$setId)->addFieldToFilter('attribute_group_name', '**ATTRIBUTE GROUP NAME**')->setOrder('attribute_group_id',ASC)->getFirstItem(); | |
$groupId = $group->getId(); | |
$addAttribute = Mage::getModel('eav/entity_attribute'); | |
$addAttribute->setEntityTypeId($attSet->getId()) | |
->setAttributeSetId($setId) | |
->setAttributeGroupId($groupId) | |
->setAttributeId($attId) | |
->setSortOrder(**SORT ORDER**) | |
->save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment