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

Commit b0846c3

Browse files
authored
Merge pull request #336 from andrzejewsky/feature/3337-refactor-newsletter-module
Error response when there is problem with Mailchimp
2 parents 73efbb9 + 4d15ac8 commit b0846c3

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Force ES connections to use protocol config option - @cewald (#303, #304)
2323
- Better handling of HTTP error codes provided by API client - #3151
2424

25+
### Changed
26+
- Error responses for mailchimp - @andrzejewsky (#3337)
27+
- Replaced function arguments to object destructuring in `calculateProductTax` - @andrzejewsky (#3337)
28+
2529
## [1.10.0] - 2019.08.12
2630

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

8084
## [1.8.4] - 2019.04.17

src/api/extensions/mailchimp-subscribe/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ module.exports = ({ config, db }) => {
2121
json: true,
2222
headers: { 'Authorization': 'apikey ' + config.extensions.mailchimp.apiKey }
2323
}, (error, response, body) => {
24-
if (error) {
25-
console.error(error)
24+
if (error || response.statusCode !== 200) {
25+
console.error(error, body)
2626
apiStatus(res, 'An error occured while accessing Mailchimp', 500)
2727
} else {
2828
apiStatus(res, body.status, 200)
@@ -46,8 +46,8 @@ module.exports = ({ config, db }) => {
4646
json: true,
4747
body: { members: [ { email_address: userData.email, status: config.extensions.mailchimp.userStatus } ], 'update_existing': true }
4848
}, (error, response, body) => {
49-
if (error) {
50-
console.error(error)
49+
if (error || response.statusCode !== 200) {
50+
console.error(error, body)
5151
apiStatus(res, 'An error occured while accessing Mailchimp', 500)
5252
} else {
5353
apiStatus(res, body.status, 200)
@@ -73,8 +73,8 @@ module.exports = ({ config, db }) => {
7373
json: true,
7474
body: { members: [ { email_address: userData.email, status: 'unsubscribed' } ], 'update_existing': true }
7575
}, (error, response, body) => {
76-
if (error) {
77-
console.error(error)
76+
if (error || response.statusCode !== 200) {
77+
console.error(error, body)
7878
apiStatus(res, 'An error occured while accessing Mailchimp', 500)
7979
} else {
8080
apiStatus(res, body.status, 200)

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)