0

I have created custom module. In that I am displaying product collection in Ui grid. I have extend \Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider to display collections.

What is my requirement : I want to display(load) collection only after user search anything from filter.

The UI grid should not display any product until user search anything from filter.

My code For this file app/code/Company/module/Ui/DataProvider/Product/Vendor/ProductDataProvider.php

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Company\module\Ui\DataProvider\Product\Vendor;

use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;

/**
 * Class ProductDataProvider
 */
class ProductDataProvider extends \Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider
{

    /**
     * Construct
     *
     * @param string $name
     * @param string $primaryFieldName
     * @param string $requestFieldName
     * @param CollectionFactory $collectionFactory
     * @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
     * @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
     * @param array $meta
     * @param array $data
     */
    public function __construct(
        $name,
        $primaryFieldName,
        $requestFieldName,
        CollectionFactory $collectionFactory,
        array $addFieldStrategies = [],
        array $addFilterStrategies = [],
        array $meta = [],
        array $data = []
    ) {
        parent::__construct($name, $primaryFieldName, $requestFieldName, $collectionFactory, $addFieldStrategies, $addFilterStrategies, $meta, $data);
        $this->collection->addAttributeToFilter('type_id', 'configurable');
        $this->collection->addAttributeToFilter('has_options', '1');
        $this->collection->joinField(
            'qty',
            'cataloginventory_stock_item',
            'qty',
            'product_id=entity_id',
            '{{table}}.stock_id=1',
            'left'
        );
    }
}
  • Share your extended ProductDataProvider code. – Chirag Patel Jul 17 at 4:41
  • @ChiragPatel I have updated my answer – David Coder Jul 17 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.