Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxRatesFixture.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Setup\Fixtures;
8 
18 class TaxRatesFixture extends Fixture
19 {
23  protected $priority = 100;
24 
28  public function execute()
29  {
30  $taxRatesFile = $this->fixtureModel->getValue('tax_rates_file', null);
31  if (empty($taxRatesFile)) {
32  return;
33  }
34  $this->fixtureModel->resetObjectManager();
37  $collection = $this->fixtureModel->getObjectManager()
38  ->get(\Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection::class);
39 
41  $model = $this->fixtureModel->getObjectManager()
42  ->get(\Magento\Tax\Model\Calculation\Rate::class);
43 
44  foreach ($collection->getAllIds() as $id) {
45  $model->setId($id);
46  $model->delete();
47  }
51  $filename = realpath(__DIR__ . DIRECTORY_SEPARATOR . "_files" . DIRECTORY_SEPARATOR . $taxRatesFile);
52  $file = [
53  'name' => $filename,
54  'type' => 'fixtureModel/vnd.ms-excel',
55  'tmp_name' => $filename,
56  'error' => 0,
57  'size' => filesize($filename),
58  ];
59  $importHandler = $this->fixtureModel->getObjectManager()
60  ->create(\Magento\TaxImportExport\Model\Rate\CsvImportHandler::class);
61  $importHandler->importFromCsvFile($file);
62  }
63 
67  public function getActionTitle()
68  {
69  return 'Generating tax rates';
70  }
71 
75  public function introduceParamLabels()
76  {
77  return [];
78  }
79 }
$id
Definition: fieldset.phtml:14
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60