2

I'm trying override getBreadcrumbPath() in Magento\Catalog\Helper\Data.

In di.xml

<type name="Magento\Catalog\Helper\Data">
    <plugin name="Helper" type="XXX\YYY\Plugin\Helper\Data" sortOrder="10"/>
</type>

In plugin

public function aroundGetBreadcrumbPath(\Magento\Catalog\Helper\Data $subject, callable $proceed)
{
echo "hi";exit;
}

But its not working

2 Answers 2

2

1.Create file di.xml inside Vendor/Module/etc

 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Helper\Data">
    <plugin name="catalog-helper-data" type="Vendor\Module\Plugin\Data" />
</type>

2.Create file Data.php inside Vendor/Module/Plugin

<?php
namespace Vendor\Module\Plugin;
class Data
{
public function aroundGetBreadcrumbPath(\Magento\Catalog\Helper\Data $subject, callable $proceed)
    {
        echo "hi";exit;  
    }
}
?>
0

An around plugin needs to always have a return value. The return value should be something like:

$result = $proceed(PARAMETERS FROM THE ORIGINAL FUNCTION);

You can look at the documentation here.

Not sure if there is more that you are missing.

Does your di.xml also start with the following?

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.