I'm a beginner with Magento 2 and am having some issues with plugins - I've successfully done a plugin to change a simple object get statement (after event) - and in this case after compiling my code I've seen the generated files inside the var/generation folder.
However, when trying to tap in to the ProductRepository
getList
method, I'm having some issues - it's not doing anything.
Is there a log I can check after compilation to try to find out what the issue is?
I've tried before, around, after - different settings, but can't get it to work. Am I missing something?
I just need to add final price to the product collection. The example below obviously won't do this, but it doesn't even get compiled.
Can someone hint as to how to achieve this? Perhaps by using 'aroundGetList' - and show me which parameters would work?
Plugin class:
<?php
namespace MyCo\MyExt\Plugin;
class ProductOverride {
public function afterGetList($subject) {
$subject->addFinalPrice();
}
di.xml
file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\ProductRepository">
<plugin name="MyListener" type="MyCo\MyExt\Plugin\ProductOverride" sortOrder="1" />
</type>
</config>
The method I want to plug in to has this signature:
/**
* Get product list
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Magento\Catalog\Api\Data\ProductSearchResultsInterface
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
}
The method already appears to have a generated interceptor file also... is it wise to do it this way if i just want to call $collection->addFinalPrice();?
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getList');
if (!$pluginInfo) {
return parent::getList($searchCriteria);
} else {
return $this->___callPlugins('getList', func_get_args(), $pluginInfo);
}
}