Beispiel #1
0
 /**
  * Convert a rate model to a TaxRate data object
  *
  * @param TaxRateModel $rateModel
  * @return TaxRateDataObject
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function createTaxRateDataObjectFromModel(TaxRateModel $rateModel)
 {
     $this->taxRateDataObjectBuilder->populateWithArray([]);
     if ($rateModel->getId()) {
         $this->taxRateDataObjectBuilder->setId($rateModel->getId());
     }
     if ($rateModel->getTaxCountryId()) {
         $this->taxRateDataObjectBuilder->setCountryId($rateModel->getTaxCountryId());
     }
     /* tax region id may be 0 which is "*" which would fail an if check */
     if ($rateModel->getTaxRegionId() !== null) {
         $this->taxRateDataObjectBuilder->setRegionId($rateModel->getTaxRegionId());
         $regionName = $this->directoryRegion->load($rateModel->getTaxRegionId())->getCode();
         $this->taxRateDataObjectBuilder->setRegionName($regionName);
     }
     if ($rateModel->getRegionName()) {
         $this->taxRateDataObjectBuilder->setRegionName($rateModel->getRegionName());
     }
     if ($rateModel->getTaxPostcode()) {
         $this->taxRateDataObjectBuilder->setPostcode($rateModel->getTaxPostcode());
     }
     if ($rateModel->getCode()) {
         $this->taxRateDataObjectBuilder->setCode($rateModel->getCode());
     }
     if ($rateModel->getRate()) {
         $this->taxRateDataObjectBuilder->setPercentageRate((double) $rateModel->getRate());
     }
     if ($rateModel->getZipIsRange()) {
         $zipRange = $this->zipRangeDataObjectBuilder->populateWithArray([])->setFrom($rateModel->getZipFrom())->setTo($rateModel->getZipTo())->create();
         $this->taxRateDataObjectBuilder->setZipRange($zipRange);
     }
     $this->taxRateDataObjectBuilder->setTitles($this->createTitleArrayFromModel($rateModel));
     return $this->taxRateDataObjectBuilder->create();
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 protected function _setDataValues(array $data)
 {
     if (array_key_exists(TaxRate::KEY_ZIP_RANGE, $data)) {
         $data[TaxRate::KEY_ZIP_RANGE] = $this->zipRangeBuilder->populateWithArray($data[TaxRate::KEY_ZIP_RANGE])->create();
     }
     if (array_key_exists(TaxRate::KEY_TITLES, $data)) {
         $titles = array();
         foreach ($data[TaxRate::KEY_TITLES] as $titleData) {
             $titles[] = $this->taxRateTitleBuilder->populateWithArray($titleData)->create();
         }
         $data[TaxRate::KEY_TITLES] = $titles;
     }
     return parent::_setDataValues($data);
 }
Beispiel #3
0
 /**
  * Populate a tax rate data object
  *
  * @param array $formData
  * @return \Magento\Tax\Service\V1\Data\TaxRate
  */
 protected function populateTaxRateData($formData)
 {
     $this->_taxRateBuilder->setId($this->extractFormData($formData, 'tax_calculation_rate_id'))->setCountryId($this->extractFormData($formData, 'tax_country_id'))->setRegionId($this->extractFormData($formData, 'tax_region_id'))->setPostcode($this->extractFormData($formData, 'tax_postcode'))->setCode($this->extractFormData($formData, 'code'))->setPercentageRate($this->extractFormData($formData, 'rate'));
     if (isset($formData['zip_is_range']) && $formData['zip_is_range']) {
         $this->_zipRangeBuilder->setFrom($this->extractFormData($formData, 'zip_from'))->setTo($this->extractFormData($formData, 'zip_to'));
         $zipRange = $this->_zipRangeBuilder->create();
         $this->_taxRateBuilder->setZipRange($zipRange);
     }
     if (isset($formData['title'])) {
         $titles = [];
         foreach ($formData['title'] as $storeId => $value) {
             $titles[] = $this->_taxRateTitleBuilder->setStoreId($storeId)->setValue($value)->create();
         }
         $this->_taxRateBuilder->setTitles($titles);
     }
     return $this->_taxRateBuilder->create();
 }