diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 5bb9fecf..19fa5f34 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -4,6 +4,13 @@ ... +## [1.25.0] (2020.11.04) + +### Fixed +- Improved Customer and Product Tax Class fetcher for Tax Rules ([#354](https://github.com/DivanteLtd/magento2-vsbridge-indexer/issues/353)) + +## [1.24.0] + ## [1.23.0] (2020.11.03) ### Fixed diff --git a/src/module-vsbridge-indexer-tax/Model/Indexer/DataProvider/TaxClasses.php b/src/module-vsbridge-indexer-tax/Model/Indexer/DataProvider/TaxClasses.php index b8bfc239..61487ec4 100644 --- a/src/module-vsbridge-indexer-tax/Model/Indexer/DataProvider/TaxClasses.php +++ b/src/module-vsbridge-indexer-tax/Model/Indexer/DataProvider/TaxClasses.php @@ -40,10 +40,19 @@ public function addData(array $indexData, $storeId) foreach ($taxClasses as $data) { $ruleId = $data['tax_calculation_rule_id']; - $indexData[$ruleId]['customer_tax_class_ids'][] = (int)$data['customer_tax_class_id']; - $indexData[$ruleId]['product_tax_class_ids'][] = (int)$data['product_tax_class_id']; + $indexData[$ruleId]['customer_tax_class_ids'] = $this->explodeAsInt($data['customer_tax_class_ids']); + $indexData[$ruleId]['product_tax_class_ids'] = $this->explodeAsInt($data['product_tax_class_ids']); } return $indexData; } + + /** + * @param string $concatIds + * @return array + */ + protected function explodeAsInt(string $concatIds) : array + { + return array_map('intval', explode(',', $concatIds)); + } } diff --git a/src/module-vsbridge-indexer-tax/ResourceModel/TaxClasses.php b/src/module-vsbridge-indexer-tax/ResourceModel/TaxClasses.php index d5ed75b7..2952e05e 100644 --- a/src/module-vsbridge-indexer-tax/ResourceModel/TaxClasses.php +++ b/src/module-vsbridge-indexer-tax/ResourceModel/TaxClasses.php @@ -43,12 +43,11 @@ public function loadTaxClasses(array $ruleIds) $this->resource->getTableName('tax_calculation'), [ 'tax_calculation_rule_id', - 'customer_tax_class_id', - 'product_tax_class_id', + 'customer_tax_class_ids' => new \Zend_Db_Expr('GROUP_CONCAT(DISTINCT(`customer_tax_class_id`))'), + 'product_tax_class_ids' => new \Zend_Db_Expr('GROUP_CONCAT(DISTINCT(`product_tax_class_id`))'), ] - )->where('tax_calculation_rule_id IN (?)', $ruleIds); - - $select->distinct(true); + )->where('tax_calculation_rule_id IN (?)', $ruleIds + )->group('tax_calculation_rule_id'); return $this->getConnection()->fetchAssoc($select); }