Skip to content

Commit 0dcef95

Browse files
committed
MAGETWO-64499: Error during deploying using " auto_increment_increment = 3" as Mysql option
1 parent 21f6525 commit 0dcef95

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

app/code/Magento/Tax/Setup/InstallData.php

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Tax\Setup;
88

9+
use Magento\Directory\Model\ResourceModel\Region\CollectionFactory;
10+
use Magento\Framework\App\ObjectManager;
911
use Magento\Framework\Setup\InstallDataInterface;
1012
use Magento\Framework\Setup\ModuleContextInterface;
1113
use Magento\Framework\Setup\ModuleDataSetupInterface;
@@ -22,14 +24,34 @@ class InstallData implements InstallDataInterface
2224
*/
2325
private $taxSetupFactory;
2426

27+
/**
28+
* Region collection factory.
29+
*
30+
* @var \Magento\Directory\Model\ResourceModel\Region\CollectionFactory
31+
*/
32+
private $regionCollectionFactory;
33+
34+
/**
35+
* Region collection.
36+
*
37+
* @var \Magento\Directory\Model\ResourceModel\Region\Collection
38+
*/
39+
private $regionCollection;
40+
2541
/**
2642
* Init
2743
*
2844
* @param TaxSetupFactory $taxSetupFactory
45+
* @param CollectionFactory $collectionFactory
2946
*/
30-
public function __construct(TaxSetupFactory $taxSetupFactory)
31-
{
47+
public function __construct(
48+
TaxSetupFactory $taxSetupFactory,
49+
CollectionFactory $collectionFactory = null
50+
) {
3251
$this->taxSetupFactory = $taxSetupFactory;
52+
$this->regionCollectionFactory = $collectionFactory ?: ObjectManager::getInstance()->get(
53+
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory::class
54+
);
3355
}
3456

3557
/**
@@ -101,22 +123,41 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
101123
[
102124
'tax_calculation_rate_id' => 1,
103125
'tax_country_id' => 'US',
104-
'tax_region_id' => 12,
126+
'tax_region_id' => $this->getRegionId('CA'),
105127
'tax_postcode' => '*',
106128
'code' => 'US-CA-*-Rate 1',
107129
'rate' => '8.2500',
108130
],
109131
[
110132
'tax_calculation_rate_id' => 2,
111133
'tax_country_id' => 'US',
112-
'tax_region_id' => 43,
134+
'tax_region_id' => $this->getRegionId('NY'),
113135
'tax_postcode' => '*',
114136
'code' => 'US-NY-*-Rate 1',
115137
'rate' => '8.3750'
116138
],
117139
];
140+
118141
foreach ($data as $row) {
119142
$setup->getConnection()->insertForce($setup->getTable('tax_calculation_rate'), $row);
120143
}
121144
}
145+
146+
/**
147+
* Return region id by code.
148+
*
149+
* @param string $regionCode
150+
* @return mixed
151+
*/
152+
private function getRegionId($regionCode)
153+
{
154+
if ($this->regionCollection === null) {
155+
/** @var \Magento\Directory\Model\ResourceModel\Region\Collection $regionCollection */
156+
$this->regionCollection = $this->regionCollectionFactory->create();
157+
$this->regionCollection->addCountryFilter('US')
158+
->addRegionCodeOrNameFilter(['CA', 'NY']);
159+
}
160+
161+
return $this->regionCollection->getItemByColumnValue('code', $regionCode)->getId();
162+
}
122163
}

0 commit comments

Comments
 (0)