8
8
use Magento \Catalog \Api \Data \ProductInterface ;
9
9
use Magento \Catalog \Model \Product ;
10
10
use Magento \Catalog \Model \Product \Visibility ;
11
- use Magento \Catalog \Model \ResourceModel \Product \Collection ;
11
+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
12
12
use Magento \CatalogUrlRewrite \Model \ProductScopeRewriteGenerator ;
13
13
use Magento \CatalogUrlRewrite \Model \ProductUrlPathGenerator ;
14
14
use Magento \CatalogUrlRewrite \Model \ProductUrlRewriteGenerator ;
@@ -59,9 +59,9 @@ class ProductProcessUrlRewriteSavingObserver implements ObserverInterface
59
59
private $ deleteEntitiesFromStores ;
60
60
61
61
/**
62
- * @var Collection
62
+ * @var CollectionFactory
63
63
*/
64
- private $ productCollection ;
64
+ private $ collectionFactory ;
65
65
66
66
/**
67
67
* @param ProductUrlRewriteGenerator $productUrlRewriteGenerator
@@ -70,7 +70,7 @@ class ProductProcessUrlRewriteSavingObserver implements ObserverInterface
70
70
* @param StoreManagerInterface $storeManager
71
71
* @param ProductScopeRewriteGenerator $productScopeRewriteGenerator
72
72
* @param DeleteEntitiesFromStores $deleteEntitiesFromStores
73
- * @param Collection $productCollection
73
+ * @param CollectionFactory $collectionFactory
74
74
*/
75
75
public function __construct (
76
76
ProductUrlRewriteGenerator $ productUrlRewriteGenerator ,
@@ -79,15 +79,15 @@ public function __construct(
79
79
StoreManagerInterface $ storeManager ,
80
80
ProductScopeRewriteGenerator $ productScopeRewriteGenerator ,
81
81
DeleteEntitiesFromStores $ deleteEntitiesFromStores ,
82
- Collection $ productCollection
82
+ CollectionFactory $ collectionFactory
83
83
) {
84
84
$ this ->productUrlRewriteGenerator = $ productUrlRewriteGenerator ;
85
85
$ this ->urlPersist = $ urlPersist ;
86
86
$ this ->productUrlPathGenerator = $ productUrlPathGenerator ;
87
87
$ this ->storeManager = $ storeManager ;
88
88
$ this ->productScopeRewriteGenerator = $ productScopeRewriteGenerator ;
89
89
$ this ->deleteEntitiesFromStores = $ deleteEntitiesFromStores ;
90
- $ this ->productCollection = $ productCollection ;
90
+ $ this ->collectionFactory = $ collectionFactory ;
91
91
}
92
92
93
93
/**
@@ -117,7 +117,8 @@ public function execute(Observer $observer)
117
117
118
118
$ storeIdsToRemove = [];
119
119
$ productWebsiteMap = array_flip ($ product ->getWebsiteIds ());
120
- $ storeVisibilities = $ this ->productCollection ->getAllAttributeValues (ProductInterface::VISIBILITY );
120
+ $ storeVisibilities = $ this ->collectionFactory ->create ()
121
+ ->getAllAttributeValues (ProductInterface::VISIBILITY );
121
122
if ($ this ->productScopeRewriteGenerator ->isGlobalScope ($ product ->getStoreId ())) {
122
123
//Remove any rewrite URLs for websites the product is not in, or is not visible in. Global Scope.
123
124
foreach ($ this ->storeManager ->getStores () as $ store ) {
0 commit comments