I want to add a field "slider" in /rest/V1/products/:sku

I created a custom module and in my di.xml i have added the following code

<?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\Model\Product" type="mymod\Catalog\Model\Product" />
    <preference for="mymod\Catalog\Api\Data\ProductInterface" type="mymod\Catalog\Model\Product" />
    <preference for="mymod\Catalog\Api\ProductRepositoryInterface" type="Magento\Catalog\Api\ProductRepositoryInterface" />
    <preference for="mymod\Catalog\Api\Data\ProductInterface" type="Magento\Catalog\Api\Data\ProductInterface" />   

And I have added a method to Api/Data/ProductInterface

const slider = 'slider';

    public function getSlider();

    public function setSlider($slider);

I have implemented the two methods in


namespace mymod\Catalog\Model;

class Product extends \Magento\Catalog\Model\Product implements \Augmentes\Catalog\Api\Data\ProductInterface
     * {@inheritdoc}
    public function getSlider()
        return "test";

     * Set slider value
     * @param string $slider
     * @return $this
    public function setSlider($slider)
        return $this->setData('slider', "");
    } }

I also extended the ProductRepositoryInterface
changed the routes in webapi.xml

Still the field not coming in response. Anyone please advise.


  • any clue how to solve this ? I've got the same problem – Gujarat Santana Oct 2 '17 at 9:00

methods to test your code.

first check which api is getting called, your or default magento by putting some die in middle of code.

if it is coming from default then check your di.xml

if it is from your code make sure you deleted all cache and run setup-upgrade and static-content:deploy as well.

Your Answer

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

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