diff --git a/vendor/magento/module-catalog-widget/Block/Product/ProductsList.php b/vendor/magento/module-catalog-widget/Block/Product/ProductsList.php
index 7e6693ce68ef..7181d028ab33 100644
--- a/vendor/magento/module-catalog-widget/Block/Product/ProductsList.php
+++ b/vendor/magento/module-catalog-widget/Block/Product/ProductsList.php
@@ -328,15 +328,26 @@ protected function _beforeToHtml()
*/
public function createCollection()
{
- /** @var $collection Collection */
- $collection = $this->productCollectionFactory->create();
+ $collection = $this->getBaseCollection();
+
+ $collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
+
+ return $collection;
+ }
+ /**
+ * Prepare and return product collection without visibility filter
+ *
+ * @return Collection
+ * @throws LocalizedException
+ */
+ public function getBaseCollection(): Collection
+ {
+ $collection = $this->productCollectionFactory->create();
if ($this->getData('store_id') !== null) {
$collection->setStoreId($this->getData('store_id'));
}
- $collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
-
/**
* Change sorting attribute to entity_id because created_at can be the same for products fastly created
* one by one and sorting by created_at is indeterministic in this case.
diff --git a/vendor/magento/module-catalog-widget/view/frontend/templates/product/widget/content/grid.phtml b/vendor/magento/module-catalog-widget/view/frontend/templates/product/widget/content/grid.phtml
index 8677a47e0729..2a96a0b44c48 100644
--- a/vendor/magento/module-catalog-widget/view/frontend/templates/product/widget/content/grid.phtml
+++ b/vendor/magento/module-catalog-widget/view/frontend/templates/product/widget/content/grid.phtml
@@ -15,7 +15,7 @@ use Magento\Framework\App\Action\Action;
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
?>
-getProductCollection() && $block->getProductCollection()->getSize())): ?>
+getProductCollection() && $block->getProductCollection()->count())): ?>
productCollectionFactory = $productCollectionFactory;
+ $this->catalogProductVisibility = $catalogProductVisibility;
+ $this->resource = $resource;
+ $this->metadataPool = $metadataPool;
+ }
+
+ /**
+ * Adds configurable products to the item list if child products are already part of the collection
+ *
+ * @param ProductsList $subject
+ * @param Collection $result
+ * @return Collection
+ * @throws LocalizedException
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public function afterCreateCollection(ProductsList $subject, Collection $result): Collection
+ {
+ $notVisibleCollection = $subject->getBaseCollection();
+ $currentIds = $result->getAllIds();
+ $searchProducts = array_merge($currentIds, $notVisibleCollection->getAllIds());
+
+ if (!empty($searchProducts)) {
+ $linkField = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
+ ->getLinkField();
+ $connection = $this->resource->getConnection();
+ $productIds = $connection->fetchCol(
+ $connection
+ ->select()
+ ->from(['e' => $this->resource->getTableName('catalog_product_entity')], ['link_table.parent_id'])
+ ->joinInner(
+ ['link_table' => $this->resource->getTableName('catalog_product_super_link')],
+ 'link_table.product_id = e.' . $linkField,
+ []
+ )
+ ->where('link_table.product_id IN (?)', $searchProducts)
+ );
+
+ $configurableProductCollection = $this->productCollectionFactory->create();
+ $configurableProductCollection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
+ $configurableProductCollection->addIdFilter($productIds);
+
+ /** @var Product $item */
+ foreach ($configurableProductCollection->getItems() as $item) {
+ if (false === in_array($item->getId(), $currentIds)) {
+ $result->addItem($item->load($item->getId()));
+ }
+ }
+ }
+
+ return $result;
+ }
+}
diff --git a/vendor/magento/module-configurable-product/etc/di.xml b/vendor/magento/module-configurable-product/etc/di.xml
index 4559fd503d03..36041169514c 100644
--- a/vendor/magento/module-configurable-product/etc/di.xml
+++ b/vendor/magento/module-configurable-product/etc/di.xml
@@ -21,6 +21,9 @@
+
+
+