Пример #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();
 }
Пример #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);
 }