Skip to content

Commit eced127

Browse files
authored
Merge pull request #2625 from magento-tango/MAGETWO-69940
MAGETWO-69940: [GITHUB] Free shipping coupon not working with Table Rates shipping #8172 / #8089
2 parents 22eac8e + dfb0b5d commit eced127

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ public function collectRates(RateRequest $request)
128128
$freeQty += $item->getQty() * ($child->getQty() - $freeShipping);
129129
}
130130
}
131-
} elseif ($item->getFreeShipping()) {
132-
$freeShipping = is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0;
131+
} elseif ($item->getFreeShipping() || $item->getAddress()->getFreeShipping()) {
132+
$freeShipping = $item->getFreeShipping() ?
133+
$item->getFreeShipping() : $item->getAddress()->getFreeShipping();
134+
$freeShipping = is_numeric($freeShipping) ? $freeShipping : 0;
133135
$freeQty += $item->getQty() - $freeShipping;
134136
$freePackageValue += $item->getBaseRowTotal();
135137
}

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,57 @@ public function testRateAppliedToShipping()
3030
$this->assertEquals(0, $customerQuote->getBaseGrandTotal());
3131
}
3232

33+
/**
34+
* @magentoConfigFixture current_store carriers/tablerate/active 1
35+
* @magentoConfigFixture current_store carriers/flatrate/active 0
36+
* @magentoConfigFixture current_store carriers/freeshipping/active 0
37+
* @magentoConfigFixture current_store carriers/tablerate/condition_name package_qty
38+
* @magentoDataFixture Magento/SalesRule/_files/cart_rule_free_shipping_by_cart.php
39+
* @magentoDataFixture Magento/Sales/_files/quote.php
40+
* @magentoDataFixture Magento/OfflineShipping/_files/tablerates.php
41+
* @return void
42+
*/
43+
public function testTableRateFreeShipping()
44+
{
45+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
46+
/** @var \Magento\Quote\Model\Quote $quote */
47+
$quote = $objectManager->get(\Magento\Quote\Model\Quote::class);
48+
$quote->load('test01', 'reserved_order_id');
49+
$cartId = $quote->getId();
50+
if (!$cartId) {
51+
$this->fail('quote fixture failed');
52+
}
53+
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
54+
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
55+
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
56+
->create();
57+
$quoteIdMask->load($cartId, 'quote_id');
58+
//Use masked cart Id
59+
$cartId = $quoteIdMask->getMaskedId();
60+
$data = [
61+
'data' => [
62+
'country_id' => "US",
63+
'postcode' => null,
64+
'region' => null,
65+
'region_id' => null
66+
]
67+
];
68+
/** @var \Magento\Quote\Api\Data\EstimateAddressInterface $address */
69+
$address = $objectManager->create(\Magento\Quote\Api\Data\EstimateAddressInterface::class, $data);
70+
/** @var \Magento\Quote\Api\GuestShippingMethodManagementInterface $shippingEstimation */
71+
$shippingEstimation = $objectManager->get(\Magento\Quote\Api\GuestShippingMethodManagementInterface::class);
72+
$result = $shippingEstimation->estimateByAddress($cartId, $address);
73+
$this->assertNotEmpty($result);
74+
$expectedResult = [
75+
'method_code' => 'bestway',
76+
'amount' => 0
77+
];
78+
foreach ($result as $rate) {
79+
$this->assertEquals($expectedResult['amount'], $rate->getAmount());
80+
$this->assertEquals($expectedResult['method_code'], $rate->getMethodCode());
81+
}
82+
}
83+
3384
/**
3485
* @magentoConfigFixture current_store carriers/tablerate/active 1
3586
* @magentoConfigFixture current_store carriers/tablerate/condition_name package_qty
@@ -53,6 +104,7 @@ public function testEstimateByAddressWithCartPriceRuleByItem()
53104
*/
54105
public function testEstimateByAddressWithCartPriceRuleByShipment()
55106
{
107+
$this->markTestSkipped('According to MAGETWO-69940 it is an incorrect behavior');
56108
// Rule applied to entire shipment should not overwrite flat or table rate shipping prices
57109
// Only rules applied to specific items should modify those prices (MAGETWO-63844)
58110
$this->executeTestFlow(5, 10);

0 commit comments

Comments
 (0)