Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function updateTaxRate(TaxRateDataObject $taxRate)
 {
     // Only update existing tax rates
     $this->rateRegistry->retrieveTaxRate($taxRate->getId());
     $this->saveTaxRate($taxRate);
     return true;
 }
Пример #2
0
 /**
  * Creates a collection item that represents a tax rate for the tax rates grid.
  *
  * @param TaxRate $taxRate Input data for creating the item.
  * @return \Magento\Framework\Object Collection item that represents a tax rate
  */
 protected function createTaxRateCollectionItem(TaxRate $taxRate)
 {
     $collectionItem = new \Magento\Framework\Object();
     $collectionItem->setTaxCalculationRateId($taxRate->getId());
     $collectionItem->setCode($taxRate->getCode());
     $collectionItem->setTaxCountryId($taxRate->getCountryId());
     $collectionItem->setTaxRegionId($taxRate->getRegionId());
     $collectionItem->setRegionName($taxRate->getRegionName());
     $collectionItem->setTaxPostcode($taxRate->getPostcode());
     $collectionItem->setRate($taxRate->getPercentageRate());
     $collectionItem->setTitles($this->rateConverter->createTitleArrayFromServiceObject($taxRate));
     if ($taxRate->getZipRange() != null) {
         $zipRange = $taxRate->getZipRange();
         /* must be a "1" for existing code (e.g. JavaScript) to work */
         $collectionItem->setZipIsRange("1");
         $collectionItem->setZipFrom($zipRange->getFrom());
         $collectionItem->setZipTo($zipRange->getTo());
     } else {
         $collectionItem->setZipIsRange(null);
         $collectionItem->setZipFrom(null);
         $collectionItem->setZipTo(null);
     }
     return $collectionItem;
 }
Пример #3
0
 /**
  * Extract tax rate data in a format which is
  *
  * @param \Magento\Tax\Service\V1\Data\TaxRate $taxRate
  * @return array
  */
 protected function extractTaxRateData($taxRate)
 {
     $zipRange = $taxRate->getZipRange();
     $formData = ['tax_calculation_rate_id' => $taxRate->getId(), 'tax_country_id' => $taxRate->getCountryId(), 'tax_region_id' => $taxRate->getRegionId(), 'tax_postcode' => $taxRate->getPostcode(), 'code' => $taxRate->getCode(), 'rate' => $taxRate->getPercentageRate(), 'zip_is_range' => false];
     if ($zipRange) {
         $formData['zip_is_range'] = true;
         $formData['zip_from'] = $zipRange->getFrom();
         $formData['zip_to'] = $zipRange->getTo();
     }
     if ($taxRate->getTitles()) {
         $titleData = [];
         foreach ($taxRate->getTitles() as $title) {
             $titleData[] = [$title->getStoreId() => $title->getValue()];
         }
         $formData['title'] = $titleData;
     }
     return $formData;
 }
Пример #4
0
 /**
  * Convert a TaxRate data object to rate model
  *
  * @param TaxRateDataObject $taxRate
  * @return TaxRateModel
  */
 public function createTaxRateModel(TaxRateDataObject $taxRate)
 {
     $rateModel = $this->taxRateModelFactory->create();
     $rateId = $taxRate->getId();
     if ($rateId) {
         $rateModel->setId($rateId);
     }
     $rateModel->setTaxCountryId($taxRate->getCountryId());
     $rateModel->setTaxRegionId($taxRate->getRegionId());
     $rateModel->setRate($taxRate->getPercentageRate());
     $rateModel->setCode($taxRate->getCode());
     $rateModel->setTaxPostcode($taxRate->getPostCode());
     $rateModel->setRegionName($taxRate->getRegionName());
     $zipRange = $taxRate->getZipRange();
     if ($zipRange) {
         $zipFrom = $zipRange->getFrom();
         $zipTo = $zipRange->getTo();
         if (!empty($zipFrom) || !empty($zipTo)) {
             $rateModel->setZipIsRange(1);
         }
         $rateModel->setZipFrom($zipFrom);
         $rateModel->setZipTo($zipTo);
     }
     return $rateModel;
 }