Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check error with duplicate cart #943

Merged
merged 6 commits into from
Aug 24, 2023
Merged
Changes from 4 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
13 changes: 10 additions & 3 deletions @ecomplus/storefront-app/src/lib/sync-cart-to-api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ecomPassport from '@ecomplus/passport-client'
import ecomClient from '@ecomplus/client'
import ecomCart from '@ecomplus/shopping-cart'
import router from '../router/'

let resolveCartId
const fetchingCartId = new Promise(resolve => (resolveCartId = resolve))
Expand Down Expand Up @@ -82,6 +83,9 @@ const prepareCart = cart => {
} else {
url = '/carts.json'
method = 'POST'
if (router && router.currentRoute && router.currentRoute.name === 'confirmation' && completed === undefined) {
leomp12 marked this conversation as resolved.
Show resolved Hide resolved
return {}
}
}
return {
url,
Expand Down Expand Up @@ -111,6 +115,9 @@ const queueUpdateCart = tryRequestApi => new Promise(resolve => {
const upsertCart = () => {
if (ecomPassport.checkAuthorization() && ecomCart.data.items.length) {
const { url, method, cleanedData } = prepareCart(ecomCart.data)
if (!cleanedData) {
return Promise.resolve(null)
}
const tryRequestApi = () => {
return ecomPassport.requestApi(url, method, cleanedData)
.catch(console.error)
Expand All @@ -125,9 +132,9 @@ const upsertCart = () => {
}, 300)
})
: queueUpdateCart(tryRequestApi)
} else {
return Promise.resolve()
}
} else {
return Promise.resolve()
}
leomp12 marked this conversation as resolved.
Show resolved Hide resolved
}

export { fetchCart, fetchingCartId, upsertCart }
Loading