Skip to content

Commit 551d7bc

Browse files
committed
MAGETWO-67283: quote_address.free_shipping is different depending on whether Magento was upgraded vs installed
1 parent 7b3ee01 commit 551d7bc

File tree

4 files changed

+136
-8
lines changed

4 files changed

+136
-8
lines changed

app/code/Magento/OfflineShipping/Setup/UpgradeData.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@
99
use Magento\Framework\Setup\ModuleContextInterface;
1010
use Magento\Framework\Setup\ModuleDataSetupInterface;
1111
use Magento\Framework\Setup\UpgradeDataInterface;
12-
use Magento\Quote\Model\Quote\Address;
1312

1413
/**
1514
* Upgrade Data script.
1615
*/
1716
class UpgradeData implements UpgradeDataInterface
1817
{
18+
/**
19+
* @var string
20+
*/
21+
private static $quoteConnectionName = 'checkout';
22+
23+
/**
24+
* @var string
25+
*/
26+
private static $salesConnectionName = 'sales';
27+
1928
/**
2029
* {@inheritdoc}
2130
*/
@@ -29,20 +38,32 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
2938
}
3039

3140
/**
32-
* Replace Null with '0' for free_shipping in quote shipping addresses.
41+
* Replace Null with '0' for 'free_shipping' and 'simple_free_shipping' accordingly to upgraded schema.
3342
*
3443
* @param ModuleDataSetupInterface $setup
3544
* @return void
3645
*/
3746
private function updateQuoteShippingAddresses(ModuleDataSetupInterface $setup)
3847
{
3948
$setup->getConnection()->update(
49+
$setup->getTable('salesrule'),
50+
['simple_free_shipping' => 0],
51+
[new \Zend_Db_Expr('simple_free_shipping IS NULL')]
52+
);
53+
$setup->getConnection(self::$salesConnectionName)->update(
54+
$setup->getTable('sales_order_item'),
55+
['free_shipping' => 0],
56+
[new \Zend_Db_Expr('free_shipping IS NULL')]
57+
);
58+
$setup->getConnection(self::$quoteConnectionName)->update(
4059
$setup->getTable('quote_address'),
4160
['free_shipping' => 0],
42-
[
43-
'address_type = ?' => Address::ADDRESS_TYPE_SHIPPING,
44-
new \Zend_Db_Expr('free_shipping IS NULL'),
45-
]
61+
[new \Zend_Db_Expr('free_shipping IS NULL')]
62+
);
63+
$setup->getConnection(self::$quoteConnectionName)->update(
64+
$setup->getTable('quote_item'),
65+
['free_shipping' => 0],
66+
[new \Zend_Db_Expr('free_shipping IS NULL')]
4667
);
4768
}
4869
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\OfflineShipping\Setup;
8+
9+
use Magento\Framework\Setup\ModuleContextInterface;
10+
use Magento\Framework\Setup\SchemaSetupInterface;
11+
use Magento\Framework\Setup\UpgradeSchemaInterface;
12+
13+
/**
14+
* Upgrade schema DB for OfflineShipping module.
15+
*/
16+
class UpgradeSchema implements UpgradeSchemaInterface
17+
{
18+
/**
19+
* @var string
20+
*/
21+
private static $quoteConnectionName = 'checkout';
22+
23+
/**
24+
* @var string
25+
*/
26+
private static $salesConnectionName = 'sales';
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
32+
{
33+
$setup->startSetup();
34+
35+
if (version_compare($context->getVersion(), '2.0.1', '<')) {
36+
$this->updateFreeShippingColumns($setup);
37+
}
38+
39+
$setup->endSetup();
40+
}
41+
42+
/**
43+
* Modify free_shipping columns added incorrectly in InstallSchema.
44+
*
45+
* @param SchemaSetupInterface $setup
46+
* @return void
47+
*/
48+
private function updateFreeShippingColumns(SchemaSetupInterface $setup)
49+
{
50+
$setup->getConnection()->modifyColumn(
51+
$setup->getTable('salesrule'),
52+
'simple_free_shipping',
53+
[
54+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
55+
'unsigned' => true,
56+
'nullable' => false,
57+
'default' => '0',
58+
'comment' => 'Simple Free Shipping',
59+
]
60+
61+
);
62+
$setup->getConnection(self::$salesConnectionName)->modifyColumn(
63+
$setup->getTable('sales_order_item', self::$salesConnectionName),
64+
'free_shipping',
65+
[
66+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
67+
'unsigned' => true,
68+
'nullable' => false,
69+
'default' => '0',
70+
'comment' => 'Free Shipping',
71+
]
72+
73+
);
74+
$setup->getConnection(self::$quoteConnectionName)->modifyColumn(
75+
$setup->getTable('quote_address', self::$quoteConnectionName),
76+
'free_shipping',
77+
[
78+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
79+
'unsigned' => true,
80+
'nullable' => false,
81+
'default' => '0',
82+
'comment' => 'Free Shipping',
83+
]
84+
85+
);
86+
$setup->getConnection(self::$quoteConnectionName)->modifyColumn(
87+
$setup->getTable('quote_item', self::$quoteConnectionName),
88+
'free_shipping',
89+
[
90+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
91+
'unsigned' => true,
92+
'nullable' => false,
93+
'default' => '0',
94+
'comment' => 'Free Shipping',
95+
]
96+
);
97+
$setup->getConnection(self::$quoteConnectionName)->modifyColumn(
98+
$setup->getTable('quote_address_item', self::$quoteConnectionName),
99+
'free_shipping',
100+
[
101+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
102+
'unsigned' => true,
103+
'comment' => 'Free Shipping',
104+
]
105+
);
106+
}
107+
}

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ public function applyCoupon($code)
15681568
$this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
15691569

15701570
if (empty($code)) {
1571-
$this->getQuote()->getShippingAddress()->setFreeShipping(null);
1571+
$this->getQuote()->getShippingAddress()->setFreeShipping(0);
15721572
}
15731573
$this->getQuote()->setCouponCode($code);
15741574
$this->setRecollect(true);

app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public function testApplyCoupon()
374374
$quoteMock->expects($this->once())->method('setCouponCode')->with($couponCode)->willReturnSelf();
375375

376376
$addressMock->expects($this->once())->method('setCollectShippingRates')->with(true)->willReturnSelf();
377-
$addressMock->expects($this->once())->method('setFreeShipping')->with(null)->willReturnSelf();
377+
$addressMock->expects($this->once())->method('setFreeShipping')->with(0)->willReturnSelf();
378378

379379
$this->adminOrderCreate->applyCoupon($couponCode);
380380
}

0 commit comments

Comments
 (0)