How to Convert Custom Field From Quote Item to Order Item in Magento 2
- Step 1: Add a di.xml file
- Step 2: Identify a code, a plugin
- Step 3: Add a class to your module, then identify a function
Step 1: Add a di.xml file
In the module app/code/Tony/HelloWorld/etc, please add the di.xml file.
Step 2: Identify a code, a plugin
<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"><type name="Magento\Quote\Model\Quote\Item\ToOrderItem"><plugin name="TonyHelloworld_to_order_item" type="Tony\Helloworld\Model\Plugin\Quote\TonyHelloworldToOrderItem"/></type></config>
Then, identify a plugin Tony\HelloWorld\Model\Plugin\Quote\TonyHelloworldToOrderItem of class Magento\Quote\Model\Quote\Item\ToOrderItem
Step 3: Add a class to your module, then identify a function
<?php/*** Tony** Author : Tony Liu* Blog: https://www.tonyblog.cn** DISCLAIMER** Do not edit or add to this file if you wish to upgrade this extension to newer* version in the future.** @package Tony_Helloworld*/namespace Tony\Helloworld\Model\Plugin\Quote;class TonyHelloworldToOrderItem{public function aroundConvert(\Magento\Quote\Model\Quote\Item\ToOrderItem $subject,\Closure $proceed,\Magento\Quote\Model\Quote\Item\AbstractItem $item,$additional = []) {/** @var $orderItem Item */$orderItem = $proceed($item, $additional);$orderItem->setNotes($item->getNotes());return $orderItem;}}
Finally, the result of fuction as follow :
If you want to know more information, please contact me.
- 1 Magento ver. 2.2.0-dev - A technical prob... 16579
- 2 ECS git pull 代码很慢的问题 14713
- 3 玩客云监工客户端 13205
- 4 Magento 2 UI Form Validation 13122
- 5 Codeigniter SSL 强制重定向至https访问 13006
- 6 magento2 完整卸载模块的正确姿势 12640
- 7 Magento fix 500 12280
- 8 Magento index is locked by another reinde... 10739
- 9 Ubuntu删除日志文件 9012
- 10 Magento 2安装ElasticSearch 6.x搜索引擎-Ub... 8622


