4

I am trying to add a new getter and setter to \Magento\Catalog\Api\Data\CategoryTreeInterface.

I have created a new interface - \Wildcard\CategoriesApi\Api\Data\CategoryTreeInterfaceand a new model - \Wildcard\CategoriesApi\Model\Category.

When I call the /V1/categories endpoint the property is not shown.

However, if I directly add the getter and setter to the core interface, it works.

My di.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <preference for="Magento\Catalog\Api\Data\CategoryTreeInterface" type="Wildcard\CategoriesApi\Api\Data\CategoryTreeInterface"/>
    <preference for="Magento\Catalog\Model\Category" type="Wildcard\CategoriesApi\Model\Category"/>
    <preference for="Wildcard\CategoriesApi\Api\Data\CategoryTreeInterface" type="Wildcard\CategoriesApi\Model\Category"/>

</config>

PHPStorm does highligh the Wildcard\CategoriesApi\Api\Data\CategoryTreeInterface in the type parameter in the first preference as not being able to resolve. I have triple checked my namespacing and file/folder names but they are all correct.

Can someone please help with how to add my methods to the interface?

Using Magento 2.1.7

Wildcard27
  • 445
  • 8
  • 25
  • Nobody has an idea about this? – Wildcard27 Jul 17 '17 at 00:50
  • Answer for you question is here: https://magento.stackexchange.com/questions/213753/magento-2-override-core-interface-and-model – bakalov Apr 24 '19 at 08:30
  • @Wildcard27 I need to override same core interface and model file. Have you got any solution ? Please let me know. – Kirti Nariya Oct 18 '19 at 10:20
  • Overriding core interface and model classes is simply not possible in Magento 2. You must use the Extension Attributes functionality as explained in the other answer. If you absolutely must override the core classes you could use a Composer patch to change those files, but that is very error-prone and sensitive to issues when upgrading Magento version. – Jacques May 25 '23 at 09:10

0 Answers0