77
88namespace Magento \CloudComponents \Model \UrlFinder ;
99
10+ use Magento \Catalog \Model \Product \Visibility as ProductVisibility ;
1011use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
1112use Magento \Catalog \Model \ResourceModel \Product \Collection ;
1213use Magento \CloudComponents \Model \UrlFinderInterface as CloudUrlFinderInterface ;
@@ -43,6 +44,11 @@ class Product implements CloudUrlFinderInterface
4344 */
4445 private $ productCollectionFactory ;
4546
47+ /**
48+ * @var ProductVisibility
49+ */
50+ private $ productVisibility ;
51+
4652 /**
4753 * @var integer
4854 */
@@ -51,19 +57,22 @@ class Product implements CloudUrlFinderInterface
5157 /**
5258 * @param UrlFixer $urlFixer
5359 * @param CollectionFactory $productCollectionFactory
60+ * @param ProductVisibility $productVisibility
5461 * @param StoreInterface[] $stores
5562 * @param array $productSku
5663 * @param int $productLimit
5764 */
5865 public function __construct (
5966 UrlFixer $ urlFixer ,
6067 CollectionFactory $ productCollectionFactory ,
68+ ProductVisibility $ productVisibility ,
6169 array $ stores ,
6270 array $ productSku = [],
6371 int $ productLimit = self ::PRODUCT_LIMIT
6472 ) {
6573 $ this ->urlFixer = $ urlFixer ;
6674 $ this ->productCollectionFactory = $ productCollectionFactory ;
75+ $ this ->productVisibility = $ productVisibility ;
6776 $ this ->stores = $ stores ;
6877 $ this ->productSku = $ productSku ;
6978 $ this ->productLimit = $ productLimit ;
@@ -100,6 +109,7 @@ private function getProducts($storeId): Collection
100109 /** @var Collection $collection */
101110 $ collection = $ this ->productCollectionFactory ->create ();
102111 $ collection ->addStoreFilter ($ storeId );
112+ $ collection ->setVisibility ($ this ->productVisibility ->getVisibleInSiteIds ());
103113
104114 if (count ($ this ->productSku )) {
105115 $ collection ->addAttributeToFilter ('sku ' , $ this ->productSku );
0 commit comments