How to Convert Custom Field From Quote Item to Order Item in Magento 2

Hello Magento peeps! 💻

I am back with another technical solution to help you convert custom field from quote item to order item in Magento 2.

The quote item table in Magento 2 represents the shopping cart and stores all the information about the product, quantity, prices, etc. On the successful placement of the order, all the fields from the quote item are converted to the order item table by default in Magento 2.

However, the custom fields in the quote item are not passed to the order object. This blog post is the solution to convert a custom field in Magento 2 quote item to order item. This is helpful when you have created custom columns in the quote item table and want to convert them into order items in Magento 2.

Let’s see how you can convert custom fields in the quote to order programmatically in Magento 2.

Steps to Programmatically Convert Custom Field From Quote Item to Order Item in Magento 2

In case you have a custom field in the quote item table and want to pass that to the order item table in Magento 2, you can follow the simple and easy steps mentioned below.

Step 1: Create a di.xml file at the app/code/Vendor/Extension/etc/ directory and add the following code:

Step 2: Create ConvertToOrderItem.php file at the app/code/Vendor/Extension/Plugin/Quote directory with the following code:

That’s it!

This is how easily you can pass the custom field from the quote item to the order item table in Magento 2. 😃

Have any doubts? Feel free to comment. I will be happy to help you. 😇

Also, do not forget to share this solution with your developer friends via social media.

Thanks for reading. 🍀

5
(based on 7 Reviews)
How to Convert Custom Field From Quote Item to Order Item in Magento 2Author Magento Badge

Jignesh Parmar

An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.

Leave a Reply

Your email address will not be published.