I need to add extension attributes for core api endpoint -> https://magento.redoc.ly/2.4.5-admin/tag/ordersidcomments#operation/PostV1OrdersIdComments
Created below before plugin
<type name="MagentoSalesModelServiceOrderService">
<plugin name="set_order_data_plugin" type="NamespaceModuleNamePluginModelOrderSetOrderDataPlugin"
sortOrder="1"/>
</type>
Created extension_attributes.xml file also
<extension_attributes for="MagentoSalesModelServiceOrderService">
<attribute code="custom_id" type="string" />
</extension_attributes>
While calling api in postman -> /rest/V1/orders/2/comments
Getting below error
"message": "Property "CustomId" does not have accessor method "getCustomId" in class "Magento\Sales\Api\Data\OrderStatusHistoryExtensionInterface"."
Getter and Setter are not setting up. Please help me out here.
2
Answers
You need to optimize your code or share your whole module repo. However, the error is pretty that you didn’t create the setter and getter method of custom_id in the interface OrderStatusHistoryExtensionInterface and need to implement it in the class implementing the interface.
Magento ExtensionInterfaces is required to have all the methods that are declared in the extension_attributes.xml.
please create a setter and method in your custom interface like:
The default interface in Magento 2 is: OrderStatusHistoryInterface.php check the link: https://github.com/pepe1518/magento2/blob/master/vendor/magento/module-sales/Api/Data/OrderStatusHistoryInterface.php
Follow and check the full documentation of Sales Order History:
https://www.magentoextensions.org/documentation/interface_magento_1_1_sales_1_1_api_1_1_data_1_1_order_status_history_interface.html
appcodeVendorExtensionSetupInstallData.php