0

I built my own custom admin grid. It renders the data correctly, however when I tried to filter on an input, I am receiving the following error from the ajax request:

Status code 500

Error:

TypeError: Magento\Sales\Plugin\Model\ResourceModel\Order\OrderGridCollectionFilter::aroundAddFieldToFilter(): 
Argument #1 ($subject) must be of type Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult, Vendor\ModuleName\Model\ResourceModel\MoodleLogs\Grid\Collection\Interceptor given, 
called in /var/www/html/vendor/magento/framework/Interception/Interceptor.php on line 135 and defined in /var/www/html/vendor/magento/module-sales/Plugin/Model/ResourceModel/Order/OrderGridCollectionFilter.php:41

Interesting part is that I don't have any dependencies from the Magento Sales module. This is my di.xml part:

<virtualType name="Vendor\ModuleName\Model\ResourceModel\MoodleLogs\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
    <arguments>
        <argument name="mainTable" xsi:type="string">moodle_logs</argument>
        <argument name="resourceModel" xsi:type="string">Vendor\ModuleName\Model\ResourceModel\MoodleLogs</argument>
        <argument name="eventPrefix" xsi:type="string">vendor_modulename_logs_grid_collection</argument>
        <argument name="eventObject" xsi:type="string">vendor_logs_grid_collection</argument>
    </arguments>
</virtualType>
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
    <arguments>
        <argument name="collections" xsi:type="array">
            <item name="vendor_modulename_moodle_logs_grid_data" xsi:type="string">Vendor\ModuleName\Model\ResourceModel\MoodleLogs\Grid\Collection</item>
        </argument>
    </arguments>
</type>

and this is part of my UI component:

<dataSource name="bookingsystem_bookings_list_data_source">
    <argument name="dataProvider" xsi:type="configurableObject">
        <argument name="class" xsi:type="string">Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider</argument>
        <argument name="name" xsi:type="string">vendor_modulename_moodle_logs_grid_data</argument>
        <argument name="primaryFieldName" xsi:type="string">entity_id</argument>
        <argument name="requestFieldName" xsi:type="string">id</argument>
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="update_url" xsi:type="url" path="mui/index/render"/>
                <item name="storageConfig" xsi:type="array">
                    <item name="indexField" xsi:type="string">entity_id</item>
                </item>
            </item>
        </argument>
    </argument>
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
        </item>
    </argument>
</dataSource>

<listingToolbar name="listing_top">
    <settings>
        <sticky>true</sticky>
    </settings>
    <columnsControls name="columns_controls"/>
    <paging name="listing_paging"/>
    <filters name="listing_filters">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="templates" xsi:type="array">
                    <item name="filters" xsi:type="array">
                        <item name="select" xsi:type="array">
                            <item name="component" xsi:type="string">Magento_Ui/js/form/element/ui-select</item>
                            <item name="template" xsi:type="string">ui/grid/filters/elements/ui-select</item>
                        </item>
                    </item>
                </item>
            </item>
            <item name="observers" xsi:type="array">
                <item name="column" xsi:type="string">column</item>
            </item>
        </argument>
    </filters>
</listingToolbar>

Not sure why Ii am getting that error from the magento/module-sales plugin . Any idea ?

If I disable the core plugin, it works:

<type name="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
    <plugin name="orderGridCollectionFilterPlugin" type="Magento\Sales\Plugin\Model\ResourceModel\Order\OrderGridCollectionFilter"/>
</type> 

Thanks

4
  • Did you find any solutions for it? Commented Jun 26, 2023 at 5:31
  • Facing the same issue did you have solutions for it? Kindly share it as answer if you found any it would be helpful
    – aravind
    Commented Oct 24, 2023 at 12:59
  • @RutvikMonpara see my answer! Commented Jun 6 at 12:54
  • @aravind see my answer! Commented Jun 6 at 12:54

3 Answers 3

0

when your delete controller call then add this code

 use Vendore\Module\Model\ResourceModel\YourModelName\CollectionFactory;
 use Vendore\Module\Model\YourModelFactory;



public function execute()
{
    $customData = $this->collectionFactory->create();

    foreach ($customData as $value) {
        $templateId[] = $value['id'];
    }
    $parameterData = $this->getRequest()->getParams('id');
    $selectedAppsid = $this->getRequest()->getParams('id');

    if (array_key_exists("selected", $parameterData)) {
        $selectedAppsid = $parameterData['selected'];
    }
    if (array_key_exists("excluded", $parameterData)) {
        if ($parameterData['excluded'] == 'false') {
            $selectedAppsid = $templateId;
        } else {
            $selectedAppsid = array_diff($templateId, $parameterData['excluded']);
        }
    }
    $collection = $this->collectionFactory->create();
    $collection->addFieldToFilter('id', ['in' => $selectedAppsid]);
    $delete = 0;
    $model = [];
    foreach ($collection as $item) {
        $this->deleteByIds($item->getId());
        $delete++;
    }
    $this->messageManager->addSuccess(__('A total of %1 Records have been deleted.', $delete));
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    return $resultRedirect->setPath('*/*/notification');
}

public function deleteByIds($id)
{
    $item = $this->YourModelFactory->create()->load($id);
    $item->delete();
} 
0

You have declared the virtualType of Grid Collection

<virtualType name="Vendor\ModuleName\Model\ResourceModel\MoodleLogs\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<arguments>
    <argument name="mainTable" xsi:type="string">moodle_logs</argument>
    <argument name="resourceModel" xsi:type="string">Vendor\ModuleName\Model\ResourceModel\MoodleLogs</argument>
    <argument name="eventPrefix" xsi:type="string">vendor_modulename_logs_grid_collection</argument>
    <argument name="eventObject" xsi:type="string">vendor_logs_grid_collection</argument>
</arguments>

then you have to remove grid collection class which is created in file level in module on this path "Vendor\ModuleName\Model\ResourceModel\MoodleLogs\Grid\Collection" means if you have declared the virtaulType class so no need to create at file level class with same namespace.

0

It looks like this is a MAGENTO bug :)

This is how you can create a patch:

Here is a patch:

diff --git a/vendor/magento/module-sales/Plugin/Model/ResourceModel/Order/OrderGridCollectionFilter.php b/vendor/magento/module-sales/Plugin/Model/ResourceModel/Order/OrderGridCollectionFilter.php
index 995bb833..14b83ec6 100644
--- a/vendor/magento/module-sales/Plugin/Model/ResourceModel/Order/OrderGridCollectionFilter.php
+++ b/vendor/magento/module-sales/Plugin/Model/ResourceModel/Order/OrderGridCollectionFilter.php
@@ -39,7 +39,7 @@ class OrderGridCollectionFilter
      * @throws \Magento\Framework\Exception\LocalizedException
      */
     public function aroundAddFieldToFilter(
-        SearchResult $subject,
+        $subject,
         \Closure $proceed,
         $field,
         $condition = null
@@ -52,7 +52,7 @@ class OrderGridCollectionFilter
                 }
             }
 
-            $fieldName = $subject->getConnection()->quoteIdentifier($field);
+            $fieldName = $subject->getConnection()->quoteIdentifier('main_table.' . $field);
             $condition = $subject->getConnection()->prepareSqlCondition($fieldName, $condition);
             $subject->getSelect()->where($condition, null, Select::TYPE_CONDITION);
 

Related Github issue !

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.