0

I have created an extension attribute for a product.

<extension_attributes for="Magento\Catalog\Api\Data\ProductInterface">
    <attribute code="product_options" type="Sample\Module\Api\Data\ProductOptionInterface" />
</extension_attributes>

So I am able to set product_options to the product.

But when I request using API

http://10.16.16.216/example/magento/rest/all/V1/products/mypsku

Then JSON response is no contained my extension attribute. product_options

My plugin

<type name="Magento\Catalog\Api\Data\ProductInterface">
    <plugin name="set_product_options" type="Sample\Module\Plugin\Catalog\ProductOption"/>
</type>

ProductOption

0

You need to use after plugin for Magento\Catalog\Api\Data\ProductInterface (afterGet and afterGetList function). For that use, di.xml and your custom plugin class for ProductInterface. Then in response of API, your custom extension attribute will be available.

2
  • afterGet method is not calling in my plugin. – Manish Goswami Jan 9 '20 at 12:42
  • Please paste code in your quesiton – Kishan Patadia Jan 9 '20 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.