Skip to content

Commit fbba466

Browse files
committed
ACP2E-1992: Configurable on sale products not visible in products carousel
- configurable products are now visible even if their children aren't
1 parent ba191f2 commit fbba466

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,26 @@ protected function _beforeToHtml()
324324
*/
325325
public function createCollection()
326326
{
327-
/** @var $collection Collection */
328-
$collection = $this->productCollectionFactory->create();
327+
$collection = $this->getBaseCollection();
328+
329+
$collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
330+
331+
return $collection;
332+
}
329333

334+
/**
335+
* Prepare and return product collection without visibility filter
336+
*
337+
* @return Collection
338+
* @throws LocalizedException
339+
*/
340+
public function getBaseCollection(): Collection
341+
{
342+
$collection = $this->productCollectionFactory->create();
330343
if ($this->getData('store_id') !== null) {
331344
$collection->setStoreId($this->getData('store_id'));
332345
}
333346

334-
$collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
335-
336347
/**
337348
* Change sorting attribute to entity_id because created_at can be the same for products fastly created
338349
* one by one and sorting by created_at is indeterministic in this case.

app/code/Magento/CatalogWidget/view/frontend/templates/product/widget/content/grid.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use Magento\Framework\App\Action\Action;
1515
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper
1616
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
1717
?>
18-
<?php if ($exist = ($block->getProductCollection() && $block->getProductCollection()->getSize())): ?>
18+
<?php if ($exist = ($block->getProductCollection() && $block->getProductCollection()->count())): ?>
1919
<?php
2020
$type = 'widget-product-grid';
2121

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ class ProductsListPlugin
2121
/**
2222
* @var CollectionFactory
2323
*/
24-
protected CollectionFactory $productCollectionFactory;
24+
private CollectionFactory $productCollectionFactory;
2525

2626
/**
2727
* @var Visibility
2828
*/
29-
protected Visibility $catalogProductVisibility;
29+
private Visibility $catalogProductVisibility;
3030

3131
/**
3232
* @var ResourceConnection
3333
*/
34-
protected ResourceConnection $resource;
34+
private ResourceConnection $resource;
3535

3636
/**
3737
* @var MetadataPool
3838
*/
39-
protected MetadataPool $metadataPool;
39+
private MetadataPool $metadataPool;
4040

4141
/**
4242
* @param CollectionFactory $productCollectionFactory
@@ -67,7 +67,10 @@ public function __construct(
6767
*/
6868
public function afterCreateCollection(ProductsList $subject, Collection $result): Collection
6969
{
70-
if ($result->count()) {
70+
$notVisibleCollection = $subject->getBaseCollection();
71+
$searchProducts = array_merge($result->getAllIds(), $notVisibleCollection->getAllIds());
72+
73+
if (!empty($searchProducts)) {
7174
$linkField = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
7275
->getLinkField();
7376
$connection = $this->resource->getConnection();
@@ -80,7 +83,7 @@ public function afterCreateCollection(ProductsList $subject, Collection $result)
8083
'link_table.product_id = e.' . $linkField,
8184
[]
8285
)
83-
->where('link_table.product_id IN (?)', $result->getAllIds())
86+
->where('link_table.product_id IN (?)', $searchProducts)
8487
);
8588

8689
$configurableProductCollection = $this->productCollectionFactory->create();

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ protected function setUp(): void
7575
public function testAfterCreateCollectionNoCount(): void
7676
{
7777
$subject = $this->createMock(ProductsList::class);
78+
$baseCollection = $this->createMock(Collection::class);
79+
$baseCollection->expects($this->once())->method('getAllIds')->willReturn([]);
80+
$subject->expects($this->once())->method('getBaseCollection')->willReturn($baseCollection);
7881
$result = $this->createMock(Collection::class);
79-
$result->expects($this->once())->method('count')->willReturn(0);
82+
$result->expects($this->once())->method('getAllIds')->willReturn([]);
8083

8184
$this->assertSame($result, $this->plugin->afterCreateCollection($subject, $result));
8285
}
@@ -88,9 +91,12 @@ public function testAfterCreateCollectionNoCount(): void
8891
public function testAfterCreateCollectionSuccess(): void
8992
{
9093
$linkField = 'entity_id';
94+
$baseCollection = $this->createMock(Collection::class);
95+
$baseCollection->expects($this->once())->method('getAllIds')->willReturn([2]);
9196
$subject = $this->createMock(ProductsList::class);
97+
$subject->expects($this->once())->method('getBaseCollection')->willReturn($baseCollection);
98+
9299
$result = $this->createMock(Collection::class);
93-
$result->expects($this->once())->method('count')->willReturn(1);
94100
$result->expects($this->once())->method('getAllIds')->willReturn([1]);
95101
$result->expects($this->once())->method('addItem');
96102
$entity = $this->createMock(EntityMetadataInterface::class);
@@ -112,7 +118,7 @@ public function testAfterCreateCollectionSuccess(): void
112118
'link_table.product_id = e.' . $linkField,
113119
[]
114120
)->willReturn($select);
115-
$select->expects($this->once())->method('where')->with('link_table.product_id IN (?)', [1]);
121+
$select->expects($this->once())->method('where')->with('link_table.product_id IN (?)', [1, 2]);
116122
$connection = $this->createMock(AdapterInterface::class);
117123
$connection->expects($this->once())->method('select')->willReturn($select);
118124
$connection->expects($this->once())->method('fetchCol')->willReturn([2]);

0 commit comments

Comments
 (0)