Here are the steps that you will follow in this How to copy custom data from quote item to order item:

  1. Create a “di.xml” file into etc folder
  2. Defind a code, a plugin
  3. Create a class to THE module and defind a function

In Magento 2, you cannot use field set to copy a custom data from quote item to order item so you must some tricks to do it.

In this post, I will show you how to use a plugin to do it.

How to copy custom data from quote item to order item in Magento 2

  • Firstly, I create a “di.xml” file into etc folder of my module “app/code/Magestore/TipAndTrick/etc”.
  • I defind a code below into this file

  • In this code, I defind a plugin Magestore\TipAndTrick\Model\Plugin\Quote\TipAndTrickToOrderItem” of class Magento\Quote\Model\Quote\Item\ToOrderItem
  • Then I create a class “Magestore\TipAndTrick\Model\Plugin\Quote\TipAndTrickToOrderItem” in to my module and defind a function “aroundConvertwhich will copy a custom data from quote item to order item.

  • In first line of this function “$orderItem = $proceed($item, $additional);”, this is the result of function “convert” in class “Magento\Quote\Model\Quote\Item\ToOrderItem”.
  • Then in second line, I set the value for “TipAndTrickCustomDatafor the result of function convert class “Magento\Quote\Model\Quote\Item\ToOrderItem”.
  • Then I return an object $orderItem” which will replace result of function “convert” in class “Magento\Quote\Model\Quote\Item\ToOrderItem”.
  • That’s this. Follow each of the information above and you will complete How to copy custom data from quote item to order item.Expect my post can be helpful. When you have virtually any problem throughout copy custom data from quote item to order item in magento 2, let it rest in the opinion segment, I am going to answer as soon as i‘m able to.

Thank you!


Ready to foster your knowledge

with MAGENTO 2 BASIC GUIDE

Is your site still a mess and Magento extensions are not enough to save your site? Save your site with Magento Web Development Services now

magento services


How to Get Stock Items List in Magento 2

Leave a Reply

Your email address will not be published. Required fields are marked *