QuestionQ32

APIs and Services

An Adobe Commerce developer needs to add custom data to orders retrieved through the API.

While following best practices, how should the developer accomplish this?

  • A Create an extension attribute on Magento\Sales\Api\Data\OrderInterface and an after plugin on Magento\Sales\Model\Order::getExtensionAttributes() to add the custom data.
  • B Create an extension attribute on Magento\Sales\Api\Data\OrderInterface and an after plugin on Magento\Sales\Api\OrderRepositoryInterface on get() and getList() to add the custom data.
  • C Create a before plugin on Magento\Sales\Model\ResourceModel\Order\Collection::load and alter the query to fetch the additional data. Data will then be automatically added to the items fetched from the API.
Explanation

Extension attributes are the supported mechanism for adding data to Adobe Commerce API data interfaces. An after plugin on Magento\Sales\Api\OrderRepositoryInterface can populate the extension attribute on the order returned by get() and on every order in the search results returned by getList(), ensuring the custom data is included in both API retrieval paths. Adobe’s extension-attribute guidance recommends repository after plugins for get and getList responses.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!