Skip to content

Commit 66fa85b

Browse files
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - #14866: [Forwardport] Fix: Datepicker problem when using non en-US locale. (by @rostyslav-hymon) - #14864: [Forwardport] Fix/navigation order function (by @rostyslav-hymon) - #14863: [Forwardport] Use index sitemap name as prefix in split sitemaps (by @rostyslav-hymon) - #14862: [Forwardport] Fix a non well formed numeric value encountered on Magento/Directory/� (by @rostyslav-hymon) - #14851: [Forwardport] Invoice grid shows wrong shipping & handling for partial items invoice. It shows order's shipping & handling instead if invoiced shipping& handling charge (by @rostyslav-hymon) - #13776: [Port 2.3-develop] Move isAllowed method from AccessChangeQuoteControl to separate service (by @JeroenVanLeusden)
2 parents 48b9318 + 6579a6a commit 66fa85b

File tree

10 files changed

+134
-46
lines changed

10 files changed

+134
-46
lines changed

app/code/Magento/Customer/Block/Account/Navigation.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public function getLinks()
4646
*/
4747
private function compare(SortLinkInterface $firstLink, SortLinkInterface $secondLink)
4848
{
49-
return ($firstLink->getSortOrder() < $secondLink->getSortOrder());
49+
if ($firstLink->getSortOrder() == $secondLink->getSortOrder()) {
50+
return 0;
51+
}
52+
53+
return ($firstLink->getSortOrder() < $secondLink->getSortOrder()) ? 1 : -1;
5054
}
5155
}

app/code/Magento/Directory/Model/Currency.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function convert($price, $toCurrency = null)
225225
if ($toCurrency === null) {
226226
return $price;
227227
} elseif ($rate = $this->getRate($toCurrency)) {
228-
return $price * $rate;
228+
return floatval($price) * floatval($rate);
229229
}
230230

231231
throw new \Exception(__(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Quote\Api;
10+
11+
use Magento\Quote\Api\Data\CartInterface;
12+
13+
/**
14+
* Service checks if the user has ability to change the quote.
15+
*/
16+
interface ChangeQuoteControlInterface
17+
{
18+
/**
19+
* Checks if user is allowed to change the quote.
20+
*
21+
* @param CartInterface $quote
22+
* @return bool
23+
*/
24+
public function isAllowed(CartInterface $quote): bool;
25+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Quote\Model;
10+
11+
use Magento\Authorization\Model\UserContextInterface;
12+
use Magento\Quote\Api\ChangeQuoteControlInterface;
13+
use Magento\Quote\Api\Data\CartInterface;
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
class ChangeQuoteControl implements ChangeQuoteControlInterface
19+
{
20+
/**
21+
* @var UserContextInterface $userContext
22+
*/
23+
private $userContext;
24+
25+
/**
26+
* @param UserContextInterface $userContext
27+
*/
28+
public function __construct(UserContextInterface $userContext)
29+
{
30+
$this->userContext = $userContext;
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function isAllowed(CartInterface $quote): bool
37+
{
38+
switch ($this->userContext->getUserType()) {
39+
case UserContextInterface::USER_TYPE_CUSTOMER:
40+
$isAllowed = ($quote->getCustomerId() == $this->userContext->getUserId());
41+
break;
42+
case UserContextInterface::USER_TYPE_GUEST:
43+
$isAllowed = ($quote->getCustomerId() === null);
44+
break;
45+
case UserContextInterface::USER_TYPE_ADMIN:
46+
case UserContextInterface::USER_TYPE_INTEGRATION:
47+
$isAllowed = true;
48+
break;
49+
default:
50+
$isAllowed = false;
51+
}
52+
53+
return $isAllowed;
54+
}
55+
}

app/code/Magento/Quote/Model/QuoteRepository/Plugin/AccessChangeQuoteControl.php

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Quote\Model\QuoteRepository\Plugin;
78

8-
use Magento\Authorization\Model\UserContextInterface;
9-
use Magento\Quote\Model\Quote;
9+
use Magento\Quote\Api\ChangeQuoteControlInterface;
1010
use Magento\Framework\Exception\StateException;
1111
use Magento\Quote\Api\CartRepositoryInterface;
1212
use Magento\Quote\Api\Data\CartInterface;
@@ -17,59 +17,32 @@
1717
class AccessChangeQuoteControl
1818
{
1919
/**
20-
* @var UserContextInterface
20+
* @var ChangeQuoteControlInterface $changeQuoteControl
2121
*/
22-
private $userContext;
22+
private $changeQuoteControl;
2323

2424
/**
25-
* @param UserContextInterface $userContext
25+
* @param ChangeQuoteControlInterface $changeQuoteControl
2626
*/
27-
public function __construct(
28-
UserContextInterface $userContext
29-
) {
30-
$this->userContext = $userContext;
27+
public function __construct(ChangeQuoteControlInterface $changeQuoteControl)
28+
{
29+
$this->changeQuoteControl = $changeQuoteControl;
3130
}
3231

3332
/**
3433
* Checks if change quote's customer id is allowed for current user.
3534
*
3635
* @param CartRepositoryInterface $subject
37-
* @param Quote $quote
36+
* @param CartInterface $quote
3837
* @throws StateException if Guest has customer_id or Customer's customer_id not much with user_id
3938
* or unknown user's type
4039
* @return void
4140
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4241
*/
4342
public function beforeSave(CartRepositoryInterface $subject, CartInterface $quote)
4443
{
45-
if (!$this->isAllowed($quote)) {
44+
if (! $this->changeQuoteControl->isAllowed($quote)) {
4645
throw new StateException(__("Invalid state change requested"));
4746
}
4847
}
49-
50-
/**
51-
* Checks if user is allowed to change the quote.
52-
*
53-
* @param Quote $quote
54-
* @return bool
55-
*/
56-
private function isAllowed(Quote $quote)
57-
{
58-
switch ($this->userContext->getUserType()) {
59-
case UserContextInterface::USER_TYPE_CUSTOMER:
60-
$isAllowed = ($quote->getCustomerId() == $this->userContext->getUserId());
61-
break;
62-
case UserContextInterface::USER_TYPE_GUEST:
63-
$isAllowed = ($quote->getCustomerId() === null);
64-
break;
65-
case UserContextInterface::USER_TYPE_ADMIN:
66-
case UserContextInterface::USER_TYPE_INTEGRATION:
67-
$isAllowed = true;
68-
break;
69-
default:
70-
$isAllowed = false;
71-
}
72-
73-
return $isAllowed;
74-
}
7548
}

app/code/Magento/Quote/Test/Unit/Model/QuoteRepository/Plugin/AccessChangeQuoteControlTest.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Quote\Test\Unit\Model\QuoteRepository\Plugin;
78

89
use Magento\Authorization\Model\UserContextInterface;
10+
use Magento\Quote\Model\ChangeQuoteControl;
911
use Magento\Quote\Model\QuoteRepository\Plugin\AccessChangeQuoteControl;
1012
use Magento\Quote\Model\Quote;
1113
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
@@ -34,6 +36,11 @@ class AccessChangeQuoteControlTest extends \PHPUnit\Framework\TestCase
3436
*/
3537
private $quoteRepositoryMock;
3638

39+
/**
40+
* @var ChangeQuoteControl|MockObject
41+
*/
42+
private $changeQuoteControlMock;
43+
3744
protected function setUp()
3845
{
3946
$this->userContextMock = $this->getMockBuilder(UserContextInterface::class)
@@ -50,15 +57,19 @@ protected function setUp()
5057
->disableOriginalConstructor()
5158
->getMock();
5259

60+
$this->changeQuoteControlMock = $this->getMockBuilder(ChangeQuoteControl::class)
61+
->disableOriginalConstructor()
62+
->getMock();
63+
5364
$objectManagerHelper = new ObjectManager($this);
5465
$this->accessChangeQuoteControl = $objectManagerHelper->getObject(
5566
AccessChangeQuoteControl::class,
56-
['userContext' => $this->userContextMock]
67+
['changeQuoteControl' => $this->changeQuoteControlMock]
5768
);
5869
}
5970

6071
/**
61-
* User with role Customer and customer_id much with context user_id.
72+
* User with role Customer and customer_id matches context user_id.
6273
*/
6374
public function testBeforeSaveForCustomer()
6475
{
@@ -68,6 +79,9 @@ public function testBeforeSaveForCustomer()
6879
$this->userContextMock->method('getUserType')
6980
->willReturn(UserContextInterface::USER_TYPE_CUSTOMER);
7081

82+
$this->changeQuoteControlMock->method('isAllowed')
83+
->willReturn(true);
84+
7185
$result = $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
7286

7387
$this->assertNull($result);
@@ -81,11 +95,15 @@ public function testBeforeSaveForCustomer()
8195
*/
8296
public function testBeforeSaveException()
8397
{
84-
$this->userContextMock->method('getUserType')
85-
->willReturn(UserContextInterface::USER_TYPE_CUSTOMER);
8698
$this->quoteMock->method('getCustomerId')
8799
->willReturn(2);
88100

101+
$this->userContextMock->method('getUserType')
102+
->willReturn(UserContextInterface::USER_TYPE_CUSTOMER);
103+
104+
$this->changeQuoteControlMock->method('isAllowed')
105+
->willReturn(false);
106+
89107
$this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
90108
}
91109

@@ -100,6 +118,9 @@ public function testBeforeSaveForAdmin()
100118
$this->userContextMock->method('getUserType')
101119
->willReturn(UserContextInterface::USER_TYPE_ADMIN);
102120

121+
$this->changeQuoteControlMock->method('isAllowed')
122+
->willReturn(true);
123+
103124
$result = $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
104125

105126
$this->assertNull($result);
@@ -116,6 +137,9 @@ public function testBeforeSaveForGuest()
116137
$this->userContextMock->method('getUserType')
117138
->willReturn(UserContextInterface::USER_TYPE_GUEST);
118139

140+
$this->changeQuoteControlMock->method('isAllowed')
141+
->willReturn(true);
142+
119143
$result = $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
120144

121145
$this->assertNull($result);
@@ -135,6 +159,9 @@ public function testBeforeSaveForGuestException()
135159
$this->userContextMock->method('getUserType')
136160
->willReturn(UserContextInterface::USER_TYPE_GUEST);
137161

162+
$this->changeQuoteControlMock->method('isAllowed')
163+
->willReturn(false);
164+
138165
$this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
139166
}
140167

@@ -152,6 +179,9 @@ public function testBeforeSaveForUnknownUserTypeException()
152179
$this->userContextMock->method('getUserType')
153180
->willReturn(10);
154181

182+
$this->changeQuoteControlMock->method('isAllowed')
183+
->willReturn(false);
184+
155185
$this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
156186
}
157187
}

app/code/Magento/Quote/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<preference for="Magento\Quote\Api\CouponManagementInterface" type="Magento\Quote\Model\CouponManagement" />
2323
<preference for="Magento\Quote\Api\CartManagementInterface" type="Magento\Quote\Model\QuoteManagement" />
2424
<preference for="Magento\Quote\Api\CartTotalRepositoryInterface" type="Magento\Quote\Model\Cart\CartTotalRepository" />
25+
<preference for="Magento\Quote\Api\ChangeQuoteControlInterface" type="Magento\Quote\Model\ChangeQuoteControl" />
2526
<preference for="Magento\Quote\Api\CartTotalManagementInterface" type="Magento\Quote\Model\Cart\CartTotalManagement" />
2627
<preference for="Magento\Quote\Api\Data\TotalsInterface" type="Magento\Quote\Model\Cart\Totals" />
2728
<preference for="Magento\Quote\Api\Data\TotalSegmentInterface" type="Magento\Quote\Model\Cart\TotalSegment" />

app/code/Magento/Sales/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@
686686
<item name="shipping_address" xsi:type="object">ShippingAddressAggregator</item>
687687
<item name="shipping_information" xsi:type="string">sales_order.shipping_description</item>
688688
<item name="subtotal" xsi:type="string">sales_invoice.base_subtotal</item>
689-
<item name="shipping_and_handling" xsi:type="string">sales_order.base_shipping_amount</item>
689+
<item name="shipping_and_handling" xsi:type="string">sales_invoice.base_shipping_amount</item>
690690
<item name="base_grand_total" xsi:type="string">sales_invoice.base_grand_total</item>
691691
<item name="grand_total" xsi:type="string">sales_invoice.grand_total</item>
692692
<item name="created_at" xsi:type="string">sales_invoice.created_at</item>

app/code/Magento/Sitemap/Model/Sitemap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ protected function _finalizeSitemap($type = self::TYPE_URL)
646646
*/
647647
protected function _getCurrentSitemapFilename($index)
648648
{
649-
return self::INDEX_FILE_PREFIX . '-' . $this->getStoreId() . '-' . $index . '.xml';
649+
return str_replace('.xml', '', $this->getSitemapFilename()) . '-' . $this->getStoreId() . '-' . $index . '.xml';
650650
}
651651

652652
/**

lib/web/mage/utils/misc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ define([
271271
convertToMomentFormat: function (format) {
272272
var newFormat;
273273

274-
newFormat = format.replace(/yy|y/gi, 'YYYY'); // replace the year
274+
newFormat = format.replace(/yyyy|yy|y/, 'YYYY'); // replace the year
275275
newFormat = newFormat.replace(/dd|d/g, 'DD'); // replace the date
276276

277277
return newFormat;

0 commit comments

Comments
 (0)