-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop
Accepted Community Pull Requests: - #26999: Fixed URL Rewrite addition/removal on product website add/remove (by @gwharton)
- Loading branch information
Showing
48 changed files
with
236 additions
and
1,534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
app/code/Magento/CatalogUrlRewrite/Observer/ProductToWebsiteChangeObserver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogUrlRewrite\Observer; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product\Visibility; | ||
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Store\Model\Store; | ||
use Magento\UrlRewrite\Model\UrlPersistInterface; | ||
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; | ||
use Magento\Store\Api\StoreWebsiteRelationInterface; | ||
use Magento\Framework\App\ObjectManager; | ||
|
||
/** | ||
* Observer to assign the products to website | ||
*/ | ||
class ProductToWebsiteChangeObserver implements ObserverInterface | ||
{ | ||
/** | ||
* @var ProductUrlRewriteGenerator | ||
*/ | ||
protected $productUrlRewriteGenerator; | ||
|
||
/** | ||
* @var UrlPersistInterface | ||
*/ | ||
protected $urlPersist; | ||
|
||
/** | ||
* @var ProductRepositoryInterface | ||
*/ | ||
protected $productRepository; | ||
|
||
/** | ||
* @var RequestInterface | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* @var StoreWebsiteRelationInterface | ||
*/ | ||
private $storeWebsiteRelation; | ||
|
||
/** | ||
* @param ProductUrlRewriteGenerator $productUrlRewriteGenerator | ||
* @param UrlPersistInterface $urlPersist | ||
* @param ProductRepositoryInterface $productRepository | ||
* @param RequestInterface $request | ||
* @param StoreWebsiteRelationInterface $storeWebsiteRelation | ||
*/ | ||
public function __construct( | ||
ProductUrlRewriteGenerator $productUrlRewriteGenerator, | ||
UrlPersistInterface $urlPersist, | ||
ProductRepositoryInterface $productRepository, | ||
RequestInterface $request, | ||
StoreWebsiteRelationInterface $storeWebsiteRelation = null | ||
) { | ||
$this->productUrlRewriteGenerator = $productUrlRewriteGenerator; | ||
$this->urlPersist = $urlPersist; | ||
$this->productRepository = $productRepository; | ||
$this->request = $request; | ||
$this->storeWebsiteRelation = $storeWebsiteRelation ?: | ||
ObjectManager::getInstance()->get(StoreWebsiteRelationInterface::class); | ||
} | ||
|
||
/** | ||
* Generate urls for UrlRewrite and save it in storage | ||
* | ||
* @param \Magento\Framework\Event\Observer $observer | ||
* @return void | ||
*/ | ||
public function execute(\Magento\Framework\Event\Observer $observer) | ||
{ | ||
foreach ($observer->getEvent()->getProducts() as $productId) { | ||
$product = $this->productRepository->getById( | ||
$productId, | ||
false, | ||
$this->request->getParam('store_id', Store::DEFAULT_STORE_ID) | ||
); | ||
|
||
if (!empty($this->productUrlRewriteGenerator->generate($product))) { | ||
if ($this->request->getParam('remove_website_ids')) { | ||
foreach ($this->request->getParam('remove_website_ids') as $webId) { | ||
foreach ($this->storeWebsiteRelation->getStoreByWebsiteId($webId) as $storeId) { | ||
$this->urlPersist->deleteByData([ | ||
UrlRewrite::ENTITY_ID => $product->getId(), | ||
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, | ||
UrlRewrite::STORE_ID => $storeId | ||
]); | ||
} | ||
} | ||
} | ||
if ($product->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE) { | ||
$this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product)); | ||
} | ||
} | ||
} | ||
} | ||
} |
128 changes: 0 additions & 128 deletions
128
app/code/Magento/CatalogUrlRewrite/Plugin/ProductProcessUrlRewriteRemovingPlugin.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.