Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have found it interesting to write code for this issue so here is the solution that works :)</p> <p>Run this code in php script including mage.php and let me know if it works well.</p> <blockquote> <p>replace ( firstname ) with the attribute code that you want to mass add to all attribute sets </p> </blockquote> <pre><code> $attSet = Mage::getModel('eav/entity_type')-&gt;getCollection()-&gt;addFieldToFilter('entity_type_code','catalog_product')-&gt;getFirstItem(); // This is because the you adding the attribute to catalog_products entity ( there is different entities in magento ex : catalog_category, order,invoice... etc ) $attSetCollection = Mage::getModel('eav/entity_type')-&gt;load($attSet-&gt;getId())-&gt;getAttributeSetCollection(); // this is the attribute sets associated with this entity $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection') -&gt;setCodeFilter('firstname') -&gt;getFirstItem(); $attCode = $attributeInfo-&gt;getAttributeCode(); $attId = $attributeInfo-&gt;getId(); foreach ($attSetCollection as $a) { $set = Mage::getModel('eav/entity_attribute_set')-&gt;load($a-&gt;getId()); $setId = $set-&gt;getId(); $group = Mage::getModel('eav/entity_attribute_group')-&gt;getCollection()-&gt;addFieldToFilter('attribute_set_id',$setId)-&gt;setOrder('attribute_group_id',"ASC")-&gt;getFirstItem(); $groupId = $group-&gt;getId(); $newItem = Mage::getModel('eav/entity_attribute'); $newItem-&gt;setEntityTypeId($attSet-&gt;getId()) // catalog_product eav_entity_type id ( usually 10 ) -&gt;setAttributeSetId($setId) // Attribute Set ID -&gt;setAttributeGroupId($groupId) // Attribute Group ID ( usually general or whatever based on the query i automate to get the first attribute group in each attribute set ) -&gt;setAttributeId($attId) // Attribute ID that need to be added manually -&gt;setSortOrder(10) // Sort Order for the attribute in the tab form edit -&gt;save() ; echo "Attribute ".$attCode." Added to Attribute Set ".$set-&gt;getAttributeSetName()." in Attribute Group ".$group-&gt;getAttributeGroupName()."&lt;br&gt;\n"; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload