Skip to content

Commit 4f6c78e

Browse files
🔃 [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
2 parents 0d881fc + 637a6af commit 4f6c78e

File tree

23 files changed

+635
-56
lines changed

23 files changed

+635
-56
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogUrlRewrite\Model\Products;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\Product\Visibility;
13+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
14+
use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
15+
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
16+
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
17+
use Magento\UrlRewrite\Model\UrlPersistInterface;
18+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
19+
20+
/**
21+
* Save/Delete UrlRewrites by Product ID's and visibility
22+
*/
23+
class AdaptUrlRewritesToVisibilityAttribute
24+
{
25+
/**
26+
* @var CollectionFactory
27+
*/
28+
private $productCollectionFactory;
29+
30+
/**
31+
* @var ProductUrlRewriteGenerator
32+
*/
33+
private $urlRewriteGenerator;
34+
35+
/**
36+
* @var UrlPersistInterface
37+
*/
38+
private $urlPersist;
39+
40+
/**
41+
* @var ProductUrlPathGenerator
42+
*/
43+
private $urlPathGenerator;
44+
45+
/**
46+
* @param CollectionFactory $collectionFactory
47+
* @param ProductUrlRewriteGenerator $urlRewriteGenerator
48+
* @param UrlPersistInterface $urlPersist
49+
* @param ProductUrlPathGenerator|null $urlPathGenerator
50+
*/
51+
public function __construct(
52+
CollectionFactory $collectionFactory,
53+
ProductUrlRewriteGenerator $urlRewriteGenerator,
54+
UrlPersistInterface $urlPersist,
55+
ProductUrlPathGenerator $urlPathGenerator
56+
) {
57+
$this->productCollectionFactory = $collectionFactory;
58+
$this->urlRewriteGenerator = $urlRewriteGenerator;
59+
$this->urlPersist = $urlPersist;
60+
$this->urlPathGenerator = $urlPathGenerator;
61+
}
62+
63+
/**
64+
* Process Url Rewrites according to the products visibility attribute
65+
*
66+
* @param array $productIds
67+
* @param int $visibility
68+
* @throws UrlAlreadyExistsException
69+
*/
70+
public function execute(array $productIds, int $visibility): void
71+
{
72+
$products = $this->getProductsByIds($productIds);
73+
74+
/** @var Product $product */
75+
foreach ($products as $product) {
76+
if ($visibility == Visibility::VISIBILITY_NOT_VISIBLE) {
77+
$this->urlPersist->deleteByData(
78+
[
79+
UrlRewrite::ENTITY_ID => $product->getId(),
80+
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
81+
]
82+
);
83+
} elseif ($visibility !== Visibility::VISIBILITY_NOT_VISIBLE) {
84+
$product->setVisibility($visibility);
85+
$productUrlPath = $this->urlPathGenerator->getUrlPath($product);
86+
$productUrlRewrite = $this->urlRewriteGenerator->generate($product);
87+
$product->unsUrlPath();
88+
$product->setUrlPath($productUrlPath);
89+
90+
try {
91+
$this->urlPersist->replace($productUrlRewrite);
92+
} catch (UrlAlreadyExistsException $e) {
93+
throw new UrlAlreadyExistsException(
94+
__(
95+
'Can not change the visibility of the product with SKU equals "%1". '
96+
. 'URL key "%2" for specified store already exists.',
97+
$product->getSku(),
98+
$product->getUrlKey()
99+
),
100+
$e,
101+
$e->getCode(),
102+
$e->getUrls()
103+
);
104+
}
105+
}
106+
}
107+
}
108+
109+
/**
110+
* Get Product Models by Id's
111+
*
112+
* @param array $productIds
113+
* @return array
114+
*/
115+
private function getProductsByIds(array $productIds): array
116+
{
117+
$productCollection = $this->productCollectionFactory->create();
118+
$productCollection->addAttributeToSelect(ProductInterface::VISIBILITY);
119+
$productCollection->addAttributeToSelect('url_key');
120+
$productCollection->addFieldToFilter(
121+
'entity_id',
122+
['in' => array_unique($productIds)]
123+
);
124+
125+
return $productCollection->getItems();
126+
}
127+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogUrlRewrite\Observer;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\CatalogUrlRewrite\Model\Products\AdaptUrlRewritesToVisibilityAttribute;
12+
use Magento\Framework\Event\Observer;
13+
use Magento\Framework\Event\ObserverInterface;
14+
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
15+
16+
/**
17+
* Consider URL rewrites on change product visibility via mass action
18+
*/
19+
class ProcessUrlRewriteOnChangeProductVisibilityObserver implements ObserverInterface
20+
{
21+
/**
22+
* @var AdaptUrlRewritesToVisibilityAttribute
23+
*/
24+
private $adaptUrlRewritesToVisibility;
25+
26+
/**
27+
* @param AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility
28+
*/
29+
public function __construct(AdaptUrlRewritesToVisibilityAttribute $adaptUrlRewritesToVisibility)
30+
{
31+
$this->adaptUrlRewritesToVisibility = $adaptUrlRewritesToVisibility;
32+
}
33+
34+
/**
35+
* Generate urls for UrlRewrites and save it in storage
36+
*
37+
* @param Observer $observer
38+
* @return void
39+
* @throws UrlAlreadyExistsException
40+
*/
41+
public function execute(Observer $observer)
42+
{
43+
$event = $observer->getEvent();
44+
$attrData = $event->getAttributesData();
45+
$productIds = $event->getProductIds();
46+
$visibility = $attrData[ProductInterface::VISIBILITY] ?? 0;
47+
48+
if (!$visibility || !$productIds) {
49+
return;
50+
}
51+
52+
$this->adaptUrlRewritesToVisibility->execute($productIds, (int)$visibility);
53+
}
54+
}

app/code/Magento/CatalogUrlRewrite/etc/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<event name="catalog_product_save_after">
2828
<observer name="process_url_rewrite_saving" instance="Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver"/>
2929
</event>
30+
<event name="catalog_product_attribute_update_before">
31+
<observer name="process_url_rewrite_on_change_product_visibility" instance="Magento\CatalogUrlRewrite\Observer\ProcessUrlRewriteOnChangeProductVisibilityObserver"/>
32+
</event>
3033
<event name="catalog_category_save_before">
3134
<observer name="category_url_path_autogeneration" instance="Magento\CatalogUrlRewrite\Observer\CategoryUrlPathAutogeneratorObserver"/>
3235
</event>

app/code/Magento/CheckoutAgreements/view/frontend/layout/multishipping_checkout_overview.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<body>
1010
<referenceBlock name="checkout_overview">
11-
<block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::multishipping_agreements.phtml"/>
11+
<block class="Magento\CheckoutAgreements\Block\Agreements" name="checkout.multishipping.agreements" as="agreements" template="Magento_CheckoutAgreements::additional_agreements.phtml"/>
1212
</referenceBlock>
1313
</body>
1414
</page>

app/code/Magento/CheckoutAgreements/view/frontend/templates/multishipping_agreements.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
// @deprecated
78
// @codingStandardsIgnoreFile
89

910
?>

app/code/Magento/Multishipping/view/frontend/web/js/overview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ define([
1515
opacity: 0.5, // CSS opacity for the 'Place Order' button when it's clicked and then disabled.
1616
pleaseWaitLoader: 'span.please-wait', // 'Submitting order information...' Ajax loader.
1717
placeOrderSubmit: 'button[type="submit"]', // The 'Place Order' button.
18-
agreements: '#checkout-agreements' // Container for all of the checkout agreements and terms/conditions
18+
agreements: '.checkout-agreements' // Container for all of the checkout agreements and terms/conditions
1919
},
2020

2121
/**

app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,12 @@ public function addOrdersCount()
769769
*/
770770
public function addRevenueToSelect($convertCurrency = false)
771771
{
772-
$expr = $this->getTotalsExpression(
772+
$expr = $this->getTotalsExpressionWithDiscountRefunded(
773773
!$convertCurrency,
774774
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
775775
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
776-
$this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0)
776+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0),
777+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0)
777778
);
778779
$this->getSelect()->columns(['revenue' => $expr]);
779780

@@ -791,11 +792,12 @@ public function addSumAvgTotals($storeId = 0)
791792
/**
792793
* calculate average and total amount
793794
*/
794-
$expr = $this->getTotalsExpression(
795+
$expr = $this->getTotalsExpressionWithDiscountRefunded(
795796
$storeId,
796797
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
797798
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
798-
$this->getConnection()->getIfNullSql('main_table.base_discount_canceled', 0)
799+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_refunded)', 0),
800+
$this->getConnection()->getIfNullSql('ABS(main_table.base_discount_canceled)', 0)
799801
);
800802

801803
$this->getSelect()->columns(
@@ -808,13 +810,15 @@ public function addSumAvgTotals($storeId = 0)
808810
}
809811

810812
/**
811-
* Get SQL expression for totals
813+
* Get SQL expression for totals.
812814
*
813815
* @param int $storeId
814816
* @param string $baseSubtotalRefunded
815817
* @param string $baseSubtotalCanceled
816818
* @param string $baseDiscountCanceled
817819
* @return string
820+
* @deprecated
821+
* @see getTotalsExpressionWithDiscountRefunded
818822
*/
819823
protected function getTotalsExpression(
820824
$storeId,
@@ -825,10 +829,40 @@ protected function getTotalsExpression(
825829
$template = ($storeId != 0)
826830
? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) - %3$s)'
827831
: '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s) '
828-
. ' * main_table.base_to_global_rate)';
832+
. ' * main_table.base_to_global_rate)';
829833
return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountCanceled);
830834
}
831835

836+
/**
837+
* Get SQL expression for totals with discount refunded.
838+
*
839+
* @param int $storeId
840+
* @param string $baseSubtotalRefunded
841+
* @param string $baseSubtotalCanceled
842+
* @param string $baseDiscountRefunded
843+
* @param string $baseDiscountCanceled
844+
* @return string
845+
*/
846+
private function getTotalsExpressionWithDiscountRefunded(
847+
$storeId,
848+
$baseSubtotalRefunded,
849+
$baseSubtotalCanceled,
850+
$baseDiscountRefunded,
851+
$baseDiscountCanceled
852+
) {
853+
$template = ($storeId != 0)
854+
? '(main_table.base_subtotal - %2$s - %1$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s))'
855+
: '((main_table.base_subtotal - %1$s - %2$s - (ABS(main_table.base_discount_amount) - %3$s - %4$s)) '
856+
. ' * main_table.base_to_global_rate)';
857+
return sprintf(
858+
$template,
859+
$baseSubtotalRefunded,
860+
$baseSubtotalCanceled,
861+
$baseDiscountRefunded,
862+
$baseDiscountCanceled
863+
);
864+
}
865+
832866
/**
833867
* Sort order by total amount
834868
*

app/code/Magento/Review/etc/acl.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
</resource>
1717
<resource id="Magento_Backend::marketing">
1818
<resource id="Magento_Backend::marketing_user_content">
19-
<resource id="Magento_Review::reviews_all" title="Reviews" translate="title" sortOrder="10"/>
2019
<resource id="Magento_Review::pending" title="Pending Reviews" translate="title" sortOrder="20"/>
20+
<resource id="Magento_Review::reviews_all" title="All Reviews" translate="title" sortOrder="10"/>
2121
</resource>
2222
</resource>
2323
</resource>

app/code/Magento/Review/etc/adminhtml/menu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
99
<menu>
1010
<add id="Magento_Review::catalog_reviews_ratings_ratings" title="Rating" translate="title" module="Magento_Review" sortOrder="60" parent="Magento_Backend::stores_attributes" action="review/rating/" resource="Magento_Review::ratings"/>
11-
<add id="Magento_Review::catalog_reviews_ratings_reviews_all" title="Reviews" translate="title" module="Magento_Review" parent="Magento_Backend::marketing_user_content" sortOrder="10" action="review/product/index" resource="Magento_Review::reviews_all"/>
1211
<add id="Magento_Review::catalog_reviews_ratings_pending" title="Pending Reviews" translate="title" module="Magento_Review" parent="Magento_Backend::marketing_user_content" sortOrder="20" action="review/product/pending" resource="Magento_Review::pending"/>
12+
<add id="Magento_Review::catalog_reviews_ratings_reviews_all" title="All Reviews" translate="title" module="Magento_Review" parent="Magento_Backend::marketing_user_content" sortOrder="10" action="review/product/index" resource="Magento_Review::reviews_all"/>
1313
<add id="Magento_Review::report_review" title="Reviews" translate="title" module="Magento_Reports" sortOrder="20" parent="Magento_Reports::report" resource="Magento_Reports::review"/>
1414
<add id="Magento_Review::report_review_customer" title="By Customers" translate="title" sortOrder="10" module="Magento_Review" parent="Magento_Review::report_review" action="reports/report_review/customer" resource="Magento_Reports::review_customer"/>
1515
<add id="Magento_Review::report_review_product" title="By Products" translate="title" sortOrder="20" module="Magento_Review" parent="Magento_Review::report_review" action="reports/report_review/product" resource="Magento_Reports::review_product"/>

app/code/Magento/Review/view/frontend/web/js/process-reviews.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define([
2020
showLoader: false,
2121
loaderContext: $('.product.data.items')
2222
}).done(function (data) {
23-
$('#product-review-container').html(data);
23+
$('#product-review-container').html(data).trigger('contentUpdated');
2424
$('[data-role="product-review"] .pages a').each(function (index, element) {
2525
$(element).click(function (event) { //eslint-disable-line max-nested-callbacks
2626
processReviews($(element).attr('href'), true);

0 commit comments

Comments
 (0)