From e34682b647cf8f56c4b2db7f7f9264faec6f9fac Mon Sep 17 00:00:00 2001 From: andrzejewsky Date: Thu, 29 Aug 2019 20:22:15 +0200 Subject: [PATCH 1/3] better error response for mailchimp --- CHANGELOG.md | 5 ++++- src/api/extensions/mailchimp-subscribe/index.js | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd634812..3099e2f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ 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) + ## [1.10.0] - 2019.08.12 ### Added @@ -74,7 +77,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 diff --git a/src/api/extensions/mailchimp-subscribe/index.js b/src/api/extensions/mailchimp-subscribe/index.js index 03b75bf4..47d0d4bd 100644 --- a/src/api/extensions/mailchimp-subscribe/index.js +++ b/src/api/extensions/mailchimp-subscribe/index.js @@ -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) @@ -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) @@ -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) From 39cc88bafcd02c1cb40fde60bd3407f7ef2fafd3 Mon Sep 17 00:00:00 2001 From: andrzejewsky Date: Thu, 29 Aug 2019 20:34:19 +0200 Subject: [PATCH 2/3] sync taxcalc --- src/lib/taxcalc.js | 10 +++++----- src/platform/magento1/tax.js | 12 +++++++++++- src/platform/magento2/tax.js | 12 +++++++++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/lib/taxcalc.js b/src/lib/taxcalc.js index c408cd9b..3f8c3916 100644 --- a/src/lib/taxcalc.js +++ b/src/lib/taxcalc.js @@ -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 @@ -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 @@ -222,7 +222,7 @@ 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 } @@ -230,7 +230,7 @@ export function calculateProductTax (product, taxClasses, taxCountry = 'PL', tax } } if (!rateFound) { - updateProductPrices(product, {rate: 0}) + updateProductPrices({ product, rate: {rate: 0} }) product.price_incl_tax = product.price product.price_tax = 0 diff --git a/src/platform/magento1/tax.js b/src/platform/magento1/tax.js index 1ff3c392..5890d48f 100644 --- a/src/platform/magento1/tax.js +++ b/src/platform/magento1/tax.js @@ -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) { diff --git a/src/platform/magento2/tax.js b/src/platform/magento2/tax.js index 7d8c33cf..ffd2ab2b 100644 --- a/src/platform/magento2/tax.js +++ b/src/platform/magento2/tax.js @@ -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) { From 4d15ac8b5d912f0d35f931b0fd761803e2bf735b Mon Sep 17 00:00:00 2001 From: andrzejewsky Date: Fri, 30 Aug 2019 13:43:45 +0200 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3099e2f5..97e61fa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Better handling of HTTP error codes provided by API client - #3151 ### Changed -- Error responses for mailchimp - (@andrzejewsky) +- Error responses for mailchimp - @andrzejewsky (#3337) +- Replaced function arguments to object destructuring in `calculateProductTax` - @andrzejewsky (#3337) ## [1.10.0] - 2019.08.12