Skip to content

Commit bf99d3a

Browse files
author
Oleksii Korshenko
committed
MAGETWO-52905: Group product not found by weight using advanced search
- Merge remote-tracking branch 'origin/develop' into okapis-pr-branch
2 parents beb1fc4 + 522fad0 commit bf99d3a

File tree

12 files changed

+170
-85
lines changed

12 files changed

+170
-85
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
*/
1616
class InstallSchema implements InstallSchemaInterface
1717
{
18+
/**
19+
* @var string
20+
*/
21+
private static $quoteConnectionName = 'checkout';
22+
23+
/**
24+
* @var string
25+
*/
26+
private static $salesConnectionName = 'sales';
27+
1828
/**
1929
* {@inheritdoc}
2030
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -105,32 +115,32 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
105115
['unsigned' => true, 'nullable' => false, 'default' => '0'],
106116
'Simple Free Shipping'
107117
);
108-
$installer->getConnection()->addColumn(
109-
$installer->getTable('sales_order_item'),
118+
$installer->getConnection(self::$salesConnectionName)->addColumn(
119+
$installer->getTable('sales_order_item', self::$salesConnectionName),
110120
'free_shipping',
111121
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
112122
null,
113123
['unsigned' => true, 'nullable' => false, 'default' => '0'],
114124
'Free Shipping'
115125
);
116-
$installer->getConnection()->addColumn(
117-
$installer->getTable('quote_address'),
126+
$installer->getConnection(self::$quoteConnectionName)->addColumn(
127+
$installer->getTable('quote_address', self::$quoteConnectionName),
118128
'free_shipping',
119129
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
120130
null,
121131
['unsigned' => true, 'nullable' => false, 'default' => '0'],
122132
'Free Shipping'
123133
);
124-
$installer->getConnection()->addColumn(
125-
$installer->getTable('quote_item'),
134+
$installer->getConnection(self::$quoteConnectionName)->addColumn(
135+
$installer->getTable('quote_item', self::$quoteConnectionName),
126136
'free_shipping',
127137
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
128138
null,
129139
['unsigned' => true, 'nullable' => false, 'default' => '0'],
130140
'Free Shipping'
131141
);
132-
$installer->getConnection()->addColumn(
133-
$installer->getTable('quote_address_item'),
142+
$installer->getConnection(self::$quoteConnectionName)->addColumn(
143+
$installer->getTable('quote_address_item', self::$quoteConnectionName),
134144
'free_shipping',
135145
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
136146
null,

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.*",
1211
"magento/module-sales-rule": "100.2.*",
1312
"magento/module-directory": "100.2.*",
1413
"magento/module-quote": "100.2.*",
1514
"magento/framework": "100.2.*"
1615
},
1716
"suggest": {
1817
"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/Persistent/Setup/InstallSchema.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*/
1616
class InstallSchema implements InstallSchemaInterface
1717
{
18+
/**
19+
* @var string
20+
*/
21+
private static $connectionName = 'checkout';
22+
1823
/**
1924
* {@inheritdoc}
2025
*/
@@ -97,8 +102,8 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
97102
* Alter quote table with is_persistent flag
98103
*
99104
*/
100-
$installer->getConnection()->addColumn(
101-
$installer->getTable('quote'),
105+
$installer->getConnection(self::$connectionName)->addColumn(
106+
$installer->getTable('quote', self::$connectionName),
102107
'is_persistent',
103108
[
104109
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,

app/code/Magento/Quote/Setup/QuoteSetup.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class QuoteSetup extends EavSetup
2929
*/
3030
protected $_encryptor;
3131

32+
/**
33+
* @var string
34+
*/
35+
private static $connectionName = 'checkout';
36+
3237
/**
3338
* @param ModuleDataSetupInterface $setup
3439
* @param Context $context
@@ -70,8 +75,11 @@ public function __construct(
7075
*/
7176
protected function _flatTableExist($table)
7277
{
73-
$tablesList = $this->getSetup()->getConnection()->listTables();
74-
return in_array(strtoupper($this->getSetup()->getTable($table)), array_map('strtoupper', $tablesList));
78+
$tablesList = $this->getSetup()->getConnection(self::$connectionName)->listTables();
79+
return in_array(
80+
strtoupper($this->getSetup()->getTable($table, self::$connectionName)),
81+
array_map('strtoupper', $tablesList)
82+
);
7583
}
7684

7785
/**
@@ -107,13 +115,15 @@ public function addAttribute($entityTypeId, $code, array $attr)
107115
*/
108116
protected function _addFlatAttribute($table, $attribute, $attr)
109117
{
110-
$tableInfo = $this->getSetup()->getConnection()->describeTable($this->getSetup()->getTable($table));
118+
$tableInfo = $this->getSetup()
119+
->getConnection(self::$connectionName)
120+
->describeTable($this->getSetup()->getTable($table, self::$connectionName));
111121
if (isset($tableInfo[$attribute])) {
112122
return $this;
113123
}
114124
$columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr);
115-
$this->getSetup()->getConnection()->addColumn(
116-
$this->getSetup()->getTable($table),
125+
$this->getSetup()->getConnection(self::$connectionName)->addColumn(
126+
$this->getSetup()->getTable($table, self::$connectionName),
117127
$attribute,
118128
$columnDefinition
119129
);

app/code/Magento/Quote/Setup/UpgradeSchema.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
*/
1515
class UpgradeSchema implements UpgradeSchemaInterface
1616
{
17+
/**
18+
* @var string
19+
*/
20+
private static $connectionName = 'checkout';
21+
1722
/**
1823
* {@inheritdoc}
1924
*/
@@ -22,16 +27,16 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
2227
$setup->startSetup();
2328

2429
if (version_compare($context->getVersion(), '2.0.1', '<')) {
25-
$setup->getConnection()->addIndex(
26-
$setup->getTable('quote_id_mask'),
27-
$setup->getIdxName('quote_id_mask', ['masked_id']),
30+
$setup->getConnection(self::$connectionName)->addIndex(
31+
$setup->getTable('quote_id_mask', self::$connectionName),
32+
$setup->getIdxName('quote_id_mask', ['masked_id'], '', self::$connectionName),
2833
['masked_id']
2934
);
3035
}
3136

3237
if (version_compare($context->getVersion(), '2.0.2', '<')) {
33-
$setup->getConnection()->changeColumn(
34-
$setup->getTable('quote_address'),
38+
$setup->getConnection(self::$connectionName)->changeColumn(
39+
$setup->getTable('quote_address', self::$connectionName),
3540
'street',
3641
'street',
3742
[

app/code/Magento/Sales/Setup/SalesSetup.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/**
1616
* Setup Model of Sales Module
1717
* @codeCoverageIgnore
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1819
*/
1920
class SalesSetup extends \Magento\Eav\Setup\EavSetup
2021
{
@@ -48,6 +49,11 @@ class SalesSetup extends \Magento\Eav\Setup\EavSetup
4849
*/
4950
protected $encryptor;
5051

52+
/**
53+
* @var string
54+
*/
55+
private static $connectionName = 'sales';
56+
5157
/**
5258
* @param ModuleDataSetupInterface $setup
5359
* @param Context $context
@@ -105,8 +111,11 @@ public function __construct(
105111
*/
106112
protected function _flatTableExist($table)
107113
{
108-
$tablesList = $this->getSetup()->getConnection()->listTables();
109-
return in_array(strtoupper($this->getSetup()->getTable($table)), array_map('strtoupper', $tablesList));
114+
$tablesList = $this->getSetup()->getConnection(self::$connectionName)->listTables();
115+
return in_array(
116+
strtoupper($this->getSetup()->getTable($table, self::$connectionName)),
117+
array_map('strtoupper', $tablesList)
118+
);
110119
}
111120

112121
/**
@@ -143,13 +152,15 @@ public function addAttribute($entityTypeId, $code, array $attr)
143152
*/
144153
protected function _addFlatAttribute($table, $attribute, $attr)
145154
{
146-
$tableInfo = $this->getSetup()->getConnection()->describeTable($this->getSetup()->getTable($table));
155+
$tableInfo = $this->getSetup()
156+
->getConnection(self::$connectionName)
157+
->describeTable($this->getSetup()->getTable($table, self::$connectionName));
147158
if (isset($tableInfo[$attribute])) {
148159
return $this;
149160
}
150161
$columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr);
151-
$this->getSetup()->getConnection()->addColumn(
152-
$this->getSetup()->getTable($table),
162+
$this->getSetup()->getConnection(self::$connectionName)->addColumn(
163+
$this->getSetup()->getTable($table, self::$connectionName),
153164
$attribute,
154165
$columnDefinition
155166
);
@@ -169,8 +180,8 @@ protected function _addGridAttribute($table, $attribute, $attr, $entityTypeId)
169180
{
170181
if (in_array($entityTypeId, $this->_flatEntitiesGrid) && !empty($attr['grid'])) {
171182
$columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr);
172-
$this->getSetup()->getConnection()->addColumn(
173-
$this->getSetup()->getTable($table . '_grid'),
183+
$this->getSetup()->getConnection(self::$connectionName)->addColumn(
184+
$this->getSetup()->getTable($table . '_grid', self::$connectionName),
174185
$attribute,
175186
$columnDefinition
176187
);

app/code/Magento/Sales/Setup/UpgradeSchema.php

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@
55
*/
66
namespace Magento\Sales\Setup;
77

8-
use Magento\Framework\App\ResourceConnection;
98
use Magento\Framework\Setup\UpgradeSchemaInterface;
109
use Magento\Framework\Setup\ModuleContextInterface;
1110
use Magento\Framework\Setup\SchemaSetupInterface;
12-
use Magento\Framework\DB\Adapter\AdapterInterface;
1311

1412
/**
1513
* @codeCoverageIgnore
1614
*/
1715
class UpgradeSchema implements UpgradeSchemaInterface
1816
{
1917
/**
20-
* @var AdapterInterface
18+
* @var string
2119
*/
22-
private $salesConnection;
20+
private static $connectionName = 'sales';
2321

2422
/**
2523
* {@inheritdoc}
@@ -29,36 +27,39 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
2927
$installer = $setup;
3028
$installer->startSetup();
3129
if (version_compare($context->getVersion(), '2.0.2', '<')) {
32-
$connection = $installer->getConnection();
30+
$connection = $installer->getConnection(self::$connectionName);
3331
//sales_bestsellers_aggregated_daily
3432
$connection->dropForeignKey(
35-
$installer->getTable('sales_bestsellers_aggregated_daily'),
33+
$installer->getTable('sales_bestsellers_aggregated_daily', self::$connectionName),
3634
$installer->getFkName(
3735
'sales_bestsellers_aggregated_daily',
3836
'product_id',
3937
'catalog_product_entity',
40-
'entity_id'
38+
'entity_id',
39+
self::$connectionName
4140
)
4241
);
4342
//sales_bestsellers_aggregated_monthly
4443
$connection->dropForeignKey(
45-
$installer->getTable('sales_bestsellers_aggregated_monthly'),
44+
$installer->getTable('sales_bestsellers_aggregated_monthly', self::$connectionName),
4645
$installer->getFkName(
4746
'sales_bestsellers_aggregated_monthly',
4847
'product_id',
4948
'catalog_product_entity',
50-
'entity_id'
49+
'entity_id',
50+
self::$connectionName
5151
)
5252
);
5353

5454
//sales_bestsellers_aggregated_yearly
5555
$connection->dropForeignKey(
56-
$installer->getTable('sales_bestsellers_aggregated_yearly'),
56+
$installer->getTable('sales_bestsellers_aggregated_yearly', self::$connectionName),
5757
$installer->getFkName(
5858
'sales_bestsellers_aggregated_yearly',
5959
'product_id',
6060
'catalog_product_entity',
61-
'entity_id'
61+
'entity_id',
62+
self::$connectionName
6263
)
6364
);
6465

@@ -76,9 +77,9 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
7677
*/
7778
private function addColumnBaseGrandTotal(SchemaSetupInterface $installer)
7879
{
79-
$connection = $this->getSalesConnection();
80+
$connection = $installer->getConnection(self::$connectionName);
8081
$connection->addColumn(
81-
$installer->getTable('sales_invoice_grid'),
82+
$installer->getTable('sales_invoice_grid', self::$connectionName),
8283
'base_grand_total',
8384
[
8485
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
@@ -96,29 +97,11 @@ private function addColumnBaseGrandTotal(SchemaSetupInterface $installer)
9697
*/
9798
private function addIndexBaseGrandTotal(SchemaSetupInterface $installer)
9899
{
99-
$connection = $this->getSalesConnection();
100+
$connection = $installer->getConnection(self::$connectionName);
100101
$connection->addIndex(
101-
$installer->getTable('sales_invoice_grid'),
102-
$installer->getIdxName('sales_invoice_grid', ['base_grand_total']),
102+
$installer->getTable('sales_invoice_grid', self::$connectionName),
103+
$installer->getIdxName('sales_invoice_grid', ['base_grand_total'], '', self::$connectionName),
103104
['base_grand_total']
104105
);
105106
}
106-
107-
/**
108-
* @return AdapterInterface
109-
*/
110-
private function getSalesConnection()
111-
{
112-
if ($this->salesConnection === null) {
113-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
114-
/** @var ResourceConnection $resourceConnection */
115-
$resourceConnection = $objectManager->get(ResourceConnection::class);
116-
try {
117-
$this->salesConnection = $resourceConnection->getConnectionByName('sales');
118-
} catch (\DomainException $e) {
119-
$this->salesConnection = $resourceConnection->getConnection();
120-
}
121-
}
122-
return $this->salesConnection;
123-
}
124107
}

0 commit comments

Comments
 (0)