Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Vinai opened this issue Jul 1, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@Vinai
Copy link
Collaborator

Vinai commented Jul 1, 2021

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));
}
@Vinai Vinai added the bug Something isn't working label Jul 1, 2021
@natedawg92
Copy link

natedawg92 commented Sep 10, 2024

I came across this issue yesterday whilst implementing a grid using a custom Grid Collection.

I was able to work around this issue by adding fake method docBlocks to the Model class for the joined fields and/or custom fields e.g.

/**
 * @method ?string getProductSku()
 * @method ?string getProductName()
 * @method ?string getCustomerGroupCode()
 * @method ?\Vendor\TradeAccounts\Model\StoreTierPriceValue getValueObject()
 */

This isn't really ideal as the model doesn't really have these functions and will only work if you control the Model Source code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants