46 \
Magento\Tax\Helper\Data $taxData,
50 $this->_taxData = $taxData;
74 $where = $conn->quoteInto(
'tax_calculation_rule_id = ?', (
int)
$ruleId);
141 $countedRates = count(
$rates);
142 for (
$i = 0;
$i < $countedRates;
$i++) {
147 'code' =>
$rate[
'code'],
148 'title' =>
$rate[
'title'],
150 'position' =>
$rate[
'position'],
151 'priority' =>
$rate[
'priority']
153 if (isset(
$rate[
'tax_calculation_rule_id'])) {
154 $oneRate[
'rule_id'] =
$rate[
'tax_calculation_rule_id'];
157 if (isset(
$rate[
'hidden'])) {
161 if (isset(
$rate[
'amount'])) {
165 if (isset(
$rate[
'base_amount'])) {
166 $row[
'base_amount'] =
$rate[
'base_amount'];
168 if (isset(
$rate[
'base_real_amount'])) {
169 $row[
'base_real_amount'] =
$rate[
'base_real_amount'];
171 $row[
'rates'][] = $oneRate;
174 if (isset(
$rates[
$i + 1][
'tax_calculation_rule_id'])) {
177 $priority =
$rate[
'priority'];
178 $ids[] =
$rate[
'code'];
180 if (isset(
$rates[
$i + 1][
'tax_calculation_rule_id'])) {
190 ) ||
$rates[
$i + 1][
'priority'] != $priority || isset(
194 if (!empty(
$rates[
$i][
'calculate_subtotal'])) {
195 $row[
'percent'] = $currentRate;
196 $totalPercent += $currentRate;
199 $totalPercent +=
$row[
'percent'];
201 $row[
'id'] = implode(
'', $ids);
235 $len = $this->_taxData->getPostCodeSubStringLength();
236 $postcode = substr($postcode, 0, $len);
239 $strArr = [$postcode, $postcode .
'*'];
242 if ($exactPostcode) {
243 $postcode = substr($exactPostcode, 0, $len);
244 $strArr[] = $postcode;
248 $strlen = strlen($postcode);
249 for (
$i = 1;
$i < $strlen;
$i++) {
250 $strArr[] = sprintf(
'%s*', substr($postcode, 0, -
$i));
270 $customerClassId =
$request->getCustomerClassId();
271 $countryId =
$request->getCountryId();
272 $regionId =
$request->getRegionId();
273 $postcode =
$request->getPostcode();
276 $productClassId =
$request->getProductClassId();
277 $ids = is_array($productClassId) ? $productClassId : [$productClassId];
278 foreach ($ids as $key => $val) {
279 $ids[$key] = (int)$val;
281 $ids = array_unique($ids);
283 $productClassKey = implode(
',', $ids);
288 [
$storeId, $customerClassId, $productClassKey, $countryId, $regionId, $postcode]
291 if (!isset($this->_ratesCache[$cacheKey])) {
297 'tax_calculation_rate_id',
298 'tax_calculation_rule_id',
299 'customer_tax_class_id',
300 'product_tax_class_id' 303 'customer_tax_class_id = ?',
304 (
int)$customerClassId
306 if ($productClassId) {
307 $select->where(
'product_tax_class_id IN (?)', $productClassId);
310 'title_table.value IS NULL',
314 $ruleTableAliasName = $this->
getConnection()->quoteIdentifier(
'rule.tax_calculation_rule_id');
316 [
'rule' => $this->
getTable(
'tax_calculation_rule')],
317 $ruleTableAliasName .
' = main_table.tax_calculation_rule_id',
318 [
'rule.priority',
'rule.position',
'rule.calculate_subtotal']
320 [
'rate' => $this->
getTable(
'tax_calculation_rate')],
321 'rate.tax_calculation_rate_id = main_table.tax_calculation_rate_id',
323 'value' =>
'rate.rate',
324 'rate.tax_country_id',
325 'rate.tax_region_id',
327 'rate.tax_calculation_rate_id',
331 [
'title_table' => $this->
getTable(
'tax_calculation_rate_title')],
332 "rate.tax_calculation_rate_id = title_table.tax_calculation_rate_id " .
333 "AND title_table.store_id = '{$storeId}'",
334 [
'title' => $ifnullTitleValue]
336 'rate.tax_country_id = ?',
339 "rate.tax_region_id IN(?)",
342 $postcodeIsNumeric = is_numeric($postcode);
343 $postcodeIsRange =
false;
344 $originalPostcode =
null;
345 if (is_string($postcode) && preg_match(
'/^(.+)-(.+)$/', $postcode, $matches)) {
346 if ($countryId == self::USA_COUNTRY_CODE && is_numeric($matches[2]) && strlen($matches[2]) == 4) {
347 $postcodeIsNumeric =
true;
348 $originalPostcode = $postcode;
349 $postcode = $matches[1];
351 $postcodeIsRange =
true;
352 $zipFrom = $matches[1];
353 $zipTo = $matches[2];
357 if ($postcodeIsNumeric || $postcodeIsRange) {
359 $selectClone->where(
'rate.zip_is_range IS NOT NULL');
361 $select->where(
'rate.zip_is_range IS NULL');
363 if ($postcode !=
'*' || $postcodeIsRange) {
365 "rate.tax_postcode IS NULL OR rate.tax_postcode IN('*', '', ?)",
368 if ($postcodeIsNumeric) {
369 $selectClone->where(
'? BETWEEN rate.zip_from AND rate.zip_to', $postcode);
370 }
elseif ($postcodeIsRange) {
371 $selectClone->where(
'rate.zip_from >= ?', $zipFrom)
372 ->where(
'rate.zip_to <= ?', $zipTo);
379 if ($postcodeIsNumeric || $postcodeIsRange) {
381 [
'(' .
$select .
')',
'(' . $selectClone .
')']
386 'priority ' . \
Magento\Framework\DB\Select::SQL_ASC
388 'tax_calculation_rule_id ' . \
Magento\Framework\DB\Select::SQL_ASC
390 'tax_country_id ' . \
Magento\Framework\DB\Select::SQL_DESC
392 'tax_region_id ' . \
Magento\Framework\DB\Select::SQL_DESC
394 'tax_postcode ' . \
Magento\Framework\DB\Select::SQL_DESC
396 'value ' . \
Magento\Framework\DB\Select::SQL_DESC
402 foreach ($fetchResult as
$rate) {
403 if (!isset($filteredRates[
$rate[
'tax_calculation_rate_id']])) {
404 $filteredRates[
$rate[
'tax_calculation_rate_id']] =
$rate;
408 $this->_ratesCache[$cacheKey] = array_values($filteredRates);
411 return $this->_ratesCache[$cacheKey];
424 $countedRates = count(
$rates);
425 for (
$i = 0;
$i < $countedRates;
$i++) {
429 $priority =
$rate[
'priority'];
438 if (!empty(
$rates[
$i][
'calculate_subtotal'])) {
460 $countedRates = count(
$rates);
461 for (
$i = 0;
$i < $countedRates;
$i++) {
getCalculationsById($field, $ruleId)
if($this->helper('Magento\Tax\Helper\Data') ->displayFullSummary()) foreach( $block->getTotal() ->getFullInfo() as $info)(isset($info['hidden']) && $info['hidden']) $percent
_createSearchPostCodeTemplates($postcode, $exactPostcode=null)
elseif(isset( $params[ 'redirect_parent']))
getCalculationProcess($request, $rates=null)
_collectPercent($percent, $rate)
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Tax\Helper\Data $taxData, \Magento\Store\Model\StoreManagerInterface $storeManager, $connectionName=null)
_setMainTable($mainTable, $idFieldName=null)