Skip to content

Commit 200167b

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4096' into PR_2025_08_25_muntianu
2 parents 65513e6 + 970d83f commit 200167b

File tree

2 files changed

+169
-3
lines changed

2 files changed

+169
-3
lines changed

app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ protected function addGlobalAttribute(
178178
$storeId = $connection->getIfNullSql($alias . '.store_id', $this->storeManager->getStore()->getId());
179179
$linkField = $attribute->getEntity()->getLinkField();
180180

181-
$collection->getSelect()->join(
181+
$collection->getSelect()->joinLeft(
182182
[$alias => $collection->getTable($attribute->getBackendTable())],
183183
"($alias.$linkField = e.$linkField) AND ($alias.store_id = $storeId)" .
184184
" AND ($alias.attribute_id = {$attribute->getId()})",

dev/tests/integration/testsuite/Magento/CatalogWidget/Block/Product/ProductListTest.php

Lines changed: 168 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2017 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\CatalogWidget\Block\Product;
88

99
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
1010
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
11+
use Magento\Catalog\Test\Fixture\MultiselectAttribute as MultiselectAttributeFixture;
12+
use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
1113
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
1214
use Magento\Catalog\Model\Indexer\Product\Eav\Processor;
1315
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
@@ -18,10 +20,13 @@
1820
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
1921
use Magento\TestFramework\Fixture\DbIsolation;
2022
use Magento\TestFramework\Helper\Bootstrap;
23+
use PHPUnit\Framework\Attributes\DataProvider;
2124
use PHPUnit\Framework\TestCase;
2225

2326
/**
2427
* Tests for @see \Magento\CatalogWidget\Block\Product\ProductsList
28+
*
29+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2530
*/
2631
class ProductListTest extends TestCase
2732
{
@@ -368,4 +373,165 @@ public static function priceFilterDataProvider(): array
368373
],
369374
];
370375
}
376+
377+
#[
378+
DbIsolation(false),
379+
DataProvider('collectionResultWithMultiselectAttributeDataProvider'),
380+
DataFixture(
381+
MultiselectAttributeFixture::class,
382+
[
383+
'scope' => 'global',
384+
'options' => ['option_1', 'option_2']
385+
],
386+
'gl_multiselect'
387+
),
388+
DataFixture(CategoryFixture::class, as: 'category'),
389+
DataFixture(
390+
ProductFixture::class,
391+
[
392+
'category_ids' => ['$category.id$']
393+
],
394+
as: 'product1'
395+
),
396+
DataFixture(
397+
ProductFixture::class,
398+
[
399+
'custom_attributes' => [
400+
['attribute_code' => '$gl_multiselect.attribute_code$', 'value' => '$gl_multiselect.option_1$']
401+
]
402+
],
403+
as: 'product2'
404+
),
405+
DataFixture(
406+
ProductFixture::class,
407+
[
408+
'custom_attributes' => [
409+
['attribute_code' => '$gl_multiselect.attribute_code$', 'value' => '$gl_multiselect.option_2$']
410+
]
411+
],
412+
as: 'product3'
413+
),
414+
DataFixture(
415+
ProductFixture::class,
416+
[
417+
'category_ids' => ['$category.id$'],
418+
'custom_attributes' => [
419+
['attribute_code' => '$gl_multiselect.attribute_code$', 'value' => '$gl_multiselect.option_1$']
420+
]
421+
],
422+
as: 'product4'
423+
),
424+
DataFixture(
425+
ProductFixture::class,
426+
[
427+
'category_ids' => ['$category.id$'],
428+
'custom_attributes' => [
429+
['attribute_code' => '$gl_multiselect.attribute_code$', 'value' => '$gl_multiselect.option_2$']
430+
]
431+
],
432+
as: 'product5'
433+
)
434+
]
435+
public function testCollectionResultWithMultiselectAttribute(
436+
array $conditions,
437+
array $products
438+
): void {
439+
$fixtures = DataFixtureStorageManager::getStorage();
440+
$conditions = array_map(
441+
function ($condition) use ($fixtures) {
442+
if (isset($condition['value']) && is_callable($condition['value'])) {
443+
$condition['value'] = $condition['value']($fixtures);
444+
}
445+
if (isset($condition['attribute']) && $fixtures->get($condition['attribute'])) {
446+
$condition['attribute'] = $fixtures->get($condition['attribute'])->getAttributeCode();
447+
}
448+
return $condition;
449+
},
450+
$conditions
451+
);
452+
$products = array_map(
453+
function ($product) use ($fixtures) {
454+
return $fixtures->get($product)->getSku();
455+
},
456+
$products
457+
);
458+
459+
$this->block->setConditions($conditions);
460+
$collection = $this->block->createCollection();
461+
$collection->load();
462+
463+
$this->assertEqualsCanonicalizing(
464+
$products,
465+
$collection->getColumnValues('sku')
466+
);
467+
}
468+
469+
public static function collectionResultWithMultiselectAttributeDataProvider(): array
470+
{
471+
return [
472+
'global multiselect with match ANY' => [
473+
[
474+
'1' => [
475+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class,
476+
'aggregator' => 'any',
477+
'value' => '1',
478+
'new_child' => '',
479+
],
480+
'1--1' => [
481+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
482+
'attribute' => 'category_ids',
483+
'operator' => '==',
484+
'value' => fn ($fixtures) => $fixtures->get('category')->getId(),
485+
],
486+
'1--2' => [
487+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
488+
'attribute' => 'gl_multiselect',
489+
'operator' => '()',
490+
'value' => fn ($fixtures) => $fixtures->get('gl_multiselect')->getData('option_1'),
491+
],
492+
],
493+
['product1', 'product2', 'product4', 'product5']
494+
],
495+
'global multiselect with match AND' => [
496+
[
497+
'1' => [
498+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class,
499+
'aggregator' => 'all',
500+
'value' => '1',
501+
'new_child' => '',
502+
],
503+
'1--1' => [
504+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
505+
'attribute' => 'category_ids',
506+
'operator' => '==',
507+
'value' => fn ($fixtures) => $fixtures->get('category')->getId(),
508+
],
509+
'1--2' => [
510+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
511+
'attribute' => 'gl_multiselect',
512+
'operator' => '()',
513+
'value' => fn ($fixtures) => $fixtures->get('gl_multiselect')->getData('option_1'),
514+
],
515+
],
516+
['product4']
517+
],
518+
'global multiselect with single value' => [
519+
[
520+
'1' => [
521+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class,
522+
'aggregator' => 'all',
523+
'value' => '1',
524+
'new_child' => '',
525+
],
526+
'1--1' => [
527+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
528+
'attribute' => 'gl_multiselect',
529+
'operator' => '()',
530+
'value' => fn ($fixtures) => $fixtures->get('gl_multiselect')->getData('option_2'),
531+
],
532+
],
533+
['product3', 'product5']
534+
]
535+
];
536+
}
371537
}

0 commit comments

Comments
 (0)