Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tuanphpvn/405577400986a1cbef42 to your computer and use it in GitHub Desktop.
Save tuanphpvn/405577400986a1cbef42 to your computer and use it in GitHub Desktop.
Create list attribute set by Array #Magento #Attributeset
<?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