cancel
Showing results for 
Search instead for 
Did you mean: 

After plugin argument mismatch error

SOLVED

After plugin argument mismatch error

Hi ,

Working on Magento CE2.1

 

I have created after plugin for the public function of core class, Please find code below

etc/di.xml

...
<type name="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer">
        <plugin name="ricky-order-campaign-view-information" type="Ricky\AdminGiftOrderManager\Plugin\DefaultRendererAfter" sortOrder="10" />
</type>
...
Plugin\DefaultRendererAfter.php
<?php

namespace Ricky\AdminGiftOrderManager\Plugin;

use Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer;


class DefaultRendererAfter
{
    /**
     * @param \Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer $defaultRenderer
     * @param null $result
     * @param \Magento\Framework\DataObject|Item $item
     * @param string $column
     * @param null $field
     * @return string
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     */
    public function afterGetColumnHtml(DefaultRenderer $defaultRenderer, $result, \Magento\Framework\DataObject $item, $column, $field)
    {
        $result .= $item->getCampaignName();

        return $result;
    }
}
now after clearing cache and deleting var/generation dir I have compiled the code successfully using 
php bin/magento setup:di:compile
When I try to visit the page I am reciving the follwoing error in log
[Mon Sep 21 04:14:56.760564 2020] [:error] [pid 1155] [client 172.18.0.1:58648] PHP Fatal error:  Uncaught TypeError: Argument 3 passed to Ricky\\AdminGiftOrderManager\\Plugin\\DefaultRendererAfter::afterGetColumnHtml() must be an instance of Magento\\Framework\\DataObject, none given, called in /var/www/html/app_svr/sg/member/vendor/magento/framework/Interception/Interceptor.php on line 152 and defined in /var/www/html/app_svr/sg/member/app/code/Ricky/AdminGiftOrderManager/Plugin/DefaultRendererAfter.php:20\nStack trace:\n#0 /var/www/html/app_svr/sg/member/vendor/magento/framework/Interception/Interceptor.php(152): Ricky\\AdminGiftOrderManager\\Plugin\\DefaultRendererAfter->afterGetColumnHtml(Object(Magento\\Sales\\Block\\Adminhtml\\Order\\View\\Items\\Renderer\\DefaultRenderer\\Interceptor), '\\n    <div id="o...')\n#1 /var/www/html/app_svr/sg/member/var/generation/Magento/Sales/Block/Adminhtml/Order/View/Items/Renderer/DefaultRenderer/Interceptor.php(26): Magento\\Sales\\Block\\Adminhtml\\Order\\View\\Items\\Renderer\\DefaultRenderer\\Interceptor->___callPlugins('getColumnHtml', Array, Array)\n#2 /var/www/html/app_svr/sg/membe in /var/www/html/app_svr/sg/member/app/code/Ricky/AdminGiftOrderManager/Plugin/DefaultRendererAfter.php on line 20, referer: http://127.0.0.1:86/sg/member/admin_spi/sales/order/index/key/38bc90c2714e9b588d6417fd24400a55083c27521636ca1fdd440a0897d6186e/
~  
Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: After plugin argument mismatch error

Hello @Kapil_Thakur 

 

I tried the same thing and get error if I don't use $field as a optional parameter, but it fixed later when I passed it as optional.

 

If you still getting error, you can give a try with preference !

Hope it will help you to resolve your problem Smiley Happy

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

View solution in original post

2 REPLIES 2

Re: After plugin argument mismatch error

Hello @Kapil_Thakur 

 

In your after plugin afterGetColumnHtml , you are passing three arguments but the core class is passing two arguments and 1 argument is optional, please change your function like below :

public function afterGetColumnHtml(DefaultRenderer $defaultRenderer, $result, \Magento\Framework\DataObject $item, $column, $field =null)
    {
        $result .= $item->getCampaignName();

        return $result;
    }

function fun($optionalParam = null) is used if we want to use any parameter as optional.

 

Hope it helps !

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy

Re: After plugin argument mismatch error

Hello @Kapil_Thakur 

 

I tried the same thing and get error if I don't use $field as a optional parameter, but it fixed later when I passed it as optional.

 

If you still getting error, you can give a try with preference !

Hope it will help you to resolve your problem Smiley Happy

Problem Solved ? Click on 'Kudos' & Accept as Solution ! Smiley Happy