Skip to content

Commit 37c8946

Browse files
committed
ACP2E-1992: Configurable on sale products not visible in products carousel
- addressed CR
1 parent 1e789f4 commit 37c8946

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

app/code/Magento/ConfigurableProduct/Plugin/CatalogWidget/Block/Product/ProductsListPlugin.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1414
use Magento\CatalogWidget\Block\Product\ProductsList;
1515
use Magento\Framework\App\ResourceConnection;
16+
use Magento\Framework\EntityManager\MetadataPool;
1617
use Magento\Framework\Exception\LocalizedException;
1718

1819
class ProductsListPlugin
@@ -32,19 +33,27 @@ class ProductsListPlugin
3233
*/
3334
protected ResourceConnection $resource;
3435

36+
/**
37+
* @var MetadataPool
38+
*/
39+
protected MetadataPool $metadataPool;
40+
3541
/**
3642
* @param CollectionFactory $productCollectionFactory
3743
* @param Visibility $catalogProductVisibility
3844
* @param ResourceConnection $resource
45+
* @param MetadataPool $metadataPool
3946
*/
4047
public function __construct(
4148
CollectionFactory $productCollectionFactory,
4249
Visibility $catalogProductVisibility,
43-
ResourceConnection $resource
50+
ResourceConnection $resource,
51+
MetadataPool $metadataPool
4452
) {
4553
$this->productCollectionFactory = $productCollectionFactory;
4654
$this->catalogProductVisibility = $catalogProductVisibility;
4755
$this->resource = $resource;
56+
$this->metadataPool = $metadataPool;
4857
}
4958

5059
/**
@@ -59,14 +68,16 @@ public function __construct(
5968
public function afterCreateCollection(ProductsList $subject, Collection $result): Collection
6069
{
6170
if ($result->count()) {
71+
$linkField = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
72+
->getLinkField();
6273
$connection = $this->resource->getConnection();
6374
$productIds = $connection->fetchCol(
6475
$connection
6576
->select()
6677
->from(['e' => $this->resource->getTableName('catalog_product_entity')], ['link_table.parent_id'])
6778
->joinInner(
6879
['link_table' => $this->resource->getTableName('catalog_product_super_link')],
69-
'link_table.product_id = e.entity_id',
80+
'link_table.product_id = e.' . $linkField,
7081
[]
7182
)
7283
->where('link_table.product_id IN (?)', $result->getAllIds())

app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/CatalogWidget/Block/Product/ProductListPluginTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Magento\ConfigurableProduct\Plugin\CatalogWidget\Block\Product\ProductsListPlugin;
1515
use Magento\Framework\App\ResourceConnection;
1616
use Magento\Framework\DB\Adapter\AdapterInterface;
17+
use Magento\Framework\EntityManager\EntityMetadataInterface;
18+
use Magento\Framework\EntityManager\MetadataPool;
1719
use PHPUnit\Framework\TestCase;
1820
use PHPUnit\Framework\MockObject\MockObject;
1921
use Magento\Framework\DB\Select;
@@ -36,6 +38,11 @@ class ProductListPluginTest extends TestCase
3638
*/
3739
protected ResourceConnection $resource;
3840

41+
/**
42+
* @var MetadataPool
43+
*/
44+
protected MetadataPool $metadataPool;
45+
3946
/**
4047
* @var ProductsListPlugin
4148
*/
@@ -46,11 +53,13 @@ protected function setUp(): void
4653
$this->productCollectionFactory = $this->createMock(CollectionFactory::class);
4754
$this->catalogProductVisibility = $this->createMock(Visibility::class);
4855
$this->resource = $this->createMock(ResourceConnection::class);
56+
$this->metadataPool = $this->createMock(MetadataPool::class);
4957

5058
$this->plugin = new ProductsListPlugin(
5159
$this->productCollectionFactory,
5260
$this->catalogProductVisibility,
53-
$this->resource
61+
$this->resource,
62+
$this->metadataPool
5463
);
5564

5665
parent::setUp();
@@ -80,6 +89,12 @@ public function testAfterCreateCollectionSuccess(): void
8089
$result->expects($this->once())->method('count')->willReturn(1);
8190
$result->expects($this->once())->method('getAllIds')->willReturn([1]);
8291
$result->expects($this->once())->method('addItem');
92+
$entity = $this->createMock(EntityMetadataInterface::class);
93+
$entity->expects($this->once())->method('getLinkField')->willReturn('row_id');
94+
$this->metadataPool->expects($this->once())
95+
->method('getMetadata')
96+
->with(\Magento\Catalog\Api\Data\ProductInterface::class)
97+
->willReturn($entity);
8398

8499
$select = $this->createMock(Select::class);
85100
$select->expects($this->once())
@@ -90,7 +105,7 @@ public function testAfterCreateCollectionSuccess(): void
90105
->method('joinInner')
91106
->with(
92107
['link_table' => 'catalog_product_super_link'],
93-
'link_table.product_id = e.entity_id',
108+
'link_table.product_id = e.row_id',
94109
[]
95110
)->willReturn($select);
96111
$select->expects($this->once())->method('where')->with('link_table.product_id IN (?)', [1]);

0 commit comments

Comments
 (0)