Skip to content

Commit e5db678

Browse files
committed
MAGETWO-96410: [2.3.x] The cart rule cannot effect the cart
- Add automated test script
2 parents cf69967 + 3a3eb30 commit e5db678

File tree

6 files changed

+175
-1
lines changed

6 files changed

+175
-1
lines changed

app/code/Magento/Bundle/Test/Mftf/Section/AdminProductFormBundleSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<element name="bundleOptionXProductYQuantity" type="input" selector="[name='bundle_options[bundle_options][{{x}}][bundle_selections][{{y}}][selection_qty]']" parameterized="true"/>
2323
<element name="addProductsToOption" type="button" selector="[data-index='modal_set']" timeout="30"/>
2424
<element name="nthAddProductsToOption" type="button" selector="//tr[{{var}}]//button[@data-index='modal_set']" timeout="30" parameterized="true"/>
25+
<element name="bundlePriceType" type="select" selector="bundle_options[bundle_options][0][bundle_selections][0][selection_price_type]"/>
26+
<element name="bundlePriceValue" type="input" selector="bundle_options[bundle_options][0][bundle_selections][0][selection_price_value]"/>
2527
<!--Select"url Key"InputForm-->
2628
<element name="urlKey" type="input" selector="//input[@name='product[url_key]']" timeout="30"/>
2729
<!--AddSelectedProducts-->

app/code/Magento/SalesRule/Model/Rule/Condition/Product/Subselect.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\SalesRule\Model\Rule\Condition\Product;
77

8+
/**
9+
* Subselect conditions for product.
10+
*/
811
class Subselect extends \Magento\SalesRule\Model\Rule\Condition\Product\Combine
912
{
1013
/**
@@ -161,7 +164,9 @@ public function validate(\Magento\Framework\Model\AbstractModel $model)
161164
}
162165
}
163166
if ($hasValidChild || parent::validate($item)) {
164-
$total += (($hasValidChild && $useChildrenTotal) ? $childrenAttrTotal : $item->getData($attr));
167+
$total += ($hasValidChild && $useChildrenTotal)
168+
? $childrenAttrTotal * $item->getQty()
169+
: $item->getData($attr);
165170
}
166171
}
167172
return $this->validateAttribute($total);

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,34 @@
3636
<click selector="{{AdminCartPriceRulesFormSection.delete}}" stepKey="clickDeleteButton"/>
3737
<click selector="{{AdminCartPriceRulesFormSection.modalAcceptButton}}" stepKey="confirmDelete"/>
3838
</actionGroup>
39+
<actionGroup name="AdminCreateCartPriceRuleWithConditions" extends="AdminCreateCartPriceRuleActionGroup">
40+
<arguments>
41+
<argument name="condition1" type="string" defaultValue="Products subselection" />
42+
<argument name="condition2" type="string" defaultValue="Category" />
43+
<argument name="ruleToChange1" type="string" defaultValue="is" />
44+
<argument name="rule1" type="string" defaultValue="equals or greater than" />
45+
<argument name="ruleToChange2" type="string" defaultValue="..." />
46+
<argument name="rule2" type="string" defaultValue="2" />
47+
<argument name="categoryName" type="string" defaultValue="_defaultCategory.name" />
48+
</arguments>
49+
<remove keyForRemoval="fillDiscountAmount" />
50+
<!--Go to Conditions section-->
51+
<click selector="{{AdminCartPriceRulesFormSection.conditionsHeader}}" stepKey="openConditionsSection" after="selectActionType" />
52+
<click selector="{{AdminCartPriceRulesFormSection.addCondition('1')}}" stepKey="addFirstCondition" after="openConditionsSection" />
53+
<selectOption selector="{{AdminCartPriceRulesFormSection.ruleCondition('1')}}" userInput="{{condition1}}" stepKey="selectRule" after="addFirstCondition" />
54+
<waitForElementVisible selector="{{AdminCartPriceRulesFormSection.ruleParameter(ruleToChange1)}}" stepKey="waitForFirstRuleElement" after="selectRule" />
55+
<click selector="{{AdminCartPriceRulesFormSection.ruleParameter(ruleToChange1)}}" stepKey="clickToChangeRule" after="waitForFirstRuleElement" />
56+
<selectOption selector="{{AdminCartPriceRulesFormSection.ruleParameterSelect('1--1')}}" userInput="{{rule1}}" stepKey="selectRule1" after="clickToChangeRule" />
57+
<waitForElementVisible selector="{{AdminCartPriceRulesFormSection.ruleParameter(ruleToChange2)}}" stepKey="waitForSecondRuleElement" after="selectRule1" />
58+
<click selector="{{AdminCartPriceRulesFormSection.ruleParameter(ruleToChange2)}}" stepKey="clickToChangeRule1" after="waitForSecondRuleElement" />
59+
<fillField selector="{{AdminCartPriceRulesFormSection.ruleParameterInput('1--1')}}" userInput="{{rule2}}" stepKey="fillRule" after="clickToChangeRule1" />
60+
<click selector="{{AdminCartPriceRulesFormSection.addCondition('1--1')}}" stepKey="addSecondCondition" after="fillRule" />
61+
<selectOption selector="{{AdminCartPriceRulesFormSection.ruleCondition('1--1')}}" userInput="{{condition2}}" stepKey="selectSecondCondition" after="addSecondCondition" />
62+
<waitForElementVisible selector="{{AdminCartPriceRulesFormSection.ruleParameter(ruleToChange2)}}" stepKey="waitForThirdRuleElement" after="selectSecondCondition" />
63+
<click selector="{{AdminCartPriceRulesFormSection.ruleParameter(ruleToChange2)}}" stepKey="addThirdCondition" after="waitForThirdRuleElement" />
64+
<waitForElementVisible selector="{{AdminCartPriceRulesFormSection.openChooser('1--1--1')}}" stepKey="waitForForthRuleElement" after="addThirdCondition" />
65+
<click selector="{{AdminCartPriceRulesFormSection.openChooser('1--1--1')}}" stepKey="openChooser" after="waitForForthRuleElement" />
66+
<waitForElementVisible selector="{{AdminCartPriceRulesFormSection.categoryCheckbox(categoryName)}}" stepKey="waitForCategoryVisible" after="openChooser" />
67+
<checkOption selector="{{AdminCartPriceRulesFormSection.categoryCheckbox(categoryName)}}" stepKey="checkCategoryName" after="waitForCategoryVisible" />
68+
</actionGroup>
3969
</actionGroups>

app/code/Magento/SalesRule/Test/Mftf/Data/SalesRuleData.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,11 @@
117117
<data key="uses_per_coupon">2</data>
118118
<data key="simple_free_shipping">1</data>
119119
</entity>
120+
<entity name="PriceRuleWithCondition" type="SalesRule">
121+
<data key="name" unique="suffix">SalesRule</data>
122+
<data key="websites">Main Website</data>
123+
<data key="customerGroups">'NOT LOGGED IN', 'General', 'Wholesale', 'Retailer'</data>
124+
<data key="apply">Fixed amount discount for whole cart</data>
125+
<data key="discountAmount">50</data>
126+
</entity>
120127
</entities>

app/code/Magento/SalesRule/Test/Mftf/Section/AdminCartPriceRulesFormSection.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,15 @@
4848
<element name="couponQty" type="input" selector="#coupons_qty"/>
4949
<element name="generateCouponsButton" type="button" selector="#coupons_generate_button" timeout="30"/>
5050
<element name="generatedCouponByIndex" type="text" selector="#couponCodesGrid_table > tbody > tr:nth-child({{var}}) > td.col-code" parameterized="true"/>
51+
52+
<!--Conditions sub-form-->
53+
<element name="conditionsHeader" type="button" selector="div[data-index='conditions']" timeout="30"/>
54+
<element name="addCondition" type="button" selector="//*[@id='conditions__{{arg}}__children']//span" parameterized="true"/>
55+
<element name="ruleCondition" type="select" selector="rule[conditions][{{arg}}][new_child]" parameterized="true"/>
56+
<element name="ruleParameter" type="text" selector="//span[@class='rule-param']/a[contains(text(), '{{arg}}')]" parameterized="true"/>
57+
<element name="ruleParameterSelect" type="select" selector="rule[conditions][{{arg}}][operator]" parameterized="true"/>
58+
<element name="ruleParameterInput" type="input" selector="rule[conditions][{{arg}}][value]" parameterized="true"/>
59+
<element name="openChooser" type="button" selector="//label[@for='conditions__{{arg}}__value']" parameterized="true"/>
60+
<element name="categoryCheckbox" type="checkbox" selector="//span[contains(text(), '{{arg}}')]/parent::a/preceding-sibling::input[@type='checkbox']" parameterized="true"/>
5161
</section>
5262
</sections>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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="AdminCartRulesAppliedForProductInCartTest">
12+
<annotations>
13+
<features value="SalesRule"/>
14+
<stories value="The cart rule cannot effect the cart"/>
15+
<title value="Check that cart rules applied for product in cart"/>
16+
<description value="Check that cart rules applied for product in cart"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MAGETWO-96722"/>
19+
<useCaseId value="MAGETWO-96410"/>
20+
<group value="SalesRule"/>
21+
</annotations>
22+
23+
<before>
24+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
25+
26+
<!--Create category and product-->
27+
<createData entity="_defaultCategory" stepKey="defaultCategory"/>
28+
<createData entity="SimpleProduct2" stepKey="simpleProduct">
29+
<field key="price">200</field>
30+
<field key="quantity">500</field>
31+
</createData>
32+
</before>
33+
<after>
34+
<!--Delete created data-->
35+
<deleteData createDataKey="defaultCategory" stepKey="deleteCategory"/>
36+
<deleteData createDataKey="simpleProduct" stepKey="deleteSimpleProduct"/>
37+
38+
<actionGroup stepKey="deleteProduct1" ref="deleteProductBySku">
39+
<argument name="sku" value="{{BundleProduct.sku}}"/>
40+
</actionGroup>
41+
<actionGroup ref="DeleteCartPriceRuleByName" stepKey="deleteCartPriceRule">
42+
<argument name="ruleName" value="{{PriceRuleWithCondition.name}}"/>
43+
</actionGroup>
44+
45+
<actionGroup ref="logout" stepKey="logout"/>
46+
</after>
47+
48+
<!--Start creating a bundle product-->
49+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="goToProductList"/>
50+
<waitForPageLoad stepKey="waitForProductList"/>
51+
<actionGroup ref="goToCreateProductPage" stepKey="goToCreateProduct">
52+
<argument name="product" value="BundleProduct"/>
53+
</actionGroup>
54+
<actionGroup ref="fillProductNameAndSkuInProductForm" stepKey="fillNameAndSku">
55+
<argument name="product" value="BundleProduct"/>
56+
</actionGroup>
57+
<pressKey selector="{{AdminProductFormSection.productSku}}" parameterArray="[\Facebook\WebDriver\WebDriverKeys::ENTER]" stepKey="enter"/>
58+
59+
<!--Off dynamic price and set value-->
60+
<click selector="{{AdminProductFormBundleSection.dynamicPrice}}" stepKey="offDynamicPrice"/>
61+
<fillField selector="{{AdminProductFormBundleSection.priceField}}" userInput="0" stepKey="setProductPrice"/>
62+
63+
<!-- Add category to product -->
64+
<click selector="{{AdminProductFormBundleSection.categoriesDropDown}}" stepKey="dropDownCategories"/>
65+
<fillField selector="{{AdminProductFormBundleSection.searchForCategory}}" userInput="$$defaultCategory.name$$" stepKey="searchForCategory"/>
66+
<click selector="{{AdminProductFormBundleSection.selectCategory}}" stepKey="selectCategory"/>
67+
<click selector="{{AdminProductFormBundleSection.categoriesLabel}}" stepKey="clickOnCategoriesLabelToCloseOptions"/>
68+
69+
<!-- Add option, a "Radio Buttons" type option, with one product and set fixed price 200-->
70+
<actionGroup ref="addBundleOptionWithOneProduct" stepKey="addBundleOptionWithOneProduct">
71+
<argument name="x" value="0"/>
72+
<argument name="n" value="1"/>
73+
<argument name="prodOneSku" value="$$simpleProduct.sku$$"/>
74+
<argument name="prodTwoSku" value=""/>
75+
<argument name="optionTitle" value="Option One"/>
76+
<argument name="inputType" value="radio"/>
77+
</actionGroup>
78+
<selectOption selector="{{AdminProductFormBundleSection.bundlePriceType}}" userInput="Fixed" stepKey="selectPriceType"/>
79+
<fillField selector="{{AdminProductFormBundleSection.bundlePriceValue}}" userInput="200" stepKey="fillPriceValue"/>
80+
<actionGroup ref="saveProductForm" stepKey="saveProduct"/>
81+
82+
<!--Create cart price rule-->
83+
<actionGroup ref="AdminCreateCartPriceRuleWithConditions" stepKey="createRule">
84+
<argument name="ruleName" value="PriceRuleWithCondition"/>
85+
<argument name="condition1" value="Products subselection"/>
86+
<argument name="condition2" value="Category"/>
87+
<argument name="ruleToChange1" value="is"/>
88+
<argument name="rule1" value="equals or greater than"/>
89+
<argument name="ruleToChange2" value="..."/>
90+
<argument name="rule2" value="2"/>
91+
<argument name="categoryName" value="{{_defaultCategory.name}}"/>
92+
</actionGroup>
93+
94+
<!--Go to Storefront and add product to cart and checkout from cart-->
95+
<amOnPage url="/$$simpleProduct.name$$.html" stepKey="GoToProduct"/>
96+
<fillField selector="{{StorefrontProductActionSection.quantity}}" userInput="2" stepKey="setQuantity"/>
97+
<actionGroup ref="StorefrontAddToCartCustomOptionsProductPageActionGroup" stepKey="AddProductToCard">
98+
<argument name="productName" value="$$simpleProduct.name$$"/>
99+
</actionGroup>
100+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/>
101+
<actionGroup ref="GuestCheckoutFillingShippingSectionActionGroup" stepKey="guestCheckoutFillingShipping"/>
102+
103+
<!--Check totals-->
104+
<grabTextFrom selector="{{CheckoutPaymentSection.orderSummarySubtotal}}" stepKey="grabSubtotal"/>
105+
<grabTextFrom selector="{{CheckoutPaymentSection.orderSummaryShippingTotal}}" stepKey="grabShippingTotal"/>
106+
<grabTextFrom selector="{{CheckoutPaymentSection.orderSummaryTotal}}" stepKey="grabTotal"/>
107+
<assertEquals stepKey="assertSubtotal">
108+
<expectedResult type="string">$400.00</expectedResult>
109+
<actualResult type="variable">$grabSubtotal</actualResult>
110+
</assertEquals>
111+
<assertEquals stepKey="assertShippingTotal">
112+
<expectedResult type="string">$10.00</expectedResult>
113+
<actualResult type="variable">$grabShippingTotal</actualResult>
114+
</assertEquals>
115+
<assertEquals stepKey="assertTotal">
116+
<expectedResult type="string">$410.00</expectedResult>
117+
<actualResult type="variable">$grabTotal</actualResult>
118+
</assertEquals>
119+
</test>
120+
</tests>

0 commit comments

Comments
 (0)