Magento – How to Add Custom Value into Quote Item Table

configurationevent-observerquote

So I know that the subject of getting a custom product attribute into the a quote item has been covered many times, and I've had that working fine previously.

What I'm trying to achieve here though is to get a custom value (something out of the session) stored against a quote item. I've created the extra column in the 'sales_flat_quote_item' table (which is vrm_data). What I've got in terms of code is below;

config.xml excerpt;

<global>
    ......
    <events>
        <sales_quote_add_item>
            <observers>
                <vrmdatasave>
                    <class>vrmlookup/observer</class>
                    <method>saveVrm</method>
                </vrmdatasave>
            </observers>
        </sales_quote_add_item>
    </events>
    <fieldsets>
        <sales_convert_quote_item>
            <vrm_data>
                <to_order_item>*</to_order_item>
            </vrm_data>
        </sales_convert_quote_item>
        <sales_convert_order_item>
            <vrm_data>
                <to_quote_item>*</to_quote_item>
            </vrm_data>
        </sales_convert_order_item>
    </fieldsets> 
    <sales>
        <quote>
            <item>
                <product_attributes>
                    <vrm_data />
                </product_attributes>
            </item>
        </quote>
    </sales>
</global>

I'm not entirely sure that I need the sales>quote>item stuff as this isn't a product attribute I'm dealing with.

In my Observer.php;

public function saveVrm($observer)
{
    // Save the VRM data against the Quote
    $session = Mage::getSingleton('core/session');  
    $quoteItem = $observer->getQuoteItem();
    $quoteItem->setVrmData($session->getVehicleData());
}

I can see using debugging that the session var has the correct value, and then the $quoteItem has the correct value, but I'm never actually seeing it appear in the 'sales_flat_quote_item' table.

As usual with stuff like this, it could be something simple I'm doing/not doing….annoyingly this was working fine with the 'sales_flat_quote' table (albeit with a slightly different observer code, obviously).

Best Answer

Try Clearing Cache.

It doesn't matter whether the cache is enabled / disabled in Cache Storage Management, the table schema will be cached even though the new column is already added to the MySQL table.

See https://stackoverflow.com/questions/12205251/using-boolean-fields-with-magento-orm