-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:magento/magento2ce into MAGETWO-…
…67087
- Loading branch information
Showing
27 changed files
with
468 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Tax\Setup; | ||
|
||
use Magento\Directory\Model\RegionFactory; | ||
use Magento\Framework\Api\Search\SearchCriteriaFactory; | ||
use Magento\Framework\Setup\InstallDataInterface; | ||
use Magento\Framework\Setup\ModuleContextInterface; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Tax\Api\TaxRateRepositoryInterface; | ||
|
||
/** | ||
* Update installed tax region codes | ||
*/ | ||
class RecurringData implements InstallDataInterface | ||
{ | ||
/** | ||
* Tax rate repository | ||
* | ||
* @var TaxRateRepositoryInterface | ||
*/ | ||
private $taxRateRepository; | ||
|
||
/** | ||
* @var SearchCriteriaFactory | ||
*/ | ||
|
||
private $searchCriteriaFactory; | ||
|
||
/** | ||
* @var RegionFactory | ||
*/ | ||
private $directoryRegionFactory; | ||
|
||
/** | ||
* Init | ||
* | ||
* @param TaxRateRepositoryInterface $taxRateRepository | ||
* @param SearchCriteriaFactory $searchCriteriaFactory | ||
* @param RegionFactory $directoryRegionFactory | ||
*/ | ||
public function __construct( | ||
TaxRateRepositoryInterface $taxRateRepository, | ||
SearchCriteriaFactory $searchCriteriaFactory, | ||
RegionFactory $directoryRegionFactory | ||
) { | ||
$this->taxRateRepository = $taxRateRepository; | ||
$this->searchCriteriaFactory = $searchCriteriaFactory; | ||
$this->directoryRegionFactory = $directoryRegionFactory; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) | ||
{ | ||
$taxRateList = $this->taxRateRepository->getList($this->searchCriteriaFactory->create()); | ||
/** @var \Magento\Tax\Api\Data\TaxRateInterface $taxRateData */ | ||
foreach ($taxRateList->getItems() as $taxRateData) { | ||
$regionCode = $this->parseRegionFromTaxCode($taxRateData->getCode()); | ||
if ($regionCode) { | ||
/** @var \Magento\Directory\Model\Region $region */ | ||
$region = $this->directoryRegionFactory->create(); | ||
$region->loadByCode($regionCode, $taxRateData->getTaxCountryId()); | ||
$taxRateData->setTaxRegionId($region->getRegionId()); | ||
$this->taxRateRepository->save($taxRateData); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Parse region code from tax code | ||
* | ||
* @param string $taxCode | ||
* @return string | ||
*/ | ||
private function parseRegionFromTaxCode($taxCode) | ||
{ | ||
$result = ''; | ||
$parts = explode('-', $taxCode, 3); | ||
|
||
if (isset($parts[1])) { | ||
$result = $parts[1]; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.