Skip to content

Commit

Permalink
Merge pull request #9302 from adobe-commerce-tier-4/PR-14-10-2024
Browse files Browse the repository at this point in the history
[Support Tier-4 chittima] 14-10-2024 Regular delivery of bugfixes and improvements
  • Loading branch information
2 parents d75cff2 + d179c9b commit 1366ae5
Show file tree
Hide file tree
Showing 20 changed files with 432 additions and 186 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2019 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -182,7 +182,7 @@ private function formatTierPrices(float $productPrice, string $currencyCode, $ti
"discount" => $discount,
"quantity" => $tierPrice->getQty(),
"final_price" => [
"value" => $tierPrice->getValue() * $tierPrice->getQty(),
"value" => $tierPrice->getValue(),
"currency" => $currencyCode
]
];
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/CatalogSearch/Model/Indexer/Fulltext.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/

namespace Magento\CatalogSearch\Model\Indexer;
Expand Down Expand Up @@ -123,7 +123,7 @@ public function __construct(
IndexSwitcherInterface $indexSwitcher,
StateFactory $indexScopeStateFactory,
DimensionProviderInterface $dimensionProvider,
array $data,
array $data = [],
ProcessManager $processManager = null,
?int $batchSize = null,
?DeploymentConfig $deploymentConfig = null
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Customer/Helper/View.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2014 Adobe
* All Rights Reserved.
*/
namespace Magento\Customer\Helper;

Expand Down Expand Up @@ -68,6 +68,6 @@ public function getCustomerName(CustomerInterface $customerData)
$name .= ' ' . __($customerData->getSuffix());
}

return $this->escaper->escapeHtml($name);
return $name;
}
}
10 changes: 4 additions & 6 deletions app/code/Magento/Customer/Test/Unit/Helper/ViewTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2014 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -54,9 +54,7 @@ protected function setUp(): void
*/
public function testGetCustomerName($prefix, $firstName, $middleName, $lastName, $suffix, $result)
{
$customerData = $this->getMockBuilder(CustomerInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$customerData = $this->createMock(CustomerInterface::class);
$customerData->expects($this->any())
->method('getPrefix')->willReturn($prefix);
$customerData->expects($this->any())
Expand All @@ -67,7 +65,7 @@ public function testGetCustomerName($prefix, $firstName, $middleName, $lastName,
->method('getLastname')->willReturn($lastName);
$customerData->expects($this->any())
->method('getSuffix')->willReturn($suffix);
$this->escaperMock->expects($this->once())->method('escapeHtml')->with($result)->willReturn($result);
$this->escaperMock->expects(self::never())->method('escapeHtml');
$this->assertEquals($result, $this->object->getCustomerName($customerData));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2016 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

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

use Magento\Customer\Model\ResourceModel\Db\VersionControl\AddressSnapshot;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Metadata;
use Magento\Framework\Serialize\SerializerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand All @@ -18,22 +20,30 @@ class AddressSnapshotTest extends TestCase
/**
* @var AddressSnapshot
*/
private $model;
private AddressSnapshot $model;

/**
* @var Metadata|MockObject
*/
private $metadataMock;
private Metadata $metadataMock;

/**
* @var SerializerInterface|MockObject
*/
private SerializerInterface $serializer;

/**
* @return void
* @throws \PHPUnit\Framework\MockObject\Exception
*/
protected function setUp(): void
{
$this->metadataMock = $this->getMockBuilder(
Metadata::class
)->disableOriginalConstructor()
->getMock();
$this->metadataMock = $this->createMock(Metadata::class);
$this->serializer = $this->createMock(SerializerInterface::class);

$this->model = new AddressSnapshot(
$this->metadataMock
$this->metadataMock,
$this->serializer
);
}

Expand All @@ -43,13 +53,10 @@ protected function setUp(): void
* @param int $isDefaultShipping
* @param bool $expected
* @dataProvider dataProviderIsModified
* @throws LocalizedException
*/
public function testIsModified(
$isCustomerSaveTransaction,
$isDefaultBilling,
$isDefaultShipping,
$expected
) {
public function testIsModified($isCustomerSaveTransaction, $isDefaultBilling, $isDefaultShipping, $expected): void
{
$entityId = 1;

$dataObjectMock = $this->getMockBuilder(DataObject::class)
Expand Down Expand Up @@ -96,7 +103,7 @@ public function testIsModified(
/**
* @return array
*/
public static function dataProviderIsModified()
public static function dataProviderIsModified(): array
{
return [
[false, 1, 1, true],
Expand All @@ -106,7 +113,11 @@ public static function dataProviderIsModified()
];
}

public function testIsModifiedBypass()
/**
* @return void
* @throws LocalizedException
*/
public function testIsModifiedBypass(): void
{
$dataObjectMock = $this->getMockBuilder(DataObject::class)
->disableOriginalConstructor()
Expand Down
16 changes: 3 additions & 13 deletions app/code/Magento/Quote/Model/QuoteValidator.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2014 Adobe
* All Rights Reserved.
*/

namespace Magento\Quote\Model;
Expand All @@ -14,7 +14,6 @@
use Magento\Quote\Model\Quote as QuoteEntity;
use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage as OrderAmountValidationMessage;
use Magento\Quote\Model\ValidationRules\QuoteValidationRuleInterface;
use Magento\Framework\Webapi\Rest\Response as RestResponse;

/**
* Class to validate the quote
Expand Down Expand Up @@ -44,32 +43,24 @@ class QuoteValidator
*/
private $quoteValidationRule;

/**
* @var RestResponse
*/
private $_response;

/**
* QuoteValidator constructor.
*
* @param AllowedCountries|null $allowedCountryReader
* @param OrderAmountValidationMessage|null $minimumAmountMessage
* @param QuoteValidationRuleInterface|null $quoteValidationRule
* @param RestResponse|null $response
*/
public function __construct(
AllowedCountries $allowedCountryReader = null,
OrderAmountValidationMessage $minimumAmountMessage = null,
QuoteValidationRuleInterface $quoteValidationRule = null,
RestResponse $response = null
QuoteValidationRuleInterface $quoteValidationRule = null
) {
$this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance()
->get(AllowedCountries::class);
$this->minimumAmountMessage = $minimumAmountMessage ?: ObjectManager::getInstance()
->get(OrderAmountValidationMessage::class);
$this->quoteValidationRule = $quoteValidationRule ?: ObjectManager::getInstance()
->get(QuoteValidationRuleInterface::class);
$this->_response = $response ?: ObjectManager::getInstance()->get(RestResponse::class);
}

/**
Expand Down Expand Up @@ -115,7 +106,6 @@ public function validateBeforeSubmit(QuoteEntity $quote)
$defaultMessage .= ' %1';
}
if ($defaultMessage) {
$this->_response->setHeader('errorRedirectAction', '#shipping');
throw new ValidatorException(__($defaultMessage, implode(' ', $messages)));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright 2024 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\Quote\Plugin\Webapi\Model;

use Magento\Framework\Validator\Exception as ValidatorException;
use Magento\Framework\Webapi\Rest\Response as RestResponse;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\QuoteValidator;

class ErrorRedirectProcessor
{
/**
* @param RestResponse $restResponse
*/
public function __construct(
private readonly RestResponse $restResponse
) {
}

/**
* Set errorRedirectAction in case of exception.
*
* @param QuoteValidator $subject
* @param callable $proceed
* @param Quote $quote
*/
public function aroundValidateBeforeSubmit(QuoteValidator $subject, callable $proceed, Quote $quote)
{
try {
$result = $proceed($quote);
} catch (ValidatorException $e) {
$this->restResponse->setHeader('errorRedirectAction', '#shipping');
throw $e;
}

return $result;
}
}
7 changes: 5 additions & 2 deletions app/code/Magento/Quote/etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2014 Adobe
* All Rights Reserved.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
Expand All @@ -23,4 +23,7 @@
<type name="Magento\Quote\Api\CartRepositoryInterface">
<plugin name="quoteValidateOrderId" type="Magento\Quote\Plugin\ValidateQuoteOrigOrder"/>
</type>
<type name="Magento\Quote\Model\QuoteValidator">
<plugin name="error_redirect_processor" type="Magento\Quote\Plugin\Webapi\Model\ErrorRedirectProcessor" />
</type>
</config>
14 changes: 11 additions & 3 deletions app/code/Magento/SalesRule/Model/Quote/Discount.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/
namespace Magento\SalesRule\Model\Quote;

Expand Down Expand Up @@ -221,7 +221,15 @@ public function collect(
unset($itemsToApplyRules[$key]);
}

$totalDiscount[$item->getId()] = $item->getBaseDiscountAmount();
if ($item->getChildren() && $item->isChildrenCalculated()) {
$childTotal = 0;
foreach ($item->getChildren() as $child) {
$childTotal += $child->getBaseDiscountAmount();
}
$totalDiscount[$item->getId()] = $childTotal;
} else {
$totalDiscount[$item->getId()] = $item->getBaseDiscountAmount();
}
}
$address->setBaseDiscountAmount(array_sum(array_values($totalDiscount)));
}
Expand Down
Loading

0 comments on commit 1366ae5

Please sign in to comment.