-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Cannot use field(s) from source processor (beforeLoad) #45
Comments
Hi Victor, thanks for opening the issue!
Time to add a
I' not sure I understand correctly, but what I think you are saying is to not load the data for excluded fields, right? Does that answer this question? |
Vinai, let me explain more details about exclude scenario. This is more related to performance and extra data that are never use in grid. Maybe more correct request here is extract only included fields if they are specified. Precondition: you have a real catalog (not sample data) with 100 custom attributes, with assigned related, upsell, crosssell. You create a grid and specify only 20 attributes that are requires for you with includes. Expected Result: the system processes (extract) only your specified attributes for render Actual Result: the system processes all EAV attributes for each product individually and in case 50 products per page - try to load related, upsell, crosssell collections for each row. Possible workaround: Defines event for I didn't check scenario (saw in examples) when specified additional filters which are not present in |
Regarding the join field, I've decided to introduce a new interface that is specific for collection source type processors: It declares a method public function afterInitSelect(AbstractDbCollection $source, string $gridName): void The new interface extends the Here is the test I used to reproduce the issue and to confirm the new interface works as intended: /**
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @magentoDataFixture Magento/Catalog/_files/products_list.php
*/
public function testAfterInitSelectProcessorCanJoinFieldsForGrid(): void
{
$processor = new class() extends AbstractGridSourceProcessor implements HyvaGridCollectionProcessorInterface {
public function afterInitSelect(AbstractDbCollection $source, string $gridName): void
{
$select = $source->getSelect();
// add select expression
$select->columns(['foo' => new \Zend_Db_Expr('foo')]);
// add field from joined table
$source->getSelect()->joinLeft(
'catalog_category_product',
'e.entity_id = catalog_category_product.product_id',
['test_field' => 'catalog_category_product.entity_id']
);
}
};
$args = [
'gridName' => 'test',
'processors' => [$processor],
'sourceConfiguration' => ['collection' => ProductCollection::class],
];
/** @var CollectionGridSourceType $sut */
$sut = ObjectManager::getInstance()->create(CollectionGridSourceType::class, $args);
$columnKeys = $sut->getColumnKeys();
$this->assertContains('foo', $columnKeys); // select expression
$this->assertContains('test_field', $columnKeys); // joined field
$this->assertContains('sku', $columnKeys); // entity table attribute
$this->assertContains('color', $columnKeys); // eav attribute
} I'll roll a release shortly and hope that solves that issue for you. |
Add collection specific source type processor to allow joining fields before the available grid columns are extracted. Fixes issue #45.
Released in 1.1.14. New Interface: Example in test: |
Example: You are want to join some field (stored in separate table) to product grid
You can use native collection and processor with join data on beforeLoad
But you cannot use field in grid definition like
As Result: Exception #0 (OutOfBoundsException): Column(s) not found on source: custom_filed
Please advise designed solution for?
I can define own collection and join this field in init select, but looking for some easy way, which allows to easy extend data from different extensions
Also, if you want to use plugin for
\Hyva\Admin\Model\GridSourceType\CollectionGridSourceType
- you cannot access togridName
variableIdeally, if we have defined excluded fields - not extract them, especially linked products, etc
The text was updated successfully, but these errors were encountered: