I create plugin in my custom module to override the method collectCarrierRates($carrierCode, $request), below code is not working. What mistake here?


<?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\Shipping\Model\Shipping">
        <plugin name="vendor-shippingtest-test"



namespace Vendor\Shippingtest\Plugin;

class Test
    public function after(Magento\Shipping\Model\Shipping $subject, $result)
        echo "Calling";

1 Answer 1


I'm not entirely sure what you're trying to achieve but there's a major problem in your method name, it does not contain the name of the original method.

You should replace:

public function after(Magento\Shipping\Model\Shipping $subject, $result)


public function afterCollectCarrierRates(Magento\Shipping\Model\Shipping $subject, $result)

So your plugin can work.

  • Hello Raphael,thanks to reply. I try to use your code, but same here plugin is not working. Commented Sep 5, 2016 at 10:27
  • @PayalPatel I'm not sure an echo would be enough to show your the code is working. Try to log data by using the following method magento.stackexchange.com/questions/92434/… Commented Sep 5, 2016 at 10:30
  • Try to log data but log file is not create in var/log folder. Commented Sep 5, 2016 at 10:36
  • @PayalPatel How are you testing your module ? Are you sure you follow a testing procedure that triggers the original collectCarrierRates method ? Commented Sep 5, 2016 at 10:38
  • 1
    @PayalPatel maybe try to move your di.xml outside the frontend folder Commented Sep 5, 2016 at 10:47

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.