I have an array of attribute codes that I need to get the values:
$attributes = array( 'Category' => 'type', 'Manufacturer' => 'brand', 'Title' => 'meta_title', 'Description' => 'description', 'Product Link' => 'url_path', 'Price' => 'price', 'Product-image link' => 'image', 'SKU' => 'sku', 'Stock' => 'qty', 'Condition' => 'condition', 'Shipping cost' => 'delivery_cost');
After iterating through the product collection, I get the interface attribute values ββas follows:
$attributeId = Mage::getResourceModel('eav/entity_attribute') ->getIdByCode('catalog_product', $attribute_code); $attribute = Mage::getModel('catalog/resource_eav_attribute') ->load($attributeId); $value = $attribute->getFrontend()->getValue($product);
Just using $product->getDate($attribute) will not work with drop-down lists and multiple selections, it just returns their identifier and not its frontend value.
Although the above code works, it seems to be of great importance in getting the value, but more importantly, it works quite slowly. Is there a faster / smarter way to get interface values ββfor product attributes?
Edit
Now I have the following (after considering special cases such as image and qty ), which is slightly easier on the eyes and seems to work faster (although I donβt know why):
$inputType = $product->getResource() ->getAttribute($attribute_code) ->getFrontend() ->getInputType(); switch ($inputType) { case 'multiselect': case 'select': case 'dropdown': $value = $product->getAttributeText($attribute_code); if (is_array($value)) { $value = implode(', ', $value); } break; default: $value = $product->getData($attribute_code); break; } $attributesRow[] = $value;
If someone can improve this (make it simpler / more efficient), send a response.