-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔃 [EngCom] Public Pull Requests - 2.3-develop Minor Fixes
Accepted Public Pull Requests: - #21778: Multishipping checkout agreements now are the same as default checkout agreements (by @samuel27m) - #20774: 20434 consider url rewrite when change product visibility attribute 2 3 (by @VitaliyBoyko) - #21283: Fixed calculation of 'Total' column under "Last Orders" listing on the admin dashboard (by @rav-redchamps) - #19727: Use repository to load order when manually creating an invoice (by @JeroenVanLeusden) - #20212: Secure errors directory (by @schmengler) - #21899: Trigger contentUpdate on reviews load (by @jahvi) - #21621: Updated review text in admin menu (by @gelanivishal) - #21880: #21001 - fix unit tests, by passing currency to numbe� (by @kdegorski) - #21825: When setting `background` for labels explicitly the labels in admin will (by @TomashKhamlai) Fixed GitHub Issues: - #20434: Product URL duplicate when changing visibility via mass action (reported by @laurentplenet) has been fixed in #20774 by @VitaliyBoyko in 2.3-develop branch Related commits: 1. 24382e3 2. 4d18c9a 3. 6a5776c 4. f2088d9 5. 4edec38 6. a8d1dc0 7. 5687704 8. c865bdc 9. 1c608d7 10. a80943f 11. a8d9be1 - #18754: Negative order amount in dashboard latest order when order is cancelled where coupon has been used (reported by @albsa) has been fixed in #21283 by @rav-redchamps in 2.3-develop branch Related commits: 1. d79eb08 2. d1e71b9 3. f893a92 4. 57c4db4 - #21281: Wrong order amount on dashboard on Last orders listing when order has discount and it is partially refunded (reported by @rav-redchamps) has been fixed in #21283 by @rav-redchamps in 2.3-develop branch Related commits: 1. d79eb08 2. d1e71b9 3. f893a92 4. 57c4db4 - #20209: errors/local.xml and error page templates are publicly accessible (reported by @schmengler) has been fixed in #20212 by @schmengler in 2.3-develop branch Related commits: 1. a0566ab - #21620: Update title of Review content (reported by @sanganinamrata) has been fixed in #21621 by @gelanivishal in 2.3-develop branch Related commits: 1. ae9084d 2. b622401 3. 417fda4 4. 44ddbab - #21001: Unit Tests failed (reported by @azngeek) has been fixed in #21880 by @kdegorski in 2.3-develop branch Related commits: 1. b96435f 2. 8d7b964 3. 3825545
- Loading branch information
Showing
23 changed files
with
635 additions
and
56 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
app/code/Magento/CatalogUrlRewrite/Model/Products/AdaptUrlRewritesToVisibilityAttribute.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,127 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogUrlRewrite\Model\Products; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Visibility; | ||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; | ||
use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator; | ||
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator; | ||
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException; | ||
use Magento\UrlRewrite\Model\UrlPersistInterface; | ||
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; | ||
|
||
/** | ||
* Save/Delete UrlRewrites by Product ID's and visibility | ||
*/ | ||
class AdaptUrlRewritesToVisibilityAttribute | ||
{ | ||
/** | ||
* @var CollectionFactory | ||
*/ | ||
private $productCollectionFactory; | ||
|
||
/** | ||
* @var ProductUrlRewriteGenerator | ||
*/ | ||
private $urlRewriteGenerator; | ||
|
||
/** | ||
* @var UrlPersistInterface | ||
*/ | ||
private $urlPersist; | ||
|
||
/** | ||
* @var ProductUrlPathGenerator | ||
*/ | ||
private $urlPathGenerator; | ||
|
||
/** | ||
* @param CollectionFactory $collectionFactory | ||
* @param ProductUrlRewriteGenerator $urlRewriteGenerator | ||
* @param UrlPersistInterface $urlPersist | ||
* @param ProductUrlPathGenerator|null $urlPathGenerator | ||
*/ | ||
public function __construct( | ||
CollectionFactory $collectionFactory, | ||
ProductUrlRewriteGenerator $urlRewriteGenerator, | ||
UrlPersistInterface $urlPersist, | ||
ProductUrlPathGenerator $urlPathGenerator | ||
) { | ||
$this->productCollectionFactory = $collectionFactory; | ||
$this->urlRewriteGenerator = $urlRewriteGenerator; | ||
$this->urlPersist = $urlPersist; | ||
$this->urlPathGenerator = $urlPathGenerator; | ||
} | ||
|
||
/** | ||
* Process Url Rewrites according to the products visibility attribute | ||
* | ||
* @param array $productIds | ||
* @param int $visibility | ||
* @throws UrlAlreadyExistsException | ||
*/ | ||
public function execute(array $productIds, int $visibility): void | ||
{ | ||
$products = $this->getProductsByIds($productIds); | ||
|
||
/** @var Product $product */ | ||
foreach ($products as $product) { | ||
if ($visibility == Visibility::VISIBILITY_NOT_VISIBLE) { | ||
$this->urlPersist->deleteByData( | ||
[ | ||
UrlRewrite::ENTITY_ID => $product->getId(), | ||
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE, | ||
] | ||
); | ||
} elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) { | ||
$product->setVisibility($visibility); | ||
$productUrlPath = $this->urlPathGenerator->getUrlPath($product); | ||
$productUrlRewrite = $this->urlRewriteGenerator->generate($product); | ||
$product->unsUrlPath(); | ||
$product->setUrlPath($productUrlPath); | ||
|
||
try { | ||
$this->urlPersist->replace($productUrlRewrite); | ||
} catch (UrlAlreadyExistsException $e) { | ||
throw new UrlAlreadyExistsException( | ||
__( | ||
'Can not change the visibility of the product with SKU equals "%1". ' | ||
. 'URL key "%2" for specified store already exists.', | ||
$product->getSku(), | ||
$product->getUrlKey() | ||
), | ||
$e, | ||
$e->getCode(), | ||
$e->getUrls() | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get Product Models by Id's | ||
* | ||
* @param array $productIds | ||
* @return array | ||
*/ | ||
private function getProductsByIds(array $productIds): array | ||
{ | ||
$productCollection = $this->productCollectionFactory->create(); | ||
$productCollection->addAttributeToSelect(ProductInterface::VISIBILITY); | ||
$productCollection->addAttributeToSelect('url_key'); | ||
$productCollection->addFieldToFilter( | ||
'entity_id', | ||
['in' => array_unique($productIds)] | ||
); | ||
|
||
return $productCollection->getItems(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...Magento/CatalogUrlRewrite/Observer/ProcessUrlRewriteOnChangeProductVisibilityObserver.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,54 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogUrlRewrite\Observer; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\CatalogUrlRewrite\Model\Products\AdaptUrlRewritesToVisibilityAttribute; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException; | ||
|
||
/** | ||
* Consider URL rewrites on change product visibility via mass action | ||
*/ | ||
class ProcessUrlRewriteOnChangeProductVisibilityObserver implements ObserverInterface | ||
{ | ||
/** | ||
* @var AdaptUrlRewritesToVisibilityAttribute | ||
*/ | ||
private $adaptUrlRewritesToVisibility; | ||
|
||
/** | ||
* @param AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility | ||
*/ | ||
public function __construct(AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility) | ||
{ | ||
$this->adaptUrlRewritesToVisibility = $adaptUrlRewritesToVisibility; | ||
} | ||
|
||
/** | ||
* Generate urls for UrlRewrites and save it in storage | ||
* | ||
* @param Observer $observer | ||
* @return void | ||
* @throws UrlAlreadyExistsException | ||
*/ | ||
public function execute(Observer $observer) | ||
{ | ||
$event = $observer->getEvent(); | ||
$attrData = $event->getAttributesData(); | ||
$productIds = $event->getProductIds(); | ||
$visibility = $attrData[ProductInterface::VISIBILITY] ?? 0; | ||
|
||
if (!$visibility || !$productIds) { | ||
return; | ||
} | ||
|
||
$this->adaptUrlRewritesToVisibility->execute($productIds, (int)$visibility); | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
* See COPYING.txt for license details. | ||
*/ | ||
|
||
// @deprecated | ||
// @codingStandardsIgnoreFile | ||
|
||
?> | ||
|
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
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
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
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
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.