您的位置:首页 > 其它

Magento1.9 add attribute to catalog product & assign to all attribute set general group

2017-05-25 17:13 309 查看
$installer = $this;

$attributes = array(
'region'      =>   array(
'type'   => 'int',
'input' => 'select',
'source_model'       => 'evebit_catalog/entity_attribute_source_region',
'frontend_label' => 'Region',
'is_global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'frontend_input' => 'select',
'backend_type' => 'int',
'used_in_product_listing' => true,
'is_visible_on_front' => true,
'is_required' => false,
'is_user_defined' => true,
'searchable' => true,
'filterable' => true,
'comparable' => false,
'visible_in_advanced_search'=>true,
'position' => 15,
'is_unique' => false,
)
);

$productEntityId = $installer->getEntityTypeId(Mage_Catalog_Model_Product::ENTITY);
$allAttributeSetIds = $installer->getAllAttributeSetIds($productEntityId);

foreach($attributes as $attributeCode=>$attribute)
{
$attributeModel =   Mage::getModel('catalog/resource_eav_attribute');
$attributeModel->addData($attribute);
$attributeModel->setAttributeCode($attributeCode);
$attributeModel->setEntityTypeId($productEntityId);

try
{
$attributeModel->save();

}catch (Mage_Core_Exception $e)
{
Mage::logException($e);
}

try
{
foreach ($allAttributeSetIds as $attributeSetId){

$generalAttributeGroup = $installer->getAttributeGroupId($productEntityId,$attributeSetId,'General');
$attributeModel->setAttributeSetId($attributeSetId);
$attributeModel->setAttributeGroupId($generalAttributeGroup);
$attributeModel->save();
}

}catch (Mage_Core_Exception $e)
{
Mage::logException($e);
}
}

$installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'country_of_manufacture', 'frontend_label', 'Country');

$installer->endSetup();


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: