Skip to content

Commit 1cfa561

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-67283' into 2.2-develop-pr8
2 parents 3259107 + da303b8 commit 1cfa561

File tree

6 files changed

+177
-4
lines changed

6 files changed

+177
-4
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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\ModuleDataSetupInterface;
11+
use Magento\Framework\Setup\UpgradeDataInterface;
12+
13+
/**
14+
* Upgrade Data script.
15+
*/
16+
class UpgradeData implements UpgradeDataInterface
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(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
32+
{
33+
$setup->startSetup();
34+
if ($context->getVersion() && version_compare($context->getVersion(), '2.0.1') < 0) {
35+
$this->updateQuoteShippingAddresses($setup);
36+
}
37+
$setup->endSetup();
38+
}
39+
40+
/**
41+
* Replace Null with '0' for 'free_shipping' and 'simple_free_shipping' accordingly to upgraded schema.
42+
*
43+
* @param ModuleDataSetupInterface $setup
44+
* @return void
45+
*/
46+
private function updateQuoteShippingAddresses(ModuleDataSetupInterface $setup)
47+
{
48+
$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(
59+
$setup->getTable('quote_address'),
60+
['free_shipping' => 0],
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')]
67+
);
68+
}
69+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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' and 'simple_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+
$setup->getConnection(self::$salesConnectionName)->modifyColumn(
62+
$setup->getTable('sales_order_item', self::$salesConnectionName),
63+
'free_shipping',
64+
[
65+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
66+
'unsigned' => true,
67+
'nullable' => false,
68+
'default' => '0',
69+
'comment' => 'Free Shipping',
70+
]
71+
);
72+
$setup->getConnection(self::$quoteConnectionName)->modifyColumn(
73+
$setup->getTable('quote_address', self::$quoteConnectionName),
74+
'free_shipping',
75+
[
76+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
77+
'unsigned' => true,
78+
'nullable' => false,
79+
'default' => '0',
80+
'comment' => 'Free Shipping',
81+
]
82+
);
83+
$setup->getConnection(self::$quoteConnectionName)->modifyColumn(
84+
$setup->getTable('quote_item', self::$quoteConnectionName),
85+
'free_shipping',
86+
[
87+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
88+
'unsigned' => true,
89+
'nullable' => false,
90+
'default' => '0',
91+
'comment' => 'Free Shipping',
92+
]
93+
);
94+
$setup->getConnection(self::$quoteConnectionName)->modifyColumn(
95+
$setup->getTable('quote_address_item', self::$quoteConnectionName),
96+
'free_shipping',
97+
[
98+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
99+
'unsigned' => true,
100+
'comment' => 'Free Shipping',
101+
]
102+
);
103+
}
104+
}

app/code/Magento/OfflineShipping/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
"magento/module-backend": "100.2.*",
99
"magento/module-shipping": "100.2.*",
1010
"magento/module-catalog": "101.1.*",
11+
"magento/module-sales": "100.2.*",
1112
"magento/module-sales-rule": "100.2.*",
1213
"magento/module-directory": "100.2.*",
1314
"magento/module-quote": "100.2.*",
1415
"magento/framework": "100.2.*"
1516
},
1617
"suggest": {
1718
"magento/module-checkout": "100.2.*",
18-
"magento/module-sales": "100.2.*",
1919
"magento/module-offline-shipping-sample-data": "Sample Data version:100.2.*"
2020
},
2121
"type": "magento2-module",

app/code/Magento/OfflineShipping/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_OfflineShipping" setup_version="2.0.0">
9+
<module name="Magento_OfflineShipping" setup_version="2.0.1">
1010
<sequence>
1111
<module name="Magento_Store"/>
1212
<module name="Magento_Sales"/>

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
@@ -329,7 +329,7 @@ public function testApplyCoupon()
329329
$quoteMock->expects($this->once())->method('setCouponCode')->with($couponCode)->willReturnSelf();
330330

331331
$addressMock->expects($this->once())->method('setCollectShippingRates')->with(true)->willReturnSelf();
332-
$addressMock->expects($this->once())->method('setFreeShipping')->with(null)->willReturnSelf();
332+
$addressMock->expects($this->once())->method('setFreeShipping')->with(0)->willReturnSelf();
333333

334334
$object = $this->adminOrderCreate->applyCoupon($couponCode);
335335
$this->assertEquals($this->adminOrderCreate, $object);

0 commit comments

Comments
 (0)