88use Magento \Catalog \Api \Data \ProductInterface ;
99use Magento \Catalog \Model \Product ;
1010use Magento \Catalog \Model \Product \Visibility ;
11- use Magento \Catalog \Model \ResourceModel \Product \Collection ;
11+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
1212use Magento \CatalogUrlRewrite \Model \ProductScopeRewriteGenerator ;
1313use Magento \CatalogUrlRewrite \Model \ProductUrlPathGenerator ;
1414use Magento \CatalogUrlRewrite \Model \ProductUrlRewriteGenerator ;
@@ -59,9 +59,9 @@ class ProductProcessUrlRewriteSavingObserver implements ObserverInterface
5959 private $ deleteEntitiesFromStores ;
6060
6161 /**
62- * @var Collection
62+ * @var CollectionFactory
6363 */
64- private $ productCollection ;
64+ private $ collectionFactory ;
6565
6666 /**
6767 * @param ProductUrlRewriteGenerator $productUrlRewriteGenerator
@@ -70,7 +70,7 @@ class ProductProcessUrlRewriteSavingObserver implements ObserverInterface
7070 * @param StoreManagerInterface $storeManager
7171 * @param ProductScopeRewriteGenerator $productScopeRewriteGenerator
7272 * @param DeleteEntitiesFromStores $deleteEntitiesFromStores
73- * @param Collection $productCollection
73+ * @param CollectionFactory $collectionFactory
7474 */
7575 public function __construct (
7676 ProductUrlRewriteGenerator $ productUrlRewriteGenerator ,
@@ -79,15 +79,15 @@ public function __construct(
7979 StoreManagerInterface $ storeManager ,
8080 ProductScopeRewriteGenerator $ productScopeRewriteGenerator ,
8181 DeleteEntitiesFromStores $ deleteEntitiesFromStores ,
82- Collection $ productCollection
82+ CollectionFactory $ collectionFactory
8383 ) {
8484 $ this ->productUrlRewriteGenerator = $ productUrlRewriteGenerator ;
8585 $ this ->urlPersist = $ urlPersist ;
8686 $ this ->productUrlPathGenerator = $ productUrlPathGenerator ;
8787 $ this ->storeManager = $ storeManager ;
8888 $ this ->productScopeRewriteGenerator = $ productScopeRewriteGenerator ;
8989 $ this ->deleteEntitiesFromStores = $ deleteEntitiesFromStores ;
90- $ this ->productCollection = $ productCollection ;
90+ $ this ->collectionFactory = $ collectionFactory ;
9191 }
9292
9393 /**
@@ -117,7 +117,8 @@ public function execute(Observer $observer)
117117
118118 $ storeIdsToRemove = [];
119119 $ productWebsiteMap = array_flip ($ product ->getWebsiteIds ());
120- $ storeVisibilities = $ this ->productCollection ->getAllAttributeValues (ProductInterface::VISIBILITY );
120+ $ storeVisibilities = $ this ->collectionFactory ->create ()
121+ ->getAllAttributeValues (ProductInterface::VISIBILITY );
121122 if ($ this ->productScopeRewriteGenerator ->isGlobalScope ($ product ->getStoreId ())) {
122123 //Remove any rewrite URLs for websites the product is not in, or is not visible in. Global Scope.
123124 foreach ($ this ->storeManager ->getStores () as $ store ) {
0 commit comments