Question

I am adding another type of related products. I am adding a new method to Magento\Catalog\Model\Product\Link class by way of di.xml preference. The method also does appear in the interceptor class.

However, when I follow the execution, this call is made: $this->_linkInstance = $productLink;

Where $productLink is returning type Magento\Catalog\Model\Product\Link\Proxy

When I look in this class at run time there is no reference to my method like there is for other relations:

public function useRelatedLinks() { return $this->_getSubject()->useRelatedLinks(); }

Was it helpful?

Solution

I fixed my issue above by extending the proxy class itself by including the following:

In di.xml add this preference:

<preference for="Magento\Catalog\Model\Product\Link\Proxy" type="SprintIntercom\RelatedDownloads\Model\Catalog\Product\Link\Proxy"/>

Then created a class in my custom module at Vendor\Module\Model\Catalog\Product\Link\Proxy.php

class Proxy extends \Magento\Catalog\Model\Product\Link\Proxy

And included the method:

/**
 * {@inheritdoc}
 */
public function useCustomLinks()
{
    return $this->_getSubject()->useCustomLinks();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top