Skip to content

Commit 9389cd8

Browse files
committed
Merge remote-tracking branch 'MC-39034' into 2.4-bugfixes-121520
2 parents 88859e2 + 8f40a2b commit 9389cd8

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

app/code/Magento/SalesRule/Model/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public function process(AbstractItem $item)
318318
public function processShippingAmount(Address $address)
319319
{
320320
$shippingAmount = $address->getShippingAmountForDiscount();
321-
if ($shippingAmount !== null) {
321+
if (!empty($shippingAmount)) {
322322
$baseShippingAmount = $address->getBaseShippingAmountForDiscount();
323323
} else {
324324
$shippingAmount = $address->getShippingAmount();

app/code/Magento/SalesRule/Test/Unit/Model/ValidatorTest.php

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Magento\Store\Model\Store;
3434
use PHPUnit\Framework\MockObject\MockObject;
3535
use PHPUnit\Framework\TestCase;
36+
use Zend_Db_Select_Exception;
3637

3738
/**
3839
* Test sales rule model validator
@@ -538,7 +539,7 @@ public function testProcessShippingAmountProcessDisabled()
538539
* @param int $ruleDiscount
539540
* @param int $shippingDiscount
540541
* @dataProvider dataProviderActions
541-
* @throws \Zend_Db_Select_Exception
542+
* @throws Zend_Db_Select_Exception
542543
*/
543544
public function testProcessShippingAmountActions($action, $ruleDiscount, $shippingDiscount): void
544545
{
@@ -595,6 +596,86 @@ public static function dataProviderActions()
595596
];
596597
}
597598

599+
/**
600+
* Tests shipping amount with full discount action.
601+
*
602+
* @dataProvider dataProviderForFullShippingDiscount
603+
* @param string $action
604+
* @param float $ruleDiscount
605+
* @param float $shippingDiscount
606+
* @param float $shippingAmount
607+
* @param float $quoteBaseSubTotal
608+
* @throws Zend_Db_Select_Exception
609+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
610+
*/
611+
public function testProcessShippingAmountWithFullFixedPercentDiscount(
612+
string $action,
613+
float $ruleDiscount,
614+
float $shippingDiscount,
615+
float $shippingAmount,
616+
float $quoteBaseSubTotal
617+
): void {
618+
$ruleMock = $this->getMockBuilder(Rule::class)
619+
->disableOriginalConstructor()
620+
->setMethods(['getApplyToShipping', 'getSimpleAction', 'getDiscountAmount'])
621+
->getMock();
622+
$ruleMock->method('getApplyToShipping')
623+
->willReturn(true);
624+
$ruleMock->method('getDiscountAmount')
625+
->willReturn($ruleDiscount);
626+
$ruleMock->method('getSimpleAction')
627+
->willReturn($action);
628+
629+
$iterator = new \ArrayIterator([$ruleMock]);
630+
$this->ruleCollection->method('getIterator')
631+
->willReturn($iterator);
632+
633+
$this->utility->method('canProcessRule')
634+
->willReturn(true);
635+
636+
$this->priceCurrency->method('convert')
637+
->willReturn($ruleDiscount);
638+
639+
$this->priceCurrency->method('roundPrice')
640+
->willReturn(round($shippingDiscount, 2));
641+
642+
$this->model->init(
643+
$this->model->getWebsiteId(),
644+
$this->model->getCustomerGroupId(),
645+
$this->model->getCouponCode()
646+
);
647+
648+
$addressMock = $this->setupAddressMock($shippingAmount, $quoteBaseSubTotal);
649+
650+
self::assertInstanceOf(Validator::class, $this->model->processShippingAmount($addressMock));
651+
self::assertEquals($shippingDiscount, $addressMock->getShippingDiscountAmount());
652+
}
653+
654+
/**
655+
* Get data provider array for full shipping discount action
656+
*
657+
* @return array
658+
*/
659+
public function dataProviderForFullShippingDiscount(): array
660+
{
661+
return [
662+
'verify shipping discount when shipping amount is greater than zero' => [
663+
Rule::BY_PERCENT_ACTION,
664+
100.00,
665+
5.0,
666+
5.0,
667+
10.0
668+
],
669+
'verify shipping discount when shipping amount is zero' => [
670+
Rule::BY_PERCENT_ACTION,
671+
100.00,
672+
5.0,
673+
0,
674+
10.0
675+
]
676+
];
677+
}
678+
598679
/**
599680
* @param float $shippingAmount
600681
* @param float $quoteBaseSubTotal

0 commit comments

Comments
 (0)