Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Attributes in Magento are represented by the model 'eav/entity_attribute'. The following code shows how to access them. Hope it's what you were looking for.</p> <pre><code>/* * Initialize Magento. This assumes that we're running the script from the root * directory of a magento installation. Obviously if you're writing an extension * you don't need this. */ require_once 'app/Mage.php'; Mage::app()-&gt;setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); Mage::getSingleton("core/session")-&gt;setUser(Mage::getModel("admin/user")-&gt;load(0)); umask(0); /* * Attributes are represented by the eav/entity_attribute model */ $model = Mage::getModel("eav/entity_attribute"); foreach($model-&gt;getCollection() as $attr){ //$attr is a Mage_Eav_Model_Entity_Attribute (see Mage_Eav_Model_Entity_Attribute_Abstract for //most of the action). //Replace with your attribute processing code echo "id={$attr-&gt;getId()}, code={$attr-&gt;getAttributeCode()},label={$attr-&gt;getFrontendLabel()}\n"; //Check to see if the attribute has options if($attr-&gt;usesSource()){ echo " attribute options"; //process the options. foreach($attr-&gt;getSource()-&gt;getAllOptions() as $option){ //Replace with your option processing code. $label = $option['label']; $value = $option['value']; //Normally label is a string and value is an int. However, //some options have sub options. In this case value is like //array( array('label'=&gt;'Label', 'value'=&gt;'...'), ...) if(is_array($value)){ $value = print_r($value, true); } echo " $label =&gt; $value\n"; } } } </code></pre> <p>Some other neat things you can do with attributes:</p> <pre><code>//Load an attribute by code/name Mage::getModel('eav/entity_attribute')-&gt;loadByCode('catalog_product', 'price'); //Get the attribute set for an attribute $setId = Mage::getModel('eav/entity_attribute')-&gt;loadByCode('catalog_product', 'price')-&gt;getAttributeSetId(); $set = Mage::getModel('eav/entity_attribute_set')-&gt;load($setId); </code></pre> <p>See app/code/core/Mage/Eav/Model/Entity/Attribute.php, app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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