2016-07-28 9 views
0

私は属性を作成し、それをすべての属性セットに割り当てています。 私が見つけたのは、すべての製品を一括更新するまでは、新しい属性がすべての製品に関連付けられていないということです。Magento 1:すべての製品に属性を割り当てる方法は?

このプロセスを自動化する方法はありますか?

私は属性を作成し、すべての属性に割り当てるには、次のコードを使用していますが

<?php 
$installer = $this; 
$installer->startSetup(); 

$attr = Mage::getResourceModel('catalog/eav_attribute')->loadByCode('catalog_product', 'new_boolean_attribute'); 
if (!$attr->getId()) 
{ 
    $attribute = $installer->addAttribute('catalog_product', 'new_boolean_attribute', array(
     'type'    => 'int', 
     'input'    => 'boolean', 
     'backend'   => '', 
     'frontend'   => '', 
     'label'    => 'Exclude from Product Rules', 
     'source'   => 'eav/entity_attribute_source_table', 
     'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
     'required'   => false, 
     'user_defined'  => true, 
     'unique'   => false, 
     'default'   => '0', 
    )); 
} 

$attributeGroupName = 'General'; 

$entityTypeId = $installer->getEntityTypeId('catalog_product'); 

$sets = Mage::getModel('eav/entity_attribute_set')->getResourceCollection(); 

foreach($sets as $set) 
{ 
    //Do for all attribute sets 
    $attributeSetId = $set->getData('attribute_set_id'); 
    $installer->addAttributeGroup($entityTypeId, $attributeSetId, $attributeGroupName, 3); 

    $attributeGroupId = $installer->getAttributeGroupId($entityTypeId, $attributeSetId, $attributeGroupName); 
    $attributeId = $installer->getAttributeId($entityTypeId, 'new_boolean_attribute'); 
    $installer->addAttributeToGroup($entityTypeId, $attributeSetId, $attributeGroupId, $attributeId, null); 
} 

$installer->endSetup(); 

答えて

0

を設定し、磁気の管理パネルから再インデックス化してみてください。

関連する問題