7
7
8
8
namespace Magento \CloudComponents \Model \UrlFinder ;
9
9
10
+ use Magento \Catalog \Model \Product \Visibility as ProductVisibility ;
10
11
use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
11
12
use Magento \Catalog \Model \ResourceModel \Product \Collection ;
12
13
use Magento \CloudComponents \Model \UrlFinderInterface as CloudUrlFinderInterface ;
@@ -43,6 +44,11 @@ class Product implements CloudUrlFinderInterface
43
44
*/
44
45
private $ productCollectionFactory ;
45
46
47
+ /**
48
+ * @var ProductVisibility
49
+ */
50
+ private $ productVisibility ;
51
+
46
52
/**
47
53
* @var integer
48
54
*/
@@ -51,19 +57,22 @@ class Product implements CloudUrlFinderInterface
51
57
/**
52
58
* @param UrlFixer $urlFixer
53
59
* @param CollectionFactory $productCollectionFactory
60
+ * @param ProductVisibility $productVisibility
54
61
* @param StoreInterface[] $stores
55
62
* @param array $productSku
56
63
* @param int $productLimit
57
64
*/
58
65
public function __construct (
59
66
UrlFixer $ urlFixer ,
60
67
CollectionFactory $ productCollectionFactory ,
68
+ ProductVisibility $ productVisibility ,
61
69
array $ stores ,
62
70
array $ productSku = [],
63
71
int $ productLimit = self ::PRODUCT_LIMIT
64
72
) {
65
73
$ this ->urlFixer = $ urlFixer ;
66
74
$ this ->productCollectionFactory = $ productCollectionFactory ;
75
+ $ this ->productVisibility = $ productVisibility ;
67
76
$ this ->stores = $ stores ;
68
77
$ this ->productSku = $ productSku ;
69
78
$ this ->productLimit = $ productLimit ;
@@ -100,6 +109,7 @@ private function getProducts($storeId): Collection
100
109
/** @var Collection $collection */
101
110
$ collection = $ this ->productCollectionFactory ->create ();
102
111
$ collection ->addStoreFilter ($ storeId );
112
+ $ collection ->setVisibility ($ this ->productVisibility ->getVisibleInSiteIds ());
103
113
104
114
if (count ($ this ->productSku )) {
105
115
$ collection ->addAttributeToFilter ('sku ' , $ this ->productSku );
0 commit comments