Skip to content

Commit 1366ae5

Browse files
Merge pull request magento#9302 from adobe-commerce-tier-4/PR-14-10-2024
[Support Tier-4 chittima] 14-10-2024 Regular delivery of bugfixes and improvements
2 parents d75cff2 + d179c9b commit 1366ae5

File tree

20 files changed

+432
-186
lines changed

20 files changed

+432
-186
lines changed

app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/PriceTiers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -182,7 +182,7 @@ private function formatTierPrices(float $productPrice, string $currencyCode, $ti
182182
"discount" => $discount,
183183
"quantity" => $tierPrice->getQty(),
184184
"final_price" => [
185-
"value" => $tierPrice->getValue() * $tierPrice->getQty(),
185+
"value" => $tierPrice->getValue(),
186186
"currency" => $currencyCode
187187
]
188188
];

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\CatalogSearch\Model\Indexer;
@@ -123,7 +123,7 @@ public function __construct(
123123
IndexSwitcherInterface $indexSwitcher,
124124
StateFactory $indexScopeStateFactory,
125125
DimensionProviderInterface $dimensionProvider,
126-
array $data,
126+
array $data = [],
127127
ProcessManager $processManager = null,
128128
?int $batchSize = null,
129129
?DeploymentConfig $deploymentConfig = null

app/code/Magento/Customer/Helper/View.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Customer\Helper;
77

@@ -68,6 +68,6 @@ public function getCustomerName(CustomerInterface $customerData)
6868
$name .= ' ' . __($customerData->getSuffix());
6969
}
7070

71-
return $this->escaper->escapeHtml($name);
71+
return $name;
7272
}
7373
}

app/code/Magento/Customer/Test/Unit/Helper/ViewTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -54,9 +54,7 @@ protected function setUp(): void
5454
*/
5555
public function testGetCustomerName($prefix, $firstName, $middleName, $lastName, $suffix, $result)
5656
{
57-
$customerData = $this->getMockBuilder(CustomerInterface::class)
58-
->disableOriginalConstructor()
59-
->getMockForAbstractClass();
57+
$customerData = $this->createMock(CustomerInterface::class);
6058
$customerData->expects($this->any())
6159
->method('getPrefix')->willReturn($prefix);
6260
$customerData->expects($this->any())
@@ -67,7 +65,7 @@ public function testGetCustomerName($prefix, $firstName, $middleName, $lastName,
6765
->method('getLastname')->willReturn($lastName);
6866
$customerData->expects($this->any())
6967
->method('getSuffix')->willReturn($suffix);
70-
$this->escaperMock->expects($this->once())->method('escapeHtml')->with($result)->willReturn($result);
68+
$this->escaperMock->expects(self::never())->method('escapeHtml');
7169
$this->assertEquals($result, $this->object->getCustomerName($customerData));
7270
}
7371

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/Db/VersionControl/AddressSnapshotTest.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2016 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\Customer\Test\Unit\Model\ResourceModel\Db\VersionControl;
99

1010
use Magento\Customer\Model\ResourceModel\Db\VersionControl\AddressSnapshot;
1111
use Magento\Framework\DataObject;
12+
use Magento\Framework\Exception\LocalizedException;
1213
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Metadata;
14+
use Magento\Framework\Serialize\SerializerInterface;
1315
use PHPUnit\Framework\MockObject\MockObject;
1416
use PHPUnit\Framework\TestCase;
1517

@@ -18,22 +20,30 @@ class AddressSnapshotTest extends TestCase
1820
/**
1921
* @var AddressSnapshot
2022
*/
21-
private $model;
23+
private AddressSnapshot $model;
2224

2325
/**
2426
* @var Metadata|MockObject
2527
*/
26-
private $metadataMock;
28+
private Metadata $metadataMock;
2729

30+
/**
31+
* @var SerializerInterface|MockObject
32+
*/
33+
private SerializerInterface $serializer;
34+
35+
/**
36+
* @return void
37+
* @throws \PHPUnit\Framework\MockObject\Exception
38+
*/
2839
protected function setUp(): void
2940
{
30-
$this->metadataMock = $this->getMockBuilder(
31-
Metadata::class
32-
)->disableOriginalConstructor()
33-
->getMock();
41+
$this->metadataMock = $this->createMock(Metadata::class);
42+
$this->serializer = $this->createMock(SerializerInterface::class);
3443

3544
$this->model = new AddressSnapshot(
36-
$this->metadataMock
45+
$this->metadataMock,
46+
$this->serializer
3747
);
3848
}
3949

@@ -43,13 +53,10 @@ protected function setUp(): void
4353
* @param int $isDefaultShipping
4454
* @param bool $expected
4555
* @dataProvider dataProviderIsModified
56+
* @throws LocalizedException
4657
*/
47-
public function testIsModified(
48-
$isCustomerSaveTransaction,
49-
$isDefaultBilling,
50-
$isDefaultShipping,
51-
$expected
52-
) {
58+
public function testIsModified($isCustomerSaveTransaction, $isDefaultBilling, $isDefaultShipping, $expected): void
59+
{
5360
$entityId = 1;
5461

5562
$dataObjectMock = $this->getMockBuilder(DataObject::class)
@@ -96,7 +103,7 @@ public function testIsModified(
96103
/**
97104
* @return array
98105
*/
99-
public static function dataProviderIsModified()
106+
public static function dataProviderIsModified(): array
100107
{
101108
return [
102109
[false, 1, 1, true],
@@ -106,7 +113,11 @@ public static function dataProviderIsModified()
106113
];
107114
}
108115

109-
public function testIsModifiedBypass()
116+
/**
117+
* @return void
118+
* @throws LocalizedException
119+
*/
120+
public function testIsModifiedBypass(): void
110121
{
111122
$dataObjectMock = $this->getMockBuilder(DataObject::class)
112123
->disableOriginalConstructor()

app/code/Magento/Quote/Model/QuoteValidator.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Quote\Model;
@@ -14,7 +14,6 @@
1414
use Magento\Quote\Model\Quote as QuoteEntity;
1515
use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage as OrderAmountValidationMessage;
1616
use Magento\Quote\Model\ValidationRules\QuoteValidationRuleInterface;
17-
use Magento\Framework\Webapi\Rest\Response as RestResponse;
1817

1918
/**
2019
* Class to validate the quote
@@ -44,32 +43,24 @@ class QuoteValidator
4443
*/
4544
private $quoteValidationRule;
4645

47-
/**
48-
* @var RestResponse
49-
*/
50-
private $_response;
51-
5246
/**
5347
* QuoteValidator constructor.
5448
*
5549
* @param AllowedCountries|null $allowedCountryReader
5650
* @param OrderAmountValidationMessage|null $minimumAmountMessage
5751
* @param QuoteValidationRuleInterface|null $quoteValidationRule
58-
* @param RestResponse|null $response
5952
*/
6053
public function __construct(
6154
AllowedCountries $allowedCountryReader = null,
6255
OrderAmountValidationMessage $minimumAmountMessage = null,
63-
QuoteValidationRuleInterface $quoteValidationRule = null,
64-
RestResponse $response = null
56+
QuoteValidationRuleInterface $quoteValidationRule = null
6557
) {
6658
$this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance()
6759
->get(AllowedCountries::class);
6860
$this->minimumAmountMessage = $minimumAmountMessage ?: ObjectManager::getInstance()
6961
->get(OrderAmountValidationMessage::class);
7062
$this->quoteValidationRule = $quoteValidationRule ?: ObjectManager::getInstance()
7163
->get(QuoteValidationRuleInterface::class);
72-
$this->_response = $response ?: ObjectManager::getInstance()->get(RestResponse::class);
7364
}
7465

7566
/**
@@ -115,7 +106,6 @@ public function validateBeforeSubmit(QuoteEntity $quote)
115106
$defaultMessage .= ' %1';
116107
}
117108
if ($defaultMessage) {
118-
$this->_response->setHeader('errorRedirectAction', '#shipping');
119109
throw new ValidatorException(__($defaultMessage, implode(' ', $messages)));
120110
}
121111
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Quote\Plugin\Webapi\Model;
9+
10+
use Magento\Framework\Validator\Exception as ValidatorException;
11+
use Magento\Framework\Webapi\Rest\Response as RestResponse;
12+
use Magento\Quote\Model\Quote;
13+
use Magento\Quote\Model\QuoteValidator;
14+
15+
class ErrorRedirectProcessor
16+
{
17+
/**
18+
* @param RestResponse $restResponse
19+
*/
20+
public function __construct(
21+
private readonly RestResponse $restResponse
22+
) {
23+
}
24+
25+
/**
26+
* Set errorRedirectAction in case of exception.
27+
*
28+
* @param QuoteValidator $subject
29+
* @param callable $proceed
30+
* @param Quote $quote
31+
*/
32+
public function aroundValidateBeforeSubmit(QuoteValidator $subject, callable $proceed, Quote $quote)
33+
{
34+
try {
35+
$result = $proceed($quote);
36+
} catch (ValidatorException $e) {
37+
$this->restResponse->setHeader('errorRedirectAction', '#shipping');
38+
throw $e;
39+
}
40+
41+
return $result;
42+
}
43+
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2014 Adobe
5+
* All Rights Reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
@@ -23,4 +23,7 @@
2323
<type name="Magento\Quote\Api\CartRepositoryInterface">
2424
<plugin name="quoteValidateOrderId" type="Magento\Quote\Plugin\ValidateQuoteOrigOrder"/>
2525
</type>
26+
<type name="Magento\Quote\Model\QuoteValidator">
27+
<plugin name="error_redirect_processor" type="Magento\Quote\Plugin\Webapi\Model\ErrorRedirectProcessor" />
28+
</type>
2629
</config>

app/code/Magento/SalesRule/Model/Quote/Discount.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\SalesRule\Model\Quote;
77

@@ -221,7 +221,15 @@ public function collect(
221221
unset($itemsToApplyRules[$key]);
222222
}
223223

224-
$totalDiscount[$item->getId()] = $item->getBaseDiscountAmount();
224+
if ($item->getChildren() && $item->isChildrenCalculated()) {
225+
$childTotal = 0;
226+
foreach ($item->getChildren() as $child) {
227+
$childTotal += $child->getBaseDiscountAmount();
228+
}
229+
$totalDiscount[$item->getId()] = $childTotal;
230+
} else {
231+
$totalDiscount[$item->getId()] = $item->getBaseDiscountAmount();
232+
}
225233
}
226234
$address->setBaseDiscountAmount(array_sum(array_values($totalDiscount)));
227235
}

0 commit comments

Comments
 (0)