Skip to content

Commit 9f2fd3b

Browse files
committed
MAGETWO-70299: Error during Sample Data deploying using " auto_increment_increment = 3" as Mysql option (2.2)
1 parent 68a79d9 commit 9f2fd3b

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

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

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Tax\Setup;
88

9+
use Magento\Directory\Model\ResourceModel\Region\CollectionFactory;
910
use Magento\Framework\Setup\InstallDataInterface;
1011
use Magento\Framework\Setup\ModuleContextInterface;
1112
use Magento\Framework\Setup\ModuleDataSetupInterface;
@@ -22,14 +23,32 @@ class InstallData implements InstallDataInterface
2223
*/
2324
private $taxSetupFactory;
2425

26+
/**
27+
* Region collection factory.
28+
*
29+
* @var \Magento\Directory\Model\ResourceModel\Region\CollectionFactory
30+
*/
31+
private $regionCollectionFactory;
32+
33+
/**
34+
* Region collection.
35+
*
36+
* @var \Magento\Directory\Model\ResourceModel\Region\Collection
37+
*/
38+
private $regionCollection;
39+
2540
/**
2641
* Init
2742
*
2843
* @param TaxSetupFactory $taxSetupFactory
44+
* @param CollectionFactory $collectionFactory
2945
*/
30-
public function __construct(TaxSetupFactory $taxSetupFactory)
31-
{
46+
public function __construct(
47+
TaxSetupFactory $taxSetupFactory,
48+
CollectionFactory $collectionFactory
49+
) {
3250
$this->taxSetupFactory = $taxSetupFactory;
51+
$this->regionCollectionFactory = $collectionFactory;
3352
}
3453

3554
/**
@@ -55,7 +74,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
5574
'label' => 'Tax Class',
5675
'input' => 'select',
5776
'class' => '',
58-
'source' => \Magento\Tax\Model\TaxClass\Source\Product::class,
77+
'source' => 'Magento\Tax\Model\TaxClass\Source\Product',
5978
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE,
6079
'visible' => true,
6180
'required' => false,
@@ -101,22 +120,49 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
101120
[
102121
'tax_calculation_rate_id' => 1,
103122
'tax_country_id' => 'US',
104-
'tax_region_id' => 12,
123+
'tax_region_id' => $this->getRegionId('CA'),
105124
'tax_postcode' => '*',
106125
'code' => 'US-CA-*-Rate 1',
107126
'rate' => '8.2500',
108127
],
109128
[
110129
'tax_calculation_rate_id' => 2,
111130
'tax_country_id' => 'US',
112-
'tax_region_id' => 43,
131+
'tax_region_id' => $this->getRegionId('NY'),
113132
'tax_postcode' => '*',
114133
'code' => 'US-NY-*-Rate 1',
115134
'rate' => '8.3750'
116135
],
117136
];
137+
118138
foreach ($data as $row) {
119139
$setup->getConnection()->insertForce($setup->getTable('tax_calculation_rate'), $row);
120140
}
121141
}
142+
143+
/**
144+
* Return region id by code.
145+
*
146+
* @param string $regionCode
147+
* @return string
148+
*/
149+
private function getRegionId($regionCode)
150+
{
151+
if ($this->regionCollection === null) {
152+
/** @var \Magento\Directory\Model\ResourceModel\Region\Collection $regionCollection */
153+
$this->regionCollection = $this->regionCollectionFactory->create();
154+
$this->regionCollection->addCountryFilter('US')
155+
->addRegionCodeOrNameFilter(['CA', 'NY']);
156+
}
157+
158+
$regionId = '';
159+
160+
/** @var \Magento\Directory\Model\Region $item */
161+
$item = $this->regionCollection->getItemByColumnValue('code', $regionCode);
162+
if ($item) {
163+
$regionId = $item->getId();
164+
}
165+
166+
return $regionId;
167+
}
122168
}

0 commit comments

Comments
 (0)