Magento 1: How to assign an attribute to all products? -
i creating attribute , assigning attribute sets. have found new attribute not associated products until mass update on products.
is there way automate process?
i using following code create attribute , assign attribute sets
<?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 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 $set) { //do 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();
try re-indexing magneto admin panel.
Comments
Post a Comment