hyva-themes / magento2-hyva-admin

This module aims to make creating grids and forms in the Magento 2 adminhtml area joyful and fast.
https://hyva-themes.github.io/magento2-hyva-admin/
BSD 3-Clause "New" or "Revised" License
168 stars 39 forks source link

Filter on joined columns in a collectionGridProcessor doesn't work for EAV collections #58

Open Vinai opened 3 years ago

Vinai commented 3 years ago

EAV Collections expect columns to be declared as attributes. Joined columns are not available as attributes.

More information can be found in #55.

Test to reproduce the issue:

/**
 * @magentoDataFixture Magento/Catalog/_files/product_simple.php
 * @magentoDataFixture Magento/Catalog/_files/products_list.php
 */
public function testFilterJoinedAttributeOnEavCollection(): void
{
    $processor = new class() extends AbstractGridSourceProcessor implements HyvaGridCollectionProcessorInterface {

        /**
         * @param ProductCollection $source
         * @param string $gridName
         */
        public function afterInitSelect(AbstractDbCollection $source, string $gridName): void
        {
            $source->joinField(
                'test_field',
                'catalog_category_product',
                'product_id',
                'e.entity_id = test_field'
            );
        }
    };

    $args = [
        'gridName'            => 'test',
        'processors'          => [$processor],
        'sourceConfiguration' => ['collection' => ProductCollection::class],
    ];
    /** @var CollectionGridSourceType $sut */
    $sut = ObjectManager::getInstance()->create(CollectionGridSourceType::class, $args);

    /** @var SearchCriteriaBuilder $searchCriteriaBuilder */
    $searchCriteriaBuilder = ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
    $searchCriteriaBuilder->addFilter('test_field', '1');

    $rawGridData = $sut->fetchData($searchCriteriaBuilder->create());
    $records = $sut->extractRecords($rawGridData);
    $this->assertGreaterThan(0, count($records));
}