I am trying to get the Custom Product Attribute (uom). I want to get the Attribute value to display on the rest/V1/orders API call. m using this https://magento.stackexchange.com/a/303780/68018
app/code/{Vendorname}/{ModuleName}/etc
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Sales\Api\Data\OrderItemInterface">
<attribute code="uom" type="string" />
</extension_attributes>
</config>
namespace {VendorName}{ModuleName}\Plugin\ProductOption.php
<?php
namespace {VendorName}\{ModuleName}\Plugin;
use Magento\Sales\Api\Data\OrderItemInterface;
class ProductOption
{
/**
* @var \Magento\Sales\Api\Data\OrderItemExtensionFactory
*/
private $orderItemExtensionFactory;
public function __construct(
\Magento\Sales\Api\Data\OrderItemExtensionFactory $orderItemExtensionFactory
) {
$this->orderItemExtensionFactory = $orderItemExtensionFactory;
}
public function beforeAdd(
\Magento\Sales\Model\Order\ProductOption $subject,
OrderItemInterface $orderItem
) {
$extensionAttributes = $orderItem->getExtensionAttributes();
if(null=== $extensionAttributes){
$extensionAttributes= $this->orderItemExtensionFactory->create();
}
$extensionAttributes->setCustomField($order->getCustomField());
$orderItem->setExtensionAttributes($extensionAttributes);
}
}
app/code/{Vendorname}/{ModuleName}/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="/lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Api\Data\OrderItemInterface">
<plugin name="custom_attribute_uom" type="Devcrew\CustomAttribute\Plugin\ProductOption"/>
</type>
</config>