0

I need to add new method to the core interface so I was checking all the Magento forums and came to know that this can be achieved via extension attributes as like in the post Magento 2 : Override core Interface and Model but my question is how can I add the arguments for that method in extension attributes. I need method as below

public function updateStatus($Id, $customStatus);

I am not sure whether I have drafted my question correctly but hope its understandable. Can anyone please give me a suggestion to achieve this?

Update: I have added new method in core module at vendor Magento\NegotiableQuote\Api\NegotiableQuoteManagementInterface, it is working but my question, how can I do that in my custom module.

interface NegotiableQuoteManagementInterface
{
    /**
     * Update custom column.
     *
     * @param int $Id
     * @param string $customStatus
     * @return bool
     */
    public function updateStatus($Id, $customStatus);
MagentoDev
  • 504
  • 8
  • 37
  • This is part of your solution, but I've asked for details about request (idea, logic) which you want to solve. And what is reason to add some logic to core Management object instead of create additional custom Management Object with your logic and your interface? – Victor Tihonchuk Jul 20 '22 at 14:45

2 Answers2

0

You cannot add method or argument to core interface. The original design of interface is that all class which implements interface has some number of methods with defined signature and when you receive object which implements some interface you can use those methods. Also you cannot control which from extension (core/3rd party) can use this interface.

The main reason of use Extension Attributes is extend entity with attributes for API.

Looks like you have a custom logic and better to implement own interface or just class and use it for modify (apply your own logic)

If you still think that trying to add some method to interface is single solution, please update your question with more details and I'm sure it's possible to find the better solution for.

Victor Tihonchuk
  • 3,488
  • 1
  • 6
  • 18
  • Thanks. I have updated my question. Can you pls give some more info on how can I achieve what am I looking for? – MagentoDev Jul 20 '22 at 14:39
0

As Victor suggested it is not possible to add method or argument to core interface. Also Magento 2 Preference does not allow us to override the interfaces.

So, if you want to write a custom function for some purpose you can override the implementation class of that interface using preference and can add your custom function in that class.

Review this link for more details. Thanks!

Rahul Barot
  • 1,122
  • 5
  • 17