Skip to content

Commit b398e78

Browse files
author
Chhandak.Barua
committed
ACP2E-285: Add to cart failed when cart total is zero and cart price rule is Fixed amount discount for whole cart
1 parent 0a70499 commit b398e78

File tree

4 files changed

+28
-95
lines changed

4 files changed

+28
-95
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ public function getDiscountAmount(
8282
float $baseRuleTotals,
8383
string $discountType
8484
): float {
85-
$ratio = 0;
86-
if ($baseRuleTotals != 0) {
87-
$ratio = $baseItemPrice * $qty / $baseRuleTotals;
88-
}
85+
$ratio = $baseRuleTotals != 0 ? $baseItemPrice * $qty / $baseRuleTotals : 0;
8986
return $this->deltaPriceRound->round(
9087
$ruleDiscount * $ratio,
9188
$discountType

app/code/Magento/SalesRule/Test/Mftf/ActionGroup/FillAdminSimpleProductFormWithZeroPriceActionGroup.xml

Lines changed: 0 additions & 29 deletions
This file was deleted.

app/code/Magento/SalesRule/Test/Mftf/ActionGroup/VerifyProductInCartActionGroup.xml

Lines changed: 0 additions & 31 deletions
This file was deleted.

app/code/Magento/SalesRule/Test/Mftf/Test/AdminCreatedFixedAmountWholeCartDiscountWithZeroPriceProductTest.xml

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,55 @@
88

99
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11-
<test name="AdminCreatedFixedAmountWholeCartDiscountWithZeroPriceProductTest">
11+
<test name="StoreFrontAddZeroPriceProductToCardWithFixedAmountPriceRule">
1212
<annotations>
1313
<features value="SalesRule"/>
1414
<stories value="Zero price product added to cart while cart price rule is Fixed amount discount for whole cart"/>
15-
<title value="Admin should be able to create a cart price rule of type Fixed amount discount for whole cart and add to cart when cart total is zero"/>
16-
<description value="Admin should be able to create a cart price rule of type Fixed amount discount for whole cart and add to cart when cart total is zero"/>
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"/>
1717
<severity value="MAJOR"/>
1818
<testCaseId value="AC-1618"/>
1919
<useCaseId value="ACP2E-285"/>
2020
<group value="SalesRule"/>
21-
</annotations>
21+
</annotations>
2222

2323
<before>
24+
<!--Create Simple Product and Category -->
2425
<createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
26+
<createData entity="SimpleProduct_zero" stepKey="createSimpleProduct">
27+
<requiredEntity createDataKey="createPreReqCategory"/>
28+
</createData>
2529
<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>
2635
</before>
2736

2837
<after>
2938
<!-- Delete the cart price rule we made during the test -->
3039
<actionGroup ref="DeleteCartPriceRuleByName" stepKey="cleanUpRule">
31-
<argument name="ruleName" value="{{SimpleSalesRule.name}}"/>
40+
<argument name="ruleName" value="{{PriceRuleWithCondition.name}}"/>
3241
</actionGroup>
33-
<deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
34-
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteProduct">
35-
<argument name="sku" value="{{_defaultProduct.sku}}"/>
36-
</actionGroup>
37-
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearFilter"/>
42+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/>
43+
<deleteData createDataKey="createPreReqCategory" stepKey="deleteCategory"/>
3844
<actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/>
3945
</after>
4046

41-
<!-- Create a cart price rule for Fixed amount discount for whole cart -->
42-
<actionGroup ref="AdminOpenCartPriceRulesPageActionGroup" stepKey="amOnCartPriceList"/>
43-
<click selector="{{AdminCartPriceRulesSection.addNewRuleButton}}" stepKey="clickAddNewRule"/>
44-
<fillField selector="{{AdminCartPriceRulesFormSection.ruleName}}" userInput="{{SimpleSalesRule.name}}" stepKey="fillRuleName"/>
45-
<selectOption selector="{{AdminCartPriceRulesFormSection.websites}}" userInput="Main Website" stepKey="selectWebsites"/>
46-
<selectOption selector="{{AdminCartPriceRulesFormSection.customerGroups}}" userInput="NOT LOGGED IN" stepKey="selectCustomerGroup"/>
47-
<selectOption selector="{{AdminCartPriceRulesFormSection.coupon}}" userInput="No Coupon" stepKey="selectCoupon"/>
48-
<click selector="{{AdminCartPriceRulesFormSection.actionsHeader}}" stepKey="clickToExpandActions"/>
49-
<selectOption selector="{{AdminCartPriceRulesFormSection.apply}}" userInput="Fixed amount discount for whole cart" stepKey="selectActionType"/>
50-
<fillField selector="{{AdminCartPriceRulesFormSection.discountAmount}}" userInput="50" stepKey="fillDiscountAmount"/>
51-
<click selector="{{AdminCartPriceRulesFormSection.save}}" stepKey="clickSaveButton"/>
52-
<see selector="{{AdminCartPriceRulesSection.messages}}" userInput="You saved the rule." stepKey="seeSuccessMessage"/>
53-
54-
<!-- Create a product to check the storefront -->
55-
<actionGroup ref="FillAdminSimpleProductFormWithZeroPriceActionGroup" stepKey="fillProductFieldsInAdmin">
56-
<argument name="simpleProduct" value="_defaultProduct"/>
47+
<!-- Go to the storefront and add the product to the cart -->
48+
<actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="gotoAndAddProductToCart">
49+
<argument name="product" value="$$createSimpleProduct$$"/>
5750
</actionGroup>
5851

59-
<!-- Spot check the storefront -->
60-
<actionGroup ref="VerifyProductInCartActionGroup" stepKey="verifyStorefront">
61-
<argument name="productUrl" value="{{_defaultProduct.urlKey}}.html"/>
62-
<argument name="quantity" value="1"/>
63-
<argument name="productName" value="{{_defaultProduct.name}}"/>
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="productSku" value="$$createSimpleProduct.sku$$"/>
57+
<argument name="productPrice" value="$$createSimpleProduct.price$$"/>
58+
<argument name="subtotal" value="$$createSimpleProduct.price$$" />
59+
<argument name="qty" value="1"/>
6460
</actionGroup>
6561
</test>
6662
</tests>

0 commit comments

Comments
 (0)