84 $this->_regionFactory = $regionFactory;
85 $this->_titleFactory = $taxTitleFactory;
120 $isEmptyValues = $this->
getCode() ===
'' ||
125 if ($isEmptyValues || $isWrongRange) {
126 throw new \Magento\Framework\Exception\LocalizedException(
127 __(
'The required information is invalid. Verify the information and try again.')
132 throw new \Magento\Framework\Exception\LocalizedException(
133 __(
'The Rate Percent is invalid. Enter a positive number and try again.')
141 if (strlen($zipFrom) > 9 || strlen($zipTo) > 9) {
142 throw new \Magento\Framework\Exception\LocalizedException(
144 'The ZIP Code length is invalid. ' 145 .
'Verify that the length is nine characters or fewer and try again.' 150 if (!is_numeric($zipFrom) || !is_numeric($zipTo) || $zipFrom < 0 || $zipTo < 0) {
151 throw new \Magento\Framework\Exception\LocalizedException(
152 __(
'The ZIP Code is invalid. Use numbers only.')
156 if ($zipFrom > $zipTo) {
157 throw new \Magento\Framework\Exception\LocalizedException(
158 __(
'Range To should be equal or greater than Range From.')
166 if (strlen($taxPostCode) > 10) {
167 $taxPostCode = substr($taxPostCode, 0, 10);
170 $this->
setTaxPostcode($taxPostCode)->setZipIsRange(
null)->setZipFrom(
null)->setZipTo(
null);
173 parent::beforeSave();
177 $regionModel = $this->_regionFactory->create();
178 $regionModel->load($region);
179 if ($regionModel->getCountryId() != $country) {
193 $this->_eventManager->dispatch(
'tax_settings_change_after');
194 return parent::afterSave();
207 __(
"The tax rate can't be removed because it exists in a tax rule.")
210 return parent::beforeDelete();
221 $this->_eventManager->dispatch(
'tax_settings_change_after');
222 return parent::afterDelete();
233 if ($titles ===
null) {
234 $titles = $this->getTitle();
238 if (is_array($titles) && $titles) {
243 )->setTaxCalculationRateId(
262 if ($this->_titleModel ===
null) {
263 $this->_titleModel = $this->_titleFactory->create();
273 if ($this->
getData(self::KEY_TITLES)) {
274 return $this->
getData(self::KEY_TITLES);
276 if ($this->_titles ===
null) {
277 $this->_titles = $this->
getTitleModel()->getCollection()->loadByRateId($this->
getId())->getItems();
290 $this->_eventManager->dispatch(
'tax_settings_change_after');
321 if (!$this->
getData(self::KEY_REGION_NAME)) {
322 $regionName = $this->directoryRegion->load($this->
getTaxRegionId())->getCode();
323 $this->
setData(self::KEY_REGION_NAME, $regionName);
325 return $this->
getData(self::KEY_REGION_NAME);
334 return $this->
getData(self::KEY_ID);
342 return $this->
getData(self::KEY_COUNTRY_ID);
350 return $this->
getData(self::KEY_REGION_ID);
358 return $this->
getData(self::KEY_POSTCODE);
366 return $this->
getData(self::KEY_ZIP_RANGE_FROM);
374 return $this->
getData(self::KEY_ZIP_RANGE_TO);
382 return $this->
getData(self::KEY_PERCENTAGE_RATE);
390 return $this->
getData(self::KEY_CODE);
398 return $this->
getData(self::KEY_ZIP_IS_RANGE);
409 return $this->
setData(self::KEY_COUNTRY_ID, $taxCountryId);
420 return $this->
setData(self::KEY_REGION_ID, $taxRegionId);
431 return $this->
setData(self::KEY_REGION_NAME, $regionName);
442 return $this->
setData(self::KEY_POSTCODE, $taxPostCode);
453 return $this->
setData(self::KEY_ZIP_IS_RANGE, $zipIsRange);
464 return $this->
setData(self::KEY_ZIP_RANGE_FROM, $zipFrom);
475 return $this->
setData(self::KEY_ZIP_RANGE_TO, $zipTo);
486 return $this->
setData(self::KEY_PERCENTAGE_RATE,
$rate);
508 return $this->
setData(self::KEY_TITLES, $titles);
_getExtensionAttributes()
setZipIsRange($zipIsRange)
setTitles(array $titles=null)
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
load($modelId, $field=null)
setTaxRegionId($taxRegionId)
getTaxCalculationRateId()
setTaxCountryId($taxCountryId)
getData($key='', $index=null)
setRegionName($regionName)
setData($key, $value=null)
setExtensionAttributes(\Magento\Tax\Api\Data\TaxRateExtensionInterface $extensionAttributes)
const KEY_PERCENTAGE_RATE
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Tax\Model\Calculation\Rate\TitleFactory $taxTitleFactory, Region $directoryRegion, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
setTaxPostcode($taxPostCode)