1

I want to extend some core function via the plugin and it should work in only when function call via REST API so in short my override things are only for REST API scope not for the web.

is this possible in Magento 2 and how can I write a plugin using di.xml which only call when request form API

Any idea? any help appreciate

2

You need to create plugin in di.xml inside etc/webapi_rest folder to call plugin only in REST API.

Example :

app/code/Vendor/Module/etc/webrest_api/di.xml :

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Api\ProductCustomOptionRepositoryInterface">
        <plugin name="updateProductCustomOptionsAttributes" type="Magento\Catalog\Plugin\Model\Product\Option\UpdateProductCustomOptionsAttributes"/>
    </type>
</config>

Add your plugin based on your requirement in di.xml.

| improve this answer | |
-1

It should be app/code/Vendor/Module/etc/webapi_rest/di.xml

| improve this answer | |

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.