i am trying to override model and interface of core api in to my custom module for adding new data but i am not able to override interface to add that data contract.
-
Can you write more with code?– Sohel RanaCommented Apr 1, 2017 at 15:04
-
Can you please provide the solution that worked for you.!!– Mahi MCommented Jul 19, 2018 at 12:57
-
@nikunj Could you please help me on this question. magento.stackexchange.com/questions/293336/…– Kirti NariyaCommented Oct 31, 2019 at 5:28
Add a comment
|
1 Answer
Classes in PHP can implement many interfaces at once. Your best bet is to write your own interface which adds the methods you require, then implement the models you want to implement the interfaces you need.
The interface
interface MyCustomManagementInterface
{
public myMethod();
}
The Class
class MyCustomClass implements \Magento\Framework\Some\Interface,
MyCustomManagementInterface
{
}
-
How can I override core Interface and Mode. Please let me know ? Magento\Catalog\Api\Data\ProductCustomOptionValuesInterface.php Magento\Catalog\Model\Product\Option\Value.php Commented Oct 18, 2019 at 10:28
-
You can't override an interface. The best you can do is create an interface that inherits from the core interface and then use preferences in di.xml to provide your custom class that extends the core class and implements your custom interface.– BrettCommented Oct 18, 2019 at 10:38
-
Thank you. Please below path have preference and i have to add custom code in intarface and model as well magento2/vendor/magento/module-catalog/etc/di.xml <preference for="Magento\Catalog\Api\Data\ProductCustomOptionValuesInterface" type="Magento\Catalog\Model\Product\Option\Value" /> Give me example for di.xml file Commented Oct 18, 2019 at 10:54
-
Could you please help me on this question. magento.stackexchange.com/questions/293336/… Commented Oct 31, 2019 at 5:26