How do I get the object that my plugin is attached to from within an after
plugin? I thought it would be the $subject
parameter, but that doesn't seem to be it.
My plugin is defined like this
di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable">
<plugin name="MyCompany_Configurable" type="MyCompany\ConfigurableProduct\Plugin\Configurable" sortOrder="10" disabled="false"/>
</type>
</config>
Configurable.php
public function afterGetJsonConfig($subject, $result)
{
// ...
}
I assumed that $subject
should be an instance of Magento\ConfigurableProduct\Block\Product\View\Type\Configurable
, but when the plugin runs, $subject
is actually Magento\Swatches\Block\Product\Renderer\Configurable\Interceptor
.
The reason that this matters is because I want to call getAttributesForCollection
on the object that the plugin is attached to. However, if I call $subject.getAttributesForCollection(...)
it returns null. When getAttributesForCollection(...)
is called in the base class (Magento\ConfigurableProduct\Block\Product\View\Type\Configurable
), it returns an array.