I have added a custom product attribute via code, using InstallData.php
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
MagentoCatalogModelProduct::ENTITY,
'hts_code',
[
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'HTS Code',
'input' => 'text',
'class' => '',
'source' => '',
'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => ''
]
);
}
This attribute shows in the product details page and can be set no issue. It appears in the API when fetching the product.
However, I need to add this attribute to the Order API response (http://store.test/index.php/rest/V1/orders/) but cannot figure this out at all.
I have looked up multiple examples but none of the implementations work.
So how do I go about adding this custom attribute to the Order API response, and ideally, I need to add it to the shipping_assignments.items section of the Order extension attributes