Magento – Missing custom product attribute value in getData()

magento-1.8multiselect-attributeproduct-attribute

I have created a multiselect catalogue product attribute labelled dangerous (attribute ID: 1202) which should work exactly like an existing custom attribute sport (attribute ID: 1200).

The attribute is set up with the following options:

  • Scope: Global
  • Use In Layered Navigation: Filterable (with results)
  • Used in Product Listing: Yes

My new dangerous attribute shows up properly in the product edit form in a multiselect dropdown. When I select options and save the product I can see the database getting updated.

The only problem I have is that I can't seem to get the dangerous attribute value via the getData() method.

Mage::getModel('catalog/product')->load(494643)->getData() returns

Array (
    ...
    [supplier_warehouse] => United Kingdom
    [sport] => 4000
    [dangerous] =>
    [meta_keyword] => Nike Livestrong, Summer Cap (Black), Black, Headwear 
    ...
)

and both Mage::getModel('catalog/product')->load(494643)->getDangerous() and Mage::getModel('catalog/product')->load(494643)->getData('dangerous') return null.

On the other hand, this query:

SELECT
    cpe.entity_id AS product_id,
    cpev_sport.value AS sport,
    cpev_dangerous.value AS dangerous
FROM catalog_product_entity AS cpe

LEFT JOIN catalog_product_entity_varchar AS cpev_sport
ON cpev_sport.attribute_id = 1202
AND cpe.entity_id = cpev_sport.entity_id

LEFT JOIN catalog_product_entity_varchar AS cpev_dangerous
ON cpev_dangerous.attribute_id = 1200
AND cpe.entity_id = cpev_dangerous.entity_id

WHERE cpe.entity_id = 494643

returns

+------------+-------+-----------+
| product_id | sport | dangerous |
+------------+-------+-----------+
|     494643 | 4000  | 4087      |
+------------+-------+-----------+
1 row in set (0.00 sec)

Am I missing something obvious? Please note that I tried reindexing and clearing all types of cache, in vain so far.

EDIT: Additional info
I am using multi-store indeed but these attributes have a global scope (store ID: 0).
I have tried reindexing and clearing cache.

Best Answer

Try using $product->getDangerous() after flushing cache since often collections are cached.

Related Topic