Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing taxes:');
     $fixtureFile = 'Tax/tax_rate.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\Tools\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $taxRate = $this->rateFactory->create();
         $taxRate->setCode($data['code'])->setTaxCountryId($data['tax_country_id'])->setTaxRegionId($data['tax_region_id'])->setTaxPostcode($data['tax_postcode'])->setRate($data['rate']);
         $this->taxRateRepository->save($taxRate);
         $this->logger->logInline('.');
     }
     $fixtureFile = 'Tax/tax_rule.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\Tools\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $taxRate = $this->taxRateFactory->create()->loadByCode($data['tax_rate']);
         $taxRule = $this->ruleFactory->create();
         $taxRule->setCode($data['code'])->setTaxRateIds([$taxRate->getId()])->setCustomerTaxClassIds([$data['tax_customer_class']])->setProductTaxClassIds([$data['tax_product_class']])->setPriority($data['priority'])->setCalculateSubtotal($data['calculate_subtotal'])->setPosition($data['position']);
         $this->taxRuleRepository->save($taxRule);
         $this->logger->logInline('.');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing taxes:');
     $fixtureFile = 'Tax/tax_rate.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         if ($this->rateFactory->create()->loadByCode($data['code'])->getId()) {
             continue;
         }
         $taxRate = $this->rateFactory->create();
         $taxRate->setCode($data['code'])->setTaxCountryId($data['tax_country_id'])->setTaxRegionId($data['tax_region_id'])->setTaxPostcode($data['tax_postcode'])->setRate($data['rate']);
         $this->taxRateRepository->save($taxRate);
         $this->logger->logInline('.');
     }
     $fixtureFile = 'Tax/tax_rule.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $filter = $this->filterBuilder->setField('code')->setConditionType('=')->setValue($data['code'])->create();
         $criteria = $this->criteriaBuilder->addFilters([$filter])->create();
         $existingRates = $this->taxRuleRepository->getList($criteria)->getItems();
         if (!empty($existingRates)) {
             continue;
         }
         $taxRate = $this->taxRateFactory->create()->loadByCode($data['tax_rate']);
         $taxRule = $this->ruleFactory->create();
         $taxRule->setCode($data['code'])->setTaxRateIds([$taxRate->getId()])->setCustomerTaxClassIds([$data['tax_customer_class']])->setProductTaxClassIds([$data['tax_product_class']])->setPriority($data['priority'])->setCalculateSubtotal($data['calculate_subtotal'])->setPosition($data['position']);
         $this->taxRuleRepository->save($taxRule);
         $this->logger->logInline('.');
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function install(array $fixtures)
 {
     foreach ($fixtures as $fileName) {
         $fileName = $this->fixtureManager->getFixture($fileName);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fileName);
         $header = array_shift($rows);
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             if ($this->rateFactory->create()->loadByCode($data['code'])->getId()) {
                 continue;
             }
             $taxRate = $this->rateFactory->create();
             $taxRate->setCode($data['code'])->setTaxCountryId($data['tax_country_id'])->setTaxRegionId($data['tax_region_id'])->setTaxPostcode($data['tax_postcode'])->setRate($data['rate']);
             $this->taxRateRepository->save($taxRate);
         }
         $fixtureFile = 'Magento_TaxSampleData::fixtures/tax_rule.csv';
         $fixtureFileName = $this->fixtureManager->getFixture($fixtureFile);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fixtureFileName);
         $header = array_shift($rows);
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             $filter = $this->filterBuilder->setField('code')->setConditionType('=')->setValue($data['code'])->create();
             $criteria = $this->criteriaBuilder->addFilters([$filter])->create();
             $existingRates = $this->taxRuleRepository->getList($criteria)->getItems();
             if (!empty($existingRates)) {
                 continue;
             }
             $taxRate = $this->taxRateFactory->create()->loadByCode($data['tax_rate']);
             $taxRule = $this->ruleFactory->create();
             $taxRule->setCode($data['code'])->setTaxRateIds([$taxRate->getId()])->setCustomerTaxClassIds([$data['tax_customer_class']])->setProductTaxClassIds([$data['tax_product_class']])->setPriority($data['priority'])->setCalculateSubtotal($data['calculate_subtotal'])->setPosition($data['position']);
             $this->taxRuleRepository->save($taxRule);
         }
     }
 }
 /**
  * @magentoDbIsolation enabled
  * @expectedException \Magento\Framework\Exception\CouldNotSaveException
  * @expectedExceptionMessage code is a required field
  */
 public function testSaveThrowsExceptionIsRequiredFieldsAreMissing()
 {
     $taxRule = $this->taxRuleRepository->save($this->createTaxRuleDataObject());
     $taxRule->setCode(null);
     $this->taxRuleRepository->save($taxRule);
 }