Exemplo n.º 1
0
 /**
  * Initialize tax rule service object with form data.
  *
  * @param array $postData
  * @return \Magento\Tax\Api\Data\TaxRuleInterface
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function populateTaxRule($postData)
 {
     $taxRule = $this->taxRuleDataObjectFactory->create();
     if (isset($postData['tax_calculation_rule_id'])) {
         $taxRule->setId($postData['tax_calculation_rule_id']);
     }
     if (isset($postData['code'])) {
         $taxRule->setCode($postData['code']);
     }
     if (isset($postData['tax_rate'])) {
         $taxRule->setTaxRateIds($postData['tax_rate']);
     }
     if (isset($postData['tax_customer_class'])) {
         $taxRule->setCustomerTaxClassIds($postData['tax_customer_class']);
     }
     if (isset($postData['tax_product_class'])) {
         $taxRule->setProductTaxClassIds($postData['tax_product_class']);
     }
     if (isset($postData['priority'])) {
         $taxRule->setPriority($postData['priority']);
     }
     if (isset($postData['calculate_subtotal'])) {
         $taxRule->setCalculateSubtotal($postData['calculate_subtotal']);
     }
     if (isset($postData['position'])) {
         $taxRule->setPosition($postData['position']);
     }
     return $taxRule;
 }
Exemplo n.º 2
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('.');
     }
 }
Exemplo n.º 4
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);
         }
     }
 }
 /**
  * Creates Tax Rule Data Object
  *
  * @return \Magento\Tax\Api\Data\TaxRuleInterface
  */
 private function createTaxRuleDataObject()
 {
     $taxRule = $this->taxRuleFactory->create();
     $taxRule->setCode('code')->setCustomerTaxClassIds([3])->setProductTaxClassIds([2])->setTaxRateIds([2])->setPriority(0)->setPosition(1);
     return $taxRule;
 }