Last active
August 4, 2016 00:52
-
-
Save tuanphpvn/405577400986a1cbef42 to your computer and use it in GitHub Desktop.
Create list attribute set by Array #Magento #Attributeset
This file contains hidden or 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 | |
$createAttributeSet = function($arrAttributeSetName) { | |
$entityTypeId = Mage::getModel('catalog/product')->getResource()->getTypeId(); | |
$attributeSetDefault = Mage::getModel('eav/entity_attribute_set')->getCollection() | |
->addFieldToFilter('attribute_set_name', 'Default') | |
->addFieldToFilter('entity_type_id', $entityTypeId) | |
->setPageSize(1)->getFirstItem(); | |
if(empty($arrAttributeSetName)) return; | |
foreach($arrAttributeSetName as $attSetName) { | |
$arrAttrName = Mage::getModel('eav/entity_attribute_set')->getCollection() | |
->addFieldToFilter('attribute_set_name', $attSetName) | |
->addFieldToFilter('entity_type_id', $entityTypeId) | |
->getFirstItem() | |
; | |
if($arrAttrName){ | |
$_attributeSet = Mage::getModel('eav/entity_attribute_set')->load($arrAttrName->getId()); | |
$_attributeSet->initFromSkeleton($attributeSetDefault->getId()); | |
$_attributeSet->save(); | |
continue; | |
} | |
$model = Mage::getModel('eav/entity_attribute_set')->setEntityTypeId($entityTypeId); | |
$model->setAttributeSetName($attSetName); | |
$model->validate(); | |
$model->save(); | |
$model->initFromSkeleton($attributeSetDefault->getId()); | |
$model->save(); | |
} | |
}; | |
$arrAttributeSetName = array( | |
'Clothing', | |
'Accessories', | |
'Shoes', | |
'Home & Decor', | |
'Electronics', | |
'Books & Music', | |
); | |
$createAttributeSet($arrAttributeSetName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment