So basically I want to extend the existing web-service /V1/orders/:id for adding new order field (say: erp_id).
It's a field in sales_order table and it's available when you load the $order object.
My main concern here is not to use the extension_attributes node for adding this new field. I want it to be on the same level as other standard fields.
The reason behind this is we already have many third parties relying on this structure.
So far gathered the key files for extension seems to be:
Magento\Sales\Api\OrderRepositoryInterface(service interface for the API)Magento\Sales\Api\Data\OrderInterface(data interface for the API result)Magento\Sales\Model\OrderRepository(concrete class for service interface)Magento\Sales\Model\Order(concret class for data interface - esp. getters and setters)
Some similar queries waiting for an answer:
== EDIT ==
If you edit as below, you can have the custom field on the top-level in the SOAP response.
File: app/code/Magento/Sales/Api/Data/OrderInterface.php
//...
/*
* ERP ID
*/
const ERP_ID = 'erp_id';
//...
/**
* Gets the ERP Id
*
* @return int
*/
public function getErpId();
/**
* Sets the ERP Id
*
* @param int $id
* @return $this
*/
public function setErpId($id);
File: app/code/Magento/Sales/Model/Order.php
/**
* {@inheritdoc}
*/
public function getErpId()
{
return $this->getData(OrderInterface::ERP_ID);
}
/**
* {@inheritdoc}
*/
public function setErpId($id)
{
return $this->setData(OrderInterface::ERP_ID, $id);
}
It's that simple logically. But the problem here is overriding the interface.
Another Question:
is this possible in Magento 2 <preference for="Magento\Sales\Api\Data\OrderInterface" type="My\Custom\Api\Data\OrderInterface" />
(i.e. overriding of one interface by another)