Home Communication board WiKi Get Quote

How to receive an attribute id by the attribute name

You can use the following code to receive attribute values:

        $attributes = Mage::getResourceModel('eav/entity_attribute_collection')
            ->addFieldToFilter('attribute_code', $option)
            ->load(false);
        $attribute = $attributes->getFirstItem();
        $atts = $attribute->getSource()->getAllOptions(false);
        $result = array();
        foreach($atts as $tmp)
            $result[$tmp['label']] = $tmp['value'];
        return $result;

As a result, you will receive a short array with attributes, and it's much easier to work with arrays in most of cases.

For the “$option” variable you can set up any attribute name. For example it can be 'manufacturer', 'color', 'size' or any other attribute code you have created.

 
Home About us Privacy statement Terms & Conditions Refund policy © 2007–2024 ArsCommunity