Jul 12, 2013
kalpesh

Magento convert quote item to order item

If you have custom product attribute(s), then you may need to convert them to quote item and then to order item in Magento when an order is placed. That helps the order get the product attributes details and saves it in order tables to reference in the backend Manage Orders screen. This allows you to know what values for the product is selected by the customer, so that you can consider it when dispatching the order items.

This is a two way process where first the product attribute converts to quote item, and then quote item (with your product attribute’s value) converts to order item.

To do this you will have to put the below code in your module’s config.xml file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<global>
    <!--convert your custom product attribute "myattribute" from quote item to order item-->
    <fieldsets>
        <sales_convert_quote_item>
            <myattribute>
                <to_order_item>*</to_order_item>
            </myattribute>
        </sales_convert_quote_item>
    </fieldsets>

    <!--add your custom product attribute "myattribute" to quote item-->
    <sales>
        <quote>
            <item>
                <product_attributes>
                    <myattribute />
                </product_attributes>
            </item>
        </quote>
    </sales>

    <!--convert product attribute to quote item through event observer-->
    <events>
        <sales_quote_item_set_product>
            <observers>
                <mymodule>
                    <class>mymodule/observer</class>
                    <method>convertAttribute</method>
                </mymodule>
            </observers>
        </sales_quote_item_set_product>
    </events>
</global>


And in your Model/Observer.php

1
2
3
4
5
6
public function convertAttribute(Varien_Event_Observer $observer) {
    $item = $observer->getQuoteItem();
    $product = $observer->getProduct();
    $item->setMyattribute($product->getMyattribute());
    return $this;
}

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions