I'm trying to add an extension attribute to sales_order
(\Magento\Sales\Api\Data\OrderInterface
), and I have the following extension_attributes.xml
:
<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\OrderInterface">
<attribute code="order_status" type="string">
<resources>
<resource ref="anonymous"/>
</resources>
<join reference_table="aytech_order_approval" reference_field="order_id" join_on_field="entity_id">
<field>order_status</field>
</join>
</attribute>
</extension_attributes>
</config>
I have already created the table aytech_order_approval
with the fields order_id
and order_status
, and in my code I am trying to test getting the attribute like this (I have manually inserted a row into the table with order_id
= 1 and order_status
= 'approved':
$orders = $this->orderRepository->getList(\Magento\Framework\App\ObjectManager::getInstance()->create('Magento\Framework\Api\SearchCriteriaInterface'))->getItems();
echo $orders[1]->getExtensionAttributes()->getOrderStatus();
However, I keep getting null. What am I doing wrong? Also I've made sure to clear the var/generation
, and the generated class does indeed have the getOrderStatus
method