0

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).

  • I cannot put my finger on it, but there ought to be a moment where you save() after setting the data. Try $quoteItem->save();? Edit: Nevermind, it's an observer, the data should be passed over by reference. – user3154108 Aug 4 '14 at 13:36
  • Yeah it should be passed over automatically (though, I did try to save it too, with no luck) – thebluefox Aug 4 '14 at 13:45
3

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

  • 1
    Seriously! Thanks R.S, little frustrating given how long I've just spent trying to error check working code!!! – thebluefox Aug 4 '14 at 14:20
  • Spend 3 hours trying to figure out why attributes wasn't getting saved into db. I deleted cache many times from backend, but once i deleted var/cache/* manually it started working :) – puntable Sep 19 '17 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.