Skip to content

Commit 06f0224

Browse files
committed
Merge remote-tracking branch 'magento-l3/ACP2E-285' into L3_PR_21-12-13
2 parents 5b0197f + 2133bad commit 06f0224

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

app/code/Magento/SalesRule/Helper/CartFixedDiscount.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getDiscountAmount(
8484
float $baseRuleTotals,
8585
string $discountType
8686
): float {
87-
$ratio = $baseItemPrice * $qty / $baseRuleTotals;
87+
$ratio = $baseRuleTotals != 0 ? $baseItemPrice * $qty / $baseRuleTotals : 0;
8888
return $this->deltaPriceRound->round(
8989
$ruleDiscount * $ratio,
9090
$discountType
@@ -111,7 +111,7 @@ public function getDiscountedAmountProportionally(
111111
string $discountType
112112
): float {
113113
$baseItemPriceTotal = $baseItemPrice * $qty - $baseItemDiscountAmount;
114-
$ratio = $baseItemPriceTotal / $baseRuleTotalsDiscount;
114+
$ratio = $baseRuleTotalsDiscount != 0 ? $baseItemPriceTotal / $baseRuleTotalsDiscount : 0;
115115
$discountAmount = $this->deltaPriceRound->round($ruleDiscount * $ratio, $discountType);
116116
return $discountAmount;
117117
}
@@ -129,7 +129,7 @@ public function getShippingDiscountAmount(
129129
float $shippingAmount,
130130
float $quoteBaseSubtotal
131131
): float {
132-
$ratio = $shippingAmount / $quoteBaseSubtotal;
132+
$ratio = $quoteBaseSubtotal != 0 ? $shippingAmount / $quoteBaseSubtotal : 0;
133133
return $this->priceCurrency
134134
->roundPrice(
135135
$rule->getDiscountAmount() * $ratio
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StoreFrontAddZeroPriceProductToCardWithFixedAmountPriceRule">
12+
<annotations>
13+
<features value="SalesRule"/>
14+
<stories value="Zero price product added to cart while cart price rule is Fixed amount discount for whole cart"/>
15+
<title value="Add zero price product to cart when fixed amount discount for the whole cart rule is active"/>
16+
<description value="Customers should be able to add a zero price product from the storefront when the cart price rule of type Fixed amount discount for the whole cart is configured"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="AC-1618"/>
19+
<useCaseId value="ACP2E-285"/>
20+
<group value="SalesRule"/>
21+
</annotations>
22+
23+
<before>
24+
<!-- Create Simple Product and Category -->
25+
<createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
26+
<createData entity="SimpleProduct_zero" stepKey="createSimpleProduct">
27+
<requiredEntity createDataKey="createPreReqCategory"/>
28+
</createData>
29+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
30+
31+
<!-- Create cart price rule -->
32+
<actionGroup ref="AdminCreateCartPriceRuleActionGroup" stepKey="createCartPriceRule">
33+
<argument name="ruleName" value="PriceRuleWithCondition"/>
34+
</actionGroup>
35+
</before>
36+
37+
<after>
38+
<!-- Delete the cart price rule we made during the test -->
39+
<actionGroup ref="DeleteCartPriceRuleByName" stepKey="cleanUpRule">
40+
<argument name="ruleName" value="{{PriceRuleWithCondition.name}}"/>
41+
</actionGroup>
42+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/>
43+
<deleteData createDataKey="createPreReqCategory" stepKey="deleteCategory"/>
44+
<actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/>
45+
</after>
46+
47+
<!-- Go to the storefront and add the product to the cart -->
48+
<actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="gotoAndAddProductToCart">
49+
<argument name="product" value="$$createSimpleProduct$$"/>
50+
</actionGroup>
51+
52+
<!-- Go to the cart page and verify we see the product -->
53+
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="gotoCart"/>
54+
<actionGroup ref="AssertStorefrontCheckoutCartItemsActionGroup" stepKey="assertProductItemInCheckOutCart">
55+
<argument name="productName" value="$$createSimpleProduct.name$$"/>
56+
<argument name="productPrice" value="$$createSimpleProduct.price$$"/>
57+
<argument name="subtotal" value="$$createSimpleProduct.price$$" />
58+
<argument name="qty" value="1"/>
59+
</actionGroup>
60+
</test>
61+
</tests>

0 commit comments

Comments
 (0)