I have two product custom attributes Package and Tint. I have assigned values to those attributes in my observer before add to cart in following way

   $item = $observer->getQuoteItem();
    // Ensure we have the parent item, if it has one
    $item = ( $item->getParentItem() ? $item->getParentItem() : $item );

    // Set the custom price


    $item->setPackage('Silver'); // these values are depends upon customers selection

    // Enable super mode on the product.


then I tried to get that values in my cart.phtml page using

   $item->getPackage(); it returns nothing

What is correct method to access attribute values in cart page. Also I want to show those attributes in order for admin and customer


The quote items are kept in the db.
Since there are not columns to support your package and tint attributes the values you set to the item are not persistent.

So setting

$item->setPackage('Silver'); // these values are depends upon customers selection

Makes these values available only in the current request.
When the page is realoaded, the quote items are retrieved from the db and they don't have package and tint.

You should add 2 more columns in the table sales_flat_quote_item that will hold these values.
Clear the cache when your are done.
To be able to access these values from the order items you need to do the same for the table sales_flat_order_item.
Add 2 columns and then tell magento that when it creates an order item from a quote item it should copy these fields also.

You can do this via the fieldsets from config.xml.

In one of your custom modules, inside the config.xml add this inside the <global> tag.

    <sales_convert_quote_item><!-- when converting a quote item -->
        <package> <!-- copy the package field ...-->
             <to_order_item>*</to_order_item> <!-- .. to the order item -->

Additional...if you want these values to be available on the invoice items, shipment items and creditmemo items, you need to add the same 2 columns in the tables sales_flat_invoice_item, sales_flat_shipment_item and sales_flat_creditmemo_item.

And inside the same <fieldsets> xml node as above add this:

| improve this answer | |
  • This doesn't seem to work for me..I have user input values and have created columns in quote_item table as well. How do I save it?using controller or observer? Also the fieldsets help me in converting quote item value to order item. But how do u save it in quote_item in the first place? – Twinkal Sep 30 '16 at 6:55

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.