0

In sales_order_grid table I have this custom field:

enter image description here

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.

asked Mar 8, 2021 at 10:34

1 Answer 1

0

As per https://devdocs.magento.com/guides/v2.4/extension-dev-guide/extension_attributes/adding-attributes.html:

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).

answered Mar 8, 2021 at 16:34
2
  • 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 ? Thanks Commented 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. Commented Mar 9, 2021 at 17:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.