88
99namespace Magento \ConfigurableProduct \Plugin \CatalogWidget \Block \Product ;
1010
11+ use Magento \Catalog \Model \Product ;
1112use Magento \Catalog \Model \Product \Visibility ;
1213use Magento \Catalog \Model \ResourceModel \Product \Collection ;
1314use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
@@ -68,7 +69,8 @@ public function __construct(
6869 public function afterCreateCollection (ProductsList $ subject , Collection $ result ): Collection
6970 {
7071 $ notVisibleCollection = $ subject ->getBaseCollection ();
71- $ searchProducts = array_merge ($ result ->getAllIds (), $ notVisibleCollection ->getAllIds ());
72+ $ currentIds = $ result ->getAllIds ();
73+ $ searchProducts = array_merge ($ currentIds , $ notVisibleCollection ->getAllIds ());
7274
7375 if (!empty ($ searchProducts )) {
7476 $ linkField = $ this ->metadataPool ->getMetadata (\Magento \Catalog \Api \Data \ProductInterface::class)
@@ -90,8 +92,11 @@ public function afterCreateCollection(ProductsList $subject, Collection $result)
9092 $ configurableProductCollection ->setVisibility ($ this ->catalogProductVisibility ->getVisibleInCatalogIds ());
9193 $ configurableProductCollection ->addIdFilter ($ productIds );
9294
95+ /** @var Product $item */
9396 foreach ($ configurableProductCollection ->getItems () as $ item ) {
94- $ result ->addItem ($ item );
97+ if (false === in_array ($ item ->getId (), $ currentIds )) {
98+ $ result ->addItem ($ item );
99+ }
95100 }
96101 }
97102
0 commit comments