Skip to content

Commit bc61377

Browse files
ENGCOM-8308: Set correct discount package value for tablerate #30167
2 parents bc8e51d + 7664c1d commit bc61377

File tree

3 files changed

+110
-4
lines changed

3 files changed

+110
-4
lines changed

app/code/Magento/OfflineShipping/Model/Carrier/Tablerate.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,9 @@ public function collectRates(RateRequest $request)
140140
$freePackageValue += $item->getBaseRowTotal();
141141
}
142142
}
143-
$oldValue = $request->getPackageValue();
144-
$newPackageValue = $oldValue - $freePackageValue;
145-
$request->setPackageValue($newPackageValue);
146-
$request->setPackageValueWithDiscount($newPackageValue);
143+
144+
$request->setPackageValue($request->getPackageValue() - $freePackageValue);
145+
$request->setPackageValueWithDiscount($request->getPackageValueWithDiscount() - $freePackageValue);
147146
}
148147

149148
if (!$request->getConditionName()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?><!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<test name="SalesRuleDiscountIsAppliedOnPackageValueForTableRateTest">
10+
<annotations>
11+
<features value="Shipping"/>
12+
<stories value="Offline Shipping Methods"/>
13+
<title value="SalesRule Discount Is Applied On PackageValue For TableRate"/>
14+
<description value="SalesRule Discount Is Applied On PackageValue For TableRate"/>
15+
<severity value="AVERAGE"/>
16+
<testCaseId value="MC-38271"/>
17+
<group value="shipping"/>
18+
</annotations>
19+
<before>
20+
<!-- Add simple product -->
21+
<createData entity="SimpleProduct2" stepKey="createSimpleProduct">
22+
<field key="price">13.00</field>
23+
</createData>
24+
25+
<!-- Create cart price rule -->
26+
<createData entity="ActiveSalesRuleForNotLoggedIn" stepKey="createCartPriceRule"/>
27+
<createData entity="SimpleSalesRuleCoupon" stepKey="createCouponForCartPriceRule">
28+
<requiredEntity createDataKey="createCartPriceRule"/>
29+
</createData>
30+
31+
<!-- Login as admin -->
32+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
33+
34+
<!-- Go to Stores > Configuration > Sales > Shipping Methods -->
35+
<actionGroup ref="AdminOpenShippingMethodsConfigPageActionGroup" stepKey="openShippingMethodConfigPage"/>
36+
37+
<!-- Switch to Website scope -->
38+
<actionGroup ref="AdminSwitchWebsiteActionGroup" stepKey="AdminSwitchStoreView">
39+
<argument name="website" value="_defaultWebsite"/>
40+
</actionGroup>
41+
42+
<!-- Enable Table Rate method and save config -->
43+
<actionGroup ref="AdminChangeTableRatesShippingMethodStatusActionGroup" stepKey="enableTableRatesShippingMethod"/>
44+
45+
<!-- Uncheck Use Default checkbox for Default Condition -->
46+
<uncheckOption selector="{{AdminShippingMethodTableRatesSection.carriersTableRateConditionName}}" stepKey="disableUseDefaultCondition"/>
47+
48+
<!-- Make sure you have Condition Price vs. Destination -->
49+
<selectOption selector="{{AdminShippingMethodTableRatesSection.condition}}" userInput="{{TableRateShippingMethodConfig.package_value_with_discount}}" stepKey="setCondition"/>
50+
51+
<!-- Import file and save config -->
52+
<attachFile selector="{{AdminShippingMethodTableRatesSection.importFile}}" userInput="usa_tablerates.csv" stepKey="attachFileForImport"/>
53+
<actionGroup ref="AdminSaveConfigActionGroup" stepKey="saveConfigs"/>
54+
</before>
55+
<after>
56+
<!-- Go to Stores > Configuration > Sales > Shipping Methods -->
57+
<actionGroup ref="AdminOpenShippingMethodsConfigPageActionGroup" stepKey="openShippingMethodConfigPage"/>
58+
59+
<!-- Switch to Website scope -->
60+
<actionGroup ref="AdminSwitchWebsiteActionGroup" stepKey="AdminSwitchStoreView">
61+
<argument name="website" value="_defaultWebsite"/>
62+
</actionGroup>
63+
64+
<!-- Check Use Default checkbox for Default Condition and Active -->
65+
<checkOption selector="{{AdminShippingMethodTableRatesSection.carriersTableRateConditionName}}" stepKey="enableUseDefaultCondition"/>
66+
<checkOption selector="{{AdminShippingMethodTableRatesSection.enabledUseSystemValue}}" stepKey="enableUseDefaultActive"/>
67+
68+
<actionGroup ref="AdminSaveConfigActionGroup" stepKey="saveConfigs"/>
69+
70+
<!-- Log out -->
71+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
72+
73+
<!-- Remove simple product-->
74+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
75+
76+
<!-- Delete sales rule -->
77+
<deleteData createDataKey="createCartPriceRule" stepKey="deleteCartPriceRule"/>
78+
79+
</after>
80+
<!-- Add simple product to cart -->
81+
<actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addProductToCart">
82+
<argument name="product" value="$$createSimpleProduct$$"/>
83+
</actionGroup>
84+
85+
<!-- Assert that table rate value is correct for US -->
86+
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="goToCheckout"/>
87+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.estimateShippingAndTaxForm}}" stepKey="waitForEstimateShippingAndTaxForm"/>
88+
<waitForElement time="30" selector="{{CheckoutCartSummarySection.shippingMethodForm}}" stepKey="waitForShippingMethodForm"/>
89+
<conditionalClick selector="{{CheckoutCartSummarySection.estimateShippingAndTax}}" dependentSelector="{{CheckoutCartSummarySection.country}}" visible="false" stepKey="expandEstimateShippingandTax" />
90+
<selectOption selector="{{CheckoutCartSummarySection.country}}" userInput="United States" stepKey="selectUSCountry"/>
91+
<waitForPageLoad stepKey="waitForSelectCountry"/>
92+
<see selector="{{CheckoutCartSummarySection.shippingPrice}}" userInput="$5.99" stepKey="seeShippingForUS"/>
93+
94+
<!-- Apply Coupon -->
95+
<actionGroup ref="StorefrontApplyCouponActionGroup" stepKey="applyDiscount">
96+
<argument name="coupon" value="$$createCouponForCartPriceRule$$"/>
97+
</actionGroup>
98+
99+
<see selector="{{CheckoutCartSummarySection.shippingPrice}}" userInput="$7.99" stepKey="seeShippingForUSWithDiscount"/>
100+
</test>
101+
</tests>

app/code/Magento/Shipping/Test/Mftf/Data/TableRatesShippingMethodData.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@
1616
<data key="title">Best Way</data>
1717
<data key="methodName">Table Rate</data>
1818
</entity>
19+
<!-- Set Table Rate Shipping method Condition -->
20+
<entity name="TableRateShippingMethodConfig" type="shipping_method">
21+
<data key="package_weight">Weight vs. Destination</data>
22+
<data key="package_value_with_discount">Price vs. Destination</data>
23+
<data key="package_qty"># of Items vs. Destination</data>
24+
</entity>
1925
</entities>

0 commit comments

Comments
 (0)