![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-tax/Model/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Tax\Model; use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Tax\Api\TaxRateManagementInterface; use Magento\Tax\Api\TaxRateRepositoryInterface; use Magento\Tax\Api\TaxRuleRepositoryInterface; class TaxRateManagement implements TaxRateManagementInterface { /** * @var SearchCriteriaBuilder */ protected $searchCriteriaBuilder; /** * @var FilterBuilder */ protected $filterBuilder; /** * @var TaxRuleRepositoryInterface */ protected $taxRuleRepository; /** * @var TaxRateRepositoryInterface */ protected $taxRateRepository; /** * @param TaxRuleRepositoryInterface $taxRuleRepository * @param TaxRateRepositoryInterface $taxRateRepository * @param FilterBuilder $filterBuilder * @param SearchCriteriaBuilder $searchCriteriaBuilder */ public function __construct( TaxRuleRepositoryInterface $taxRuleRepository, TaxRateRepositoryInterface $taxRateRepository, FilterBuilder $filterBuilder, SearchCriteriaBuilder $searchCriteriaBuilder ) { $this->taxRuleRepository = $taxRuleRepository; $this->taxRateRepository = $taxRateRepository; $this->filterBuilder = $filterBuilder; $this->searchCriteriaBuilder = $searchCriteriaBuilder; } /** * {@inheritdoc} */ public function getRatesByCustomerAndProductTaxClassId($customerTaxClassId, $productTaxClassId) { $this->searchCriteriaBuilder->addFilters( [ $this->filterBuilder ->setField('customer_tax_class_ids') ->setValue([$customerTaxClassId]) ->create(), ] ); $this->searchCriteriaBuilder->addFilters( [ $this->filterBuilder ->setField('product_tax_class_ids') ->setValue([$productTaxClassId]) ->create(), ] ); $searchResults = $this->taxRuleRepository->getList($this->searchCriteriaBuilder->create()); $taxRules = $searchResults->getItems(); $rates = []; foreach ($taxRules as $taxRule) { $rateIds = $taxRule->getTaxRateIds(); if (!empty($rateIds)) { foreach ($rateIds as $rateId) { $rates[] = $this->taxRateRepository->get($rateId); } } } return $rates; } }