10 use Magento\Directory\Model\CountryFactory;
43 private $taxRateSearchResultsFactory;
73 private $collectionProcessor;
89 \
Magento\Tax\Api\Data\TaxRuleSearchResultsInterfaceFactory $taxRateSearchResultsFactory,
99 $this->taxRateSearchResultsFactory = $taxRateSearchResultsFactory;
100 $this->rateFactory = $rateFactory;
103 $this->resourceModel = $rateResource;
105 $this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
114 $this->rateRegistry->retrieveTaxRate(
$taxRate->getId());
117 $taxRateTitles = $this->converter->createTitleArrayFromServiceObject(
$taxRate);
119 $this->resourceModel->save(
$taxRate);
120 $taxRate->saveTitles($taxRateTitles);
124 $this->rateRegistry->registerTaxRate(
$taxRate);
131 public function get($rateId)
133 return $this->rateRegistry->retrieveTaxRate($rateId);
141 return $this->resourceModel->delete(
$taxRate);
149 $rateModel = $this->rateRegistry->retrieveTaxRate($rateId);
150 $this->
delete($rateModel);
151 $this->rateRegistry->removeTaxRate($rateId);
161 $collection = $this->rateFactory->create()->getCollection();
173 return $this->taxRateSearchResultsFactory->create()
192 foreach ($filterGroup->
getFilters() as $filter) {
193 $condition = $filter->getConditionType() ? $filter->getConditionType() :
'eq';
195 $conditions[] = [$condition => $filter->getValue()];
213 return 'region_table.code';
215 return "main_table." . $field;
233 $countryCode =
$taxRate->getTaxCountryId();
235 $exception->addError(
__(
'"%fieldName" is required. Enter and try again.', [
'fieldName' =>
'country_id']));
237 $this->countryFactory->create()->loadByCode($countryCode)->getId(),
240 $exception->addError(
242 'Invalid value of "%value" provided for the %fieldName field.',
244 'fieldName' =>
'country_id',
245 'value' => $countryCode
251 $regionCode =
$taxRate->getTaxRegionId();
255 $this->regionFactory->create()->load($regionCode)->getId(),
259 $exception->addError(
261 'Invalid value of "%value" provided for the %fieldName field.',
262 [
'fieldName' =>
'region_id',
'value' => $regionCode]
268 $exception->addError(
269 __(
'"%fieldName" is required. Enter and try again.', [
'fieldName' =>
'percentage_rate'])
274 $exception->addError(
__(
'"%fieldName" is required. Enter and try again.', [
'fieldName' =>
'code']));
279 'zip_from' =>
$taxRate->getZipFrom(),
282 foreach ($zipRangeFromTo as $key =>
$value) {
284 $exception->addError(
286 'Invalid value of "%value" provided for the %fieldName field.',
287 [
'fieldName' => $key,
'value' =>
$value]
292 if ($zipRangeFromTo[
'zip_from'] > $zipRangeFromTo[
'zip_to']) {
293 $exception->addError(
__(
'Range To should be equal or greater than Range From.'));
297 $exception->addError(
__(
'"%fieldName" is required. Enter and try again.', [
'fieldName' =>
'postcode']));
301 if ($exception->wasErrorAdded()) {
312 private function getCollectionProcessor()
314 if (!$this->collectionProcessor) {
316 'Magento\Tax\Model\Api\SearchCriteria\TaxRateCollectionProcessor' 319 return $this->collectionProcessor;
getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
elseif(isset( $params[ 'redirect_parent']))
addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection)
const MESSAGE_TAX_RATE_ID_IS_NOT_ALLOWED
static is($value, $classBaseName, array $args=array(), $namespaces=array())
__construct(Converter $converter, RateRegistry $rateRegistry, \Magento\Tax\Api\Data\TaxRuleSearchResultsInterfaceFactory $taxRateSearchResultsFactory, RateFactory $rateFactory, CountryFactory $countryFactory, RegionFactory $regionFactory, \Magento\Tax\Model\ResourceModel\Calculation\Rate $rateResource, \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor, CollectionProcessorInterface $collectionProcessor=null)
save(\Magento\Tax\Api\Data\TaxRateInterface $taxRate)