0

I'm trying to add a plugin for Magento\Catalog\Model\Product\Type\AbstractType.

I've got a 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">
    <type name="Magento\Catalog\Model\Product\Type\AbstractType">
        <plugin name="plugin_abstracttype" type="MyModules\Module1\Plugins\AbstractType"/>
    </type>
</config>

and corresponding MyModules\Module1\Plugins\AbstractType class:

namespace MyModules\Module1\Plugins;

use Magento\Quote\Model\Quote\Item;

class AbstractType
{
    protected $logger;

    public function __construct(\Psr\Log\LoggerInterface $logger)
    {
        die('constructor');
        $this->logger = $logger;
        $this->logger->warning("constructor called");
    }

    public function beforePrepareForCart(\Magento\Catalog\Model\Product\Type\AbstractType $abstractType, \Magento\Framework\DataObject $buyRequest, $product)
    {
        die('prepareForCart');
        $this->logger->warning("called prepareForCart");
        return [$buyRequest, $product];
    }

    public function beforeCheckProductConfiguration(\Magento\Catalog\Model\Product\Type\AbstractType $abstractType, $product, $buyRequest)
    {
        $this->logger->warning("called checkProductConfig");
        return [$product, $buyRequest];
    }
}

For some darn reason, none of the methods (not even the constructor) ever get called.

I have already:

  • bin/magento cache:flush
  • rm -rf generated/*
  • bin/magento setup:upgrade
  • bin/magento setup:di:compile

Unfortunately, none of these helped. Other plugins in this module work just fine.

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.