Skip to content

Commit 0bbafe1

Browse files
committed
ACP2E-209: "Table rate" shipping method displays as "Not yet calculated" on checkout
Integration test implemented. File changes reverted to previous commit as they were mistakenly overwritten and then added new newly implemented Integration test.
1 parent d103a55 commit 0bbafe1

File tree

1 file changed

+71
-19
lines changed

1 file changed

+71
-19
lines changed

dev/tests/integration/testsuite/Magento/Quote/Model/ShippingMethodManagementTest.php

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,74 @@ public function testRateAppliedToShipping(): void
7777
}
7878

7979
/**
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.
81134
*
82135
* @magentoConfigFixture current_store carriers/tablerate/active 1
83136
* @magentoConfigFixture current_store carriers/flatrate/active 0
84137
* @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
86139
* @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
88142
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
89143
* @magentoDataFixture Magento/OfflineShipping/_files/tablerates_price.php
144+
*
90145
* @return void
91146
*/
92-
public function testTableRateWithCartRuleForFreeShipping()
147+
public function testTableRateWithZeroPriceShownWhenDiscountCouponAndFreeShippingCartRuleApplied()
93148
{
94149
$objectManager = Bootstrap::getObjectManager();
95150
$quote = $this->getQuote('tableRate');
@@ -108,36 +163,37 @@ public function testTableRateWithCartRuleForFreeShipping()
108163
/** @var \Magento\Quote\Api\Data\AddressInterface $address */
109164
$address = $addressFactory->create();
110165
$address->setCountryId('US');
166+
/** @var CouponManagementInterface $couponManagement */
167+
$couponManagement = Bootstrap::getObjectManager()->get(CouponManagementInterface::class);
168+
$couponManagement->set($quote->getId(), '123');
111169
/** @var GuestShippingMethodManagementInterface $shippingEstimation */
112170
$shippingEstimation = $objectManager->get(GuestShippingMethodManagementInterface::class);
113171
$result = $shippingEstimation->estimateByExtendedAddress($cartId, $address);
114172
$this->assertCount(1, $result);
115173
$rate = reset($result);
174+
116175
$expectedResult = [
117-
'method_code' => 'bestway',
118-
'amount' => 10
176+
'method_code' => 'bestway',
177+
'amount' => 0
119178
];
120179
$this->assertEquals($expectedResult['method_code'], $rate->getMethodCode());
121180
$this->assertEquals($expectedResult['amount'], $rate->getAmount());
122181
}
123182

124183
/**
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.
127185
*
128186
* @magentoConfigFixture current_store carriers/tablerate/active 1
129187
* @magentoConfigFixture current_store carriers/flatrate/active 0
130188
* @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
132190
* @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
135192
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
136193
* @magentoDataFixture Magento/OfflineShipping/_files/tablerates_price.php
137-
*
138194
* @return void
139195
*/
140-
public function testTableRateWithZeroPriceShownWhenDiscountCouponAndFreeShippingCartRuleApplied()
196+
public function testTableRateWithCartRuleForFreeShipping()
141197
{
142198
$objectManager = Bootstrap::getObjectManager();
143199
$quote = $this->getQuote('tableRate');
@@ -156,18 +212,14 @@ public function testTableRateWithZeroPriceShownWhenDiscountCouponAndFreeShipping
156212
/** @var \Magento\Quote\Api\Data\AddressInterface $address */
157213
$address = $addressFactory->create();
158214
$address->setCountryId('US');
159-
/** @var CouponManagementInterface $couponManagement */
160-
$couponManagement = Bootstrap::getObjectManager()->get(CouponManagementInterface::class);
161-
$couponManagement->set($quote->getId(), '123');
162215
/** @var GuestShippingMethodManagementInterface $shippingEstimation */
163216
$shippingEstimation = $objectManager->get(GuestShippingMethodManagementInterface::class);
164217
$result = $shippingEstimation->estimateByExtendedAddress($cartId, $address);
165218
$this->assertCount(1, $result);
166219
$rate = reset($result);
167-
168220
$expectedResult = [
169-
'method_code' => 'bestway',
170-
'amount' => 0
221+
'method_code' => 'bestway',
222+
'amount' => 10
171223
];
172224
$this->assertEquals($expectedResult['method_code'], $rate->getMethodCode());
173225
$this->assertEquals($expectedResult['amount'], $rate->getAmount());

0 commit comments

Comments
 (0)