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"/>


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.