Skip to main content
5 of 5
added 10 characters in body
Maurice
  • 313
  • 1
  • 3
  • 12

Why is my product's custom attribute not available during this event?

I have a product with a custom attribute, which works fine almost everywhere I use it.

However, when I try to get this attribute's value during the catalog_product_get_final_price event, I get null returned. Also, when I print the product's data, this attribute is not shown.

Is there a logical reason for this? How can I retrieve the value of this attribute?


I suspect that because this event is fired during the create/update of a quote item, not the original product data is used, but a (partial) snapshot of it's data. If that is the case; how might I make my attribute available in this snapshot as well?


config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <My_Module>
            <version>1.0.0</version>
        </My_Module>
    </modules>
    <global>
        <events>
            <catalog_product_get_final_price>
                <observers>
                    <my_observer>
                        <class>My_Module_Model_Observer</class>
                        <method>calculateItemPrice</method>
                    </my_observer>
                </observers>
            </catalog_product_get_final_price>
        </events>
    </global>
</config>

Observer

<?php
class My_Module_Model_Observer
{
    /**
     * 
     * @param  Varien_Event_Observer $observer
     * @return void
     */
    public function calculateItemPrice( Varien_Event_Observer $observer )
    {
        $event   = $observer->getEvent();
        $product = $event->getProduct();
        
        // folowing returns NULL
        $product->getMyCustromAttribute()
    }
}

UPDATE

When I debug the $observer object in the event observer, I get the following data;

Varien_Event_Observer (
    [_data:protected] => Array
        (
            [event] => Varien_Event(...)
            [product] => Mage_Catalog_Model_Product(...)
            [qty] => 1
        )
    [_hasDataChanges:protected] => TRUE
    [_origData:protected] => NULL
    [_idFieldName:protected] => NULL
    [_underscoreCache:static:protected] => Array(...)
    [_isDeleted:protected] => FALSE
    [_oldFieldsMap:protected] => Array()
    [_syncFieldsMap:protected] => Array()
)
Maurice
  • 313
  • 1
  • 3
  • 12