@@ -77,19 +77,74 @@ public function testRateAppliedToShipping(): void
77
77
}
78
78
79
79
/**
80
- * Test table rate amount for the cart that contains some items with free shipping applied.
80
+ * @magentoConfigFixture current_store carriers/tablerate/active 1
81
+ * @magentoConfigFixture current_store carriers/flatrate/active 0
82
+ * @magentoConfigFixture current_store carriers/freeshipping/active 0
83
+ * @magentoConfigFixture current_store carriers/tablerate/condition_name package_qty
84
+ * @magentoDataFixture Magento/SalesRule/_files/cart_rule_free_shipping_by_cart.php
85
+ * @magentoDataFixture Magento/Sales/_files/quote.php
86
+ * @magentoDataFixture Magento/OfflineShipping/_files/tablerates.php
87
+ * @return void
88
+ */
89
+ public function testTableRateFreeShipping ()
90
+ {
91
+ $ objectManager = Bootstrap::getObjectManager ();
92
+ /** @var Quote $quote */
93
+ $ quote = $ objectManager ->get (Quote::class);
94
+ $ quote ->load ('test01 ' , 'reserved_order_id ' );
95
+ $ cartId = $ quote ->getId ();
96
+ if (!$ cartId ) {
97
+ $ this ->fail ('quote fixture failed ' );
98
+ }
99
+ /** @var QuoteIdMask $quoteIdMask */
100
+ $ quoteIdMask = Bootstrap::getObjectManager ()
101
+ ->create (QuoteIdMaskFactory::class)
102
+ ->create ();
103
+ $ quoteIdMask ->load ($ cartId , 'quote_id ' );
104
+ //Use masked cart Id
105
+ $ cartId = $ quoteIdMask ->getMaskedId ();
106
+ $ data = [
107
+ 'data ' => [
108
+ 'country_id ' => "US " ,
109
+ 'postcode ' => null ,
110
+ 'region ' => null ,
111
+ 'region_id ' => null
112
+ ]
113
+ ];
114
+ /** @var EstimateAddressInterface $address */
115
+ $ address = $ objectManager ->create (EstimateAddressInterface::class, $ data );
116
+ /** @var GuestShippingMethodManagementInterface $shippingEstimation */
117
+ $ shippingEstimation = $ objectManager ->get (GuestShippingMethodManagementInterface::class);
118
+ $ result = $ shippingEstimation ->estimateByAddress ($ cartId , $ address );
119
+ $ this ->assertNotEmpty ($ result );
120
+ $ expectedResult = [
121
+ 'method_code ' => 'bestway ' ,
122
+ 'amount ' => 0
123
+ ];
124
+ foreach ($ result as $ rate ) {
125
+ $ this ->assertEquals ($ expectedResult ['amount ' ], $ rate ->getAmount ());
126
+ $ this ->assertEquals ($ expectedResult ['method_code ' ], $ rate ->getMethodCode ());
127
+ }
128
+ }
129
+
130
+ /**
131
+ *
132
+ * Test table rate with zero amount is available for the cart when discount coupon cart price rule to all items
133
+ * and freeshipping cart price rule is applied when order subtotal is greater than specified amount.
81
134
*
82
135
* @magentoConfigFixture current_store carriers/tablerate/active 1
83
136
* @magentoConfigFixture current_store carriers/flatrate/active 0
84
137
* @magentoConfigFixture current_store carriers/freeshipping/active 0
85
- * @magentoConfigFixture current_store carriers/tablerate/condition_name package_value_with_discount
138
+ * @magentoConfigFixture default_store carriers/tablerate/condition_name package_value_with_discount
86
139
* @magentoDataFixture Magento/Catalog/_files/categories.php
87
- * @magentoDataFixture Magento/SalesRule/_files/cart_rule_free_shipping_by_category.php
140
+ * @magentoDataFixture Magento/SalesRule/_files/cart_rule_free_shipping_subtotal_equals_more_than_30.php
141
+ * @magentoDataFixture Magento/SalesRule/_files/cart_rule_20_percent_off_with_coupon_no_condition.php
88
142
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
89
143
* @magentoDataFixture Magento/OfflineShipping/_files/tablerates_price.php
144
+ *
90
145
* @return void
91
146
*/
92
- public function testTableRateWithCartRuleForFreeShipping ()
147
+ public function testTableRateWithZeroPriceShownWhenDiscountCouponAndFreeShippingCartRuleApplied ()
93
148
{
94
149
$ objectManager = Bootstrap::getObjectManager ();
95
150
$ quote = $ this ->getQuote ('tableRate ' );
@@ -108,36 +163,37 @@ public function testTableRateWithCartRuleForFreeShipping()
108
163
/** @var \Magento\Quote\Api\Data\AddressInterface $address */
109
164
$ address = $ addressFactory ->create ();
110
165
$ address ->setCountryId ('US ' );
166
+ /** @var CouponManagementInterface $couponManagement */
167
+ $ couponManagement = Bootstrap::getObjectManager ()->get (CouponManagementInterface::class);
168
+ $ couponManagement ->set ($ quote ->getId (), '123 ' );
111
169
/** @var GuestShippingMethodManagementInterface $shippingEstimation */
112
170
$ shippingEstimation = $ objectManager ->get (GuestShippingMethodManagementInterface::class);
113
171
$ result = $ shippingEstimation ->estimateByExtendedAddress ($ cartId , $ address );
114
172
$ this ->assertCount (1 , $ result );
115
173
$ rate = reset ($ result );
174
+
116
175
$ expectedResult = [
117
- 'method_code ' => 'bestway ' ,
118
- 'amount ' => 10
176
+ 'method_code ' => 'bestway ' ,
177
+ 'amount ' => 0
119
178
];
120
179
$ this ->assertEquals ($ expectedResult ['method_code ' ], $ rate ->getMethodCode ());
121
180
$ this ->assertEquals ($ expectedResult ['amount ' ], $ rate ->getAmount ());
122
181
}
123
182
124
183
/**
125
- * Test table rate with zero amount is available for the cart when discount coupon cart price rule to all items
126
- * and freeshipping cart price rule is applied when order subtotal is greater than specified amount.
184
+ * Test table rate amount for the cart that contains some items with free shipping applied.
127
185
*
128
186
* @magentoConfigFixture current_store carriers/tablerate/active 1
129
187
* @magentoConfigFixture current_store carriers/flatrate/active 0
130
188
* @magentoConfigFixture current_store carriers/freeshipping/active 0
131
- * @magentoConfigFixture default_store carriers/tablerate/condition_name package_value_with_discount
189
+ * @magentoConfigFixture current_store carriers/tablerate/condition_name package_value_with_discount
132
190
* @magentoDataFixture Magento/Catalog/_files/categories.php
133
- * @magentoDataFixture Magento/SalesRule/_files/cart_rule_free_shipping_subtotal_equals_more_than_30.php
134
- * @magentoDataFixture Magento/SalesRule/_files/cart_rule_20_percent_off_with_coupon_no_condition.php
191
+ * @magentoDataFixture Magento/SalesRule/_files/cart_rule_free_shipping_by_category.php
135
192
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
136
193
* @magentoDataFixture Magento/OfflineShipping/_files/tablerates_price.php
137
- *
138
194
* @return void
139
195
*/
140
- public function testTableRateWithZeroPriceShownWhenDiscountCouponAndFreeShippingCartRuleApplied ()
196
+ public function testTableRateWithCartRuleForFreeShipping ()
141
197
{
142
198
$ objectManager = Bootstrap::getObjectManager ();
143
199
$ quote = $ this ->getQuote ('tableRate ' );
@@ -156,18 +212,14 @@ public function testTableRateWithZeroPriceShownWhenDiscountCouponAndFreeShipping
156
212
/** @var \Magento\Quote\Api\Data\AddressInterface $address */
157
213
$ address = $ addressFactory ->create ();
158
214
$ address ->setCountryId ('US ' );
159
- /** @var CouponManagementInterface $couponManagement */
160
- $ couponManagement = Bootstrap::getObjectManager ()->get (CouponManagementInterface::class);
161
- $ couponManagement ->set ($ quote ->getId (), '123 ' );
162
215
/** @var GuestShippingMethodManagementInterface $shippingEstimation */
163
216
$ shippingEstimation = $ objectManager ->get (GuestShippingMethodManagementInterface::class);
164
217
$ result = $ shippingEstimation ->estimateByExtendedAddress ($ cartId , $ address );
165
218
$ this ->assertCount (1 , $ result );
166
219
$ rate = reset ($ result );
167
-
168
220
$ expectedResult = [
169
- 'method_code ' => 'bestway ' ,
170
- 'amount ' => 0
221
+ 'method_code ' => 'bestway ' ,
222
+ 'amount ' => 10
171
223
];
172
224
$ this ->assertEquals ($ expectedResult ['method_code ' ], $ rate ->getMethodCode ());
173
225
$ this ->assertEquals ($ expectedResult ['amount ' ], $ rate ->getAmount ());
0 commit comments