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
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)
Tag Cloud
500 internal server error admin answers attribute bug category checkbox checkout cookie customer difference domain name EAV error event extension interview invoice jquery linux magento magento2 magento admin magento error magento interview questions magento orm mysql observer order pinterest product products questions redirect register remove script session simplexml to array state status study guide tax url wordpress