Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit 39cc88b

Browse files
committed
sync taxcalc
1 parent e34682b commit 39cc88b

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/lib/taxcalc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function isSpecialPriceActive (fromDate, toDate) {
2020
}
2121
}
2222

23-
export function updateProductPrices (product, rate, sourcePriceInclTax = false, deprecatedPriceFieldsSupport = false, finalPriceInclTax = true) {
23+
export function updateProductPrices ({ product, rate, sourcePriceInclTax = false, deprecatedPriceFieldsSupport = false, finalPriceInclTax = true }) {
2424
const rate_factor = parseFloat(rate.rate) / 100
2525
if (finalPriceInclTax) {
2626
product.final_price_incl_tax = parseFloat(product.final_price) // final price does include tax
@@ -206,11 +206,11 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false,
206206
}
207207
}
208208

209-
export function calculateProductTax (product, taxClasses, taxCountry = 'PL', taxRegion = '', sourcePriceInclTax = false, deprecatedPriceFieldsSupport = false, finalPriceInclTax = true, userGroupId = null, _storeConfigTax) {
209+
export function calculateProductTax ({ product, taxClasses, taxCountry = 'PL', taxRegion = '', sourcePriceInclTax = false, deprecatedPriceFieldsSupport = false, finalPriceInclTax = true, userGroupId = null, isTaxWithUserGroupIsActive }) {
210210
let rateFound = false
211211
if (product.tax_class_id > 0) {
212212
let taxClass
213-
if (checkIfTaxWithUserGroupIsActive(_storeConfigTax) && typeof userGroupId === 'number') {
213+
if (isTaxWithUserGroupIsActive) {
214214
taxClass = taxClasses.find((el) =>
215215
el.product_tax_class_ids.indexOf(parseInt(product.tax_class_id)) >= 0 &&
216216
el.customer_tax_class_ids.indexOf(userGroupId) >= 0
@@ -222,15 +222,15 @@ export function calculateProductTax (product, taxClasses, taxCountry = 'PL', tax
222222
if (taxClass) {
223223
for (let rate of taxClass.rates) { // TODO: add check for zip code ranges (!)
224224
if (rate.tax_country_id === taxCountry && (rate.region_name === taxRegion || rate.tax_region_id === 0 || !rate.region_name)) {
225-
updateProductPrices(product, rate, sourcePriceInclTax, deprecatedPriceFieldsSupport)
225+
updateProductPrices({ product, rate, sourcePriceInclTax, deprecatedPriceFieldsSupport })
226226
rateFound = true
227227
break
228228
}
229229
}
230230
}
231231
}
232232
if (!rateFound) {
233-
updateProductPrices(product, {rate: 0})
233+
updateProductPrices({ product, rate: {rate: 0} })
234234

235235
product.price_incl_tax = product.price
236236
product.price_tax = 0

src/platform/magento1/tax.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ class TaxProxy extends AbstractTaxProxy {
5555
}
5656

5757
taxFor (product, groupId) {
58-
return calculateProductTax(product, this._taxClasses, this._taxCountry, this._taxRegion, this._sourcePriceInclTax, this._deprecatedPriceFieldsSupport, this._finalPriceInclTax, groupId, this._storeConfigTax)
58+
return calculateProductTax({
59+
product,
60+
taxClasses: this._taxClasses,
61+
taxCountry: this._taxCountry,
62+
taxRegion: this._taxRegion,
63+
sourcePriceInclTax: this._sourcePriceInclTax,
64+
deprecatedPriceFieldsSupport: this._deprecatedPriceFieldsSupport,
65+
finalPriceInclTax: this._finalPriceInclTax,
66+
userGroupId: groupId,
67+
isTaxWithUserGroupIsActive: checkIfTaxWithUserGroupIsActive(this._storeConfigTax) && typeof groupId === 'number'
68+
})
5969
}
6070

6171
applyTierPrices (productList, groupId) {

src/platform/magento2/tax.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,17 @@ class TaxProxy extends AbstractTaxProxy {
5454
}
5555

5656
taxFor (product, groupId) {
57-
return calculateProductTax(product, this._taxClasses, this._taxCountry, this._taxRegion, this._sourcePriceInclTax, this._deprecatedPriceFieldsSupport, this._finalPriceInclTax, groupId, this._storeConfigTax)
57+
return calculateProductTax({
58+
product,
59+
taxClasses: this._taxClasses,
60+
taxCountry: this._taxCountry,
61+
taxRegion: this._taxRegion,
62+
sourcePriceInclTax: this._sourcePriceInclTax,
63+
deprecatedPriceFieldsSupport: this._deprecatedPriceFieldsSupport,
64+
finalPriceInclTax: this._finalPriceInclTax,
65+
userGroupId: groupId,
66+
isTaxWithUserGroupIsActive: checkIfTaxWithUserGroupIsActive(this._storeConfigTax) && typeof groupId === 'number'
67+
})
5868
}
5969

6070
applyTierPrices (productList, groupId) {

0 commit comments

Comments
 (0)