1

I want to override a method from a Ui component which sets filter values. My Plugin code

<?php 

namespace MyVendor\MyModule\Plugins\DataProvider\Product;

class GiftProvider
{
    public function aroundAddFilter(
          $subject,  
          \Closure  $proceed, 
          \Magento\Framework\Api\Filter $filter
    )
    {
        if (isset($subject->addFilterStrategies[$filter->getField()])) {
            $subject->addFilterStrategies[$filter->getField()]
            ->addFilter(
                    $subject->getCollection(),
                    $filter->getField(),
                    [$filter->getConditionType() => $filter->getValue()]
            );
        } else {
            $abstractProvider::addFilter($filter);
        }

        if(!isset($subject->addFilterStrategies['is_gift']))
        {
            $subject->addFilterStrategies['is_gift']
                ->addFilter(
                    $subject->getCollection(),
                    'is_gift',
                    [$filter->getConditionType() => 1]);
        }
        return $subject;
    }

}

etc/adminhtml/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
        <plugin name="gift_data_provider_around_plugin" type="MyVendor\MyModule\Plugins\DataProvider\Product\GiftProvider" sortOrder="1500" />
    </type>
</config>

Ajax returns

Fatal 500 Internal Server Error

And a message is outputted saying :

"Attention
Something went wrong."

What did go wrong is that the response of the ajax is empty when I inspect it.

Where is my mistake, Is this possible ?

1 Answer 1

1

parameters in aroundAddFilter of plugin must have like this

public function aroundAddFilter(
   \Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider $subject,  
   \Closure $proceed, 
   \Magento\Framework\Api\Filter $filter,
   \Magento\Ui\DataProvider\AbstractDataProvider $abstractProvider
)
{
  //body code
  return $proceed($abstractProvider);
}

Hope this will help you

7
  • nope, didn't work, same thing.... Commented Feb 28, 2016 at 17:08
  • re-check your controllers , blocks . It maybe some errors vars or miss something. Try remove last parameter in function aroundAddFilter and return only proceed Could you find anything in var/log/exception? It may helpfuls for debug
    – mrtuvn
    Commented Feb 28, 2016 at 17:28
  • in magento_root/var/log/ dorectory I have only debug.log system.log , no exception, I checked the apache2 error log though... and we have winner: "Cannot access protected property Magento\\Catalog\\Ui\\DataProvider\\Product\\ProductDataProvider\\Interceptor::$addFilterStrategies" Commented Feb 28, 2016 at 18:05
  • that sucks... I have to rewrite the whole class now ? Commented Feb 28, 2016 at 18:10
  • nvm dude, 10x for the help i will modify the question and mark your answer as correct. thank you one more time! I just used $filter setters to set the values I needed and called $proceed($filter) and it worked perfectly :) Commented Feb 28, 2016 at 18:16

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.