0

Having some difficulty implementing this answer: How to override or disable core Plugins in Magento2?

I have this vendor plugin I need to override the afterToHtml method...

Vendor DI entry:

<type name="Magento\Catalog\Block\Product\AbstractProduct">
    <plugin name="Amasty_Stockstatus::Addstatus" type="Amasty\Stockstatus\Plugin\Product\Status" />
</type>

Vendor plugin class:

namespace Amasty\Stockstatus\Plugin\Product;

class Status
{
    CODE

    public function afterToHtml(
    \Magento\Catalog\Block\Product\AbstractProduct $subject,
    $result
    ) {
        $name = $subject->getNameInLayout();

        if ( in_array($name, array('product.info.configurable', 'product.info.simple', 'product.info.type_schedule_block6', 'product.info.bundle',  'product.info.virtual',  'product.info.downloadble')) ) {
            $status = $this->_helper->getCustomStockStatusText($subject->getProduct());
            if ($status) {
                $tmp = $this->_helper->showStockStatus($subject->getProduct(), 1, 0);
                if ($tmp != '') {
                    $result  = $tmp;
                }
            }
        }

        return  $result;
    }
}

My DI entry:

<type name="Amasty\Stockstatus\Plugin\Product\Status">
    <plugin name="Amasty_Stockstatus::Addstatus" type="Vendor\ExtensionName\Plugin\Product\Status" sortOrder="1" />
</type>

My plugin class:

namespace Vendor\ExtensionName\Plugin\Product;

class Status extends \Amasty\Stockstatus\Plugin\Product\Status
{
    public function afterToHtml(
        \Magento\Catalog\Block\Product\AbstractProduct $subject,
        $result
    ) {
        NEW CODE
    }
}

My extension is already installed and I have a class override working for a Helper. We are in developer mode. I've also tried a few other variations such as these:

1.

<preference for="Amasty\Stockstatus\Plugin\Product\Status" type="Vendor\ExtensionName\Plugin\Product\Status"/>

2.

<type name="Magento\Catalog\Block\Product\AbstractProduct">
    <plugin name="Amasty_Stockstatus::Addstatus" disabled="true" />
</type>

3.

<type name="Magento\Catalog\Block\Product\AbstractProduct">

4.

<plugin name="Addstatus" type="Vendor\ExtensionName\Plugin\Product\Status" sortOrder="1" />

5.

<plugin name="Vendor_ExtensionName::Addstatus" type="Vendor\ExtensionName\Plugin\Product\Status" sortOrder="1" />

What am I missing?

  • Post the method code for ToHtml from Amasty\Stockstatus\Plugin\Product\Status – Keyur Shah Jan 17 '18 at 19:00
  • @KeyurShah I've added the code to the original request. – Joshua Fricke Jan 17 '18 at 20:12

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.