예제 #1
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;
 }
예제 #2
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;
 }