0

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.

3

1 Answer 1

0

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
{
}
4
  • 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 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.
    – Brett
    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 Oct 18, 2019 at 10:54
  • Could you please help me on this question. magento.stackexchange.com/questions/293336/… Oct 31, 2019 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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