Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Force ES connections to use protocol config option - @cewald (#303, #304)
- Better handling of HTTP error codes provided by API client - #3151

### Changed
- Error responses for mailchimp - @andrzejewsky (#3337)
- Replaced function arguments to object destructuring in `calculateProductTax` - @andrzejewsky (#3337)

## [1.10.0] - 2019.08.12

### Added
Expand Down Expand Up @@ -74,7 +78,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support unicode characters in order requests - @lukeromanowicz (#201)
- TravisCI configured for building and linting - @lukeromanowicz (#204)
- Use Redis database from configuration in mage2vs - @Cyclonecode (#211)
- Requests with invalid body result in HTTP code 400 instead of 500 - @AndreiBelokopytov (#220)
- Requests with invalid body result in HTTP code 400 instead of 500 - @AndreiBelokopytov (#220)
- `src/models/order.schema.json` was moved to `src/models/order.schema.js` to support regex transformation - @lukeromanowicz (#201)

## [1.8.4] - 2019.04.17
Expand Down
12 changes: 6 additions & 6 deletions src/api/extensions/mailchimp-subscribe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module.exports = ({ config, db }) => {
json: true,
headers: { 'Authorization': 'apikey ' + config.extensions.mailchimp.apiKey }
}, (error, response, body) => {
if (error) {
console.error(error)
if (error || response.statusCode !== 200) {
console.error(error, body)
apiStatus(res, 'An error occured while accessing Mailchimp', 500)
} else {
apiStatus(res, body.status, 200)
Expand All @@ -46,8 +46,8 @@ module.exports = ({ config, db }) => {
json: true,
body: { members: [ { email_address: userData.email, status: config.extensions.mailchimp.userStatus } ], 'update_existing': true }
}, (error, response, body) => {
if (error) {
console.error(error)
if (error || response.statusCode !== 200) {
console.error(error, body)
apiStatus(res, 'An error occured while accessing Mailchimp', 500)
} else {
apiStatus(res, body.status, 200)
Expand All @@ -73,8 +73,8 @@ module.exports = ({ config, db }) => {
json: true,
body: { members: [ { email_address: userData.email, status: 'unsubscribed' } ], 'update_existing': true }
}, (error, response, body) => {
if (error) {
console.error(error)
if (error || response.statusCode !== 200) {
console.error(error, body)
apiStatus(res, 'An error occured while accessing Mailchimp', 500)
} else {
apiStatus(res, body.status, 200)
Expand Down
10 changes: 5 additions & 5 deletions src/lib/taxcalc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function isSpecialPriceActive (fromDate, toDate) {
}
}

export function updateProductPrices (product, rate, sourcePriceInclTax = false, deprecatedPriceFieldsSupport = false, finalPriceInclTax = true) {
export function updateProductPrices ({ product, rate, sourcePriceInclTax = false, deprecatedPriceFieldsSupport = false, finalPriceInclTax = true }) {
const rate_factor = parseFloat(rate.rate) / 100
if (finalPriceInclTax) {
product.final_price_incl_tax = parseFloat(product.final_price) // final price does include tax
Expand Down Expand Up @@ -206,11 +206,11 @@ export function updateProductPrices (product, rate, sourcePriceInclTax = false,
}
}

export function calculateProductTax (product, taxClasses, taxCountry = 'PL', taxRegion = '', sourcePriceInclTax = false, deprecatedPriceFieldsSupport = false, finalPriceInclTax = true, userGroupId = null, _storeConfigTax) {
export function calculateProductTax ({ product, taxClasses, taxCountry = 'PL', taxRegion = '', sourcePriceInclTax = false, deprecatedPriceFieldsSupport = false, finalPriceInclTax = true, userGroupId = null, isTaxWithUserGroupIsActive }) {
let rateFound = false
if (product.tax_class_id > 0) {
let taxClass
if (checkIfTaxWithUserGroupIsActive(_storeConfigTax) && typeof userGroupId === 'number') {
if (isTaxWithUserGroupIsActive) {
taxClass = taxClasses.find((el) =>
el.product_tax_class_ids.indexOf(parseInt(product.tax_class_id)) >= 0 &&
el.customer_tax_class_ids.indexOf(userGroupId) >= 0
Expand All @@ -222,15 +222,15 @@ export function calculateProductTax (product, taxClasses, taxCountry = 'PL', tax
if (taxClass) {
for (let rate of taxClass.rates) { // TODO: add check for zip code ranges (!)
if (rate.tax_country_id === taxCountry && (rate.region_name === taxRegion || rate.tax_region_id === 0 || !rate.region_name)) {
updateProductPrices(product, rate, sourcePriceInclTax, deprecatedPriceFieldsSupport)
updateProductPrices({ product, rate, sourcePriceInclTax, deprecatedPriceFieldsSupport })
rateFound = true
break
}
}
}
}
if (!rateFound) {
updateProductPrices(product, {rate: 0})
updateProductPrices({ product, rate: {rate: 0} })

product.price_incl_tax = product.price
product.price_tax = 0
Expand Down
12 changes: 11 additions & 1 deletion src/platform/magento1/tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,17 @@ class TaxProxy extends AbstractTaxProxy {
}

taxFor (product, groupId) {
return calculateProductTax(product, this._taxClasses, this._taxCountry, this._taxRegion, this._sourcePriceInclTax, this._deprecatedPriceFieldsSupport, this._finalPriceInclTax, groupId, this._storeConfigTax)
return calculateProductTax({
product,
taxClasses: this._taxClasses,
taxCountry: this._taxCountry,
taxRegion: this._taxRegion,
sourcePriceInclTax: this._sourcePriceInclTax,
deprecatedPriceFieldsSupport: this._deprecatedPriceFieldsSupport,
finalPriceInclTax: this._finalPriceInclTax,
userGroupId: groupId,
isTaxWithUserGroupIsActive: checkIfTaxWithUserGroupIsActive(this._storeConfigTax) && typeof groupId === 'number'
})
}

applyTierPrices (productList, groupId) {
Expand Down
12 changes: 11 additions & 1 deletion src/platform/magento2/tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ class TaxProxy extends AbstractTaxProxy {
}

taxFor (product, groupId) {
return calculateProductTax(product, this._taxClasses, this._taxCountry, this._taxRegion, this._sourcePriceInclTax, this._deprecatedPriceFieldsSupport, this._finalPriceInclTax, groupId, this._storeConfigTax)
return calculateProductTax({
product,
taxClasses: this._taxClasses,
taxCountry: this._taxCountry,
taxRegion: this._taxRegion,
sourcePriceInclTax: this._sourcePriceInclTax,
deprecatedPriceFieldsSupport: this._deprecatedPriceFieldsSupport,
finalPriceInclTax: this._finalPriceInclTax,
userGroupId: groupId,
isTaxWithUserGroupIsActive: checkIfTaxWithUserGroupIsActive(this._storeConfigTax) && typeof groupId === 'number'
})
}

applyTierPrices (productList, groupId) {
Expand Down