0

I am programatically updating the qty column values for configurable products.

Sadly, the grid filter for this column doesn't work with new values.

The underlying catalog product collection joins with cataloginventory_stock_item table for this field, via the Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFieldToCollection DataProvider field strategy, and since I haven't changed the qty column values inside the database I don't see the correct results.

The filter works if value 0 (which is the default conf products qty value stored in db) is used in filter.

Can I filter the collection for this field based on the programatically calculated values I am displaying in the grid and how exactly?

Is it possible and how can I join on programatic values instead of a db table column?

Thnx.

1 Answer 1

0

You can use the Plugin and add the below code in your admin's di.xml file

<type name="Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider">
    <plugin name="product-collection-sorting" type="[Vendor]\[Module]\Plugin\ProductDataProvider" sortOrder="999"/>
</type>

Now create file [Vendor][Module]\Plugin\ProductDataProvider

<?php
namespace [Vendor]\[Module]\Plugin;
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider as RelatedProductDataProvider;
class ProductDataProvider extends RelatedProductDataProvider
{

public function afterGetData(
        \Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider $subject,
        $result
    ){
        $subject->getCollection()->clear();
        $subject->getCollection()->addFieldToFilter('attribute_set_id', ['eq' => 4])->load();
        $items = $subject->getCollection()->addFieldToFilter('attribute_set_id', ['eq' => 4])->toArray();
        $totalRecords = $subject->getCollection()->addFieldToFilter('attribute_set_id', ['eq' => 4])->load()->getSize();
    }

}

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.