In sales_order_grid table I have this custom field:
This field was added by this extension: https://github.com/boldcommerce/magento2-ordercomments
Is it possible to add it as "custom_attributes" in the orders API response, like this:
"custom_attributes": [
{
"attribute_code": "bold_order_comment",
"value": "test comment"
}
]
It's actually set as extension_attributes at the moment but I need it as custom_attributes.
1 Answer 1
Third-party developers cannot change the API Data interfaces defined in the Magento Core code. However, most of these entities have a feature called extension attributes. Check the interface for the methods getExtensionAttributes() and setExtensionAttributes() to determine if they are available for the entity.
We cannot alter the vendor/magento/module-sales/Api/Data/OrderInterface.php
so your order property was attached to the order as an extension attribute (https://github.com/boldcommerce/magento2-ordercomments/blob/master/etc/extension_attributes.xml), and this means you'll get the data only as a property of the 'extension_attributes' object by using the default Mageto API endpoints (unless you develop your own API method that will provide you the response in your preferred structure).
-
Thanks, but it should be possible to add "custom_attributes" to the order api, shouldn't it? Reference for e.g.: devdocs.magento.com/guides/v2.4/extension-dev-guide/… "custom_attributes": { "artist": "James Smith" } I've also seen "custom_attributes" on customer interface. So It should be possible on order interface ? Thankshardy123480– hardy1234802021年03月08日 17:59:50 +00:00Commented Mar 8, 2021 at 17:59
-
Ok, but the "custom_attributes" key is populated with the attributes installed by the user on an EAV entity. The order is not an EAV entity. The only way to extend the order data interface is by adding the extension attributes.Diana– Diana2021年03月09日 17:28:34 +00:00Commented Mar 9, 2021 at 17:28