diff --git a/config/default.json b/config/default.json index e083536c1b..430cf87fb9 100644 --- a/config/default.json +++ b/config/default.json @@ -116,6 +116,7 @@ } }, "cart": { + "bypassCartLoaderForAuthorizedUsers": true, "multisiteCommonCart": true, "server_merge_by_default": true, "synchronize": true, diff --git a/core/store/modules/cart/actions.ts b/core/store/modules/cart/actions.ts index 1f724dcebe..eb703a9037 100644 --- a/core/store/modules/cart/actions.ts +++ b/core/store/modules/cart/actions.ts @@ -111,9 +111,6 @@ const actions: ActionTree = { serverCreate (context, { guestCart = false }) { if (rootStore.state.config.cart.synchronize && !Vue.prototype.$isServer) { if ((Date.now() - context.state.cartServerCreatedAt) >= CART_CREATE_INTERVAL_MS) { - if (guestCart) { - Vue.prototype.$db.usersCollection.setItem('last-cart-bypass-ts', new Date().getTime()) - } const task = { url: guestCart ? rootStore.state.config.cart.create_endpoint.replace('{{token}}', '') : rootStore.state.config.cart.create_endpoint, // sync the cart payload: { method: 'POST', @@ -467,7 +464,7 @@ const actions: ActionTree = { if (err) { console.error(err) } - if ((Date.now() - lastCartBypassTs) >= (1000 * 60 * 24)) { // don't refresh the shopping cart id up to 24h after last order + if (!rootStore.state.config.cart.bypassCartLoaderForAuthorizedUsers || (Date.now() - lastCartBypassTs) >= (1000 * 60 * 24)) { // don't refresh the shopping cart id up to 24h after last order rootStore.dispatch('cart/serverCreate', { guestCart: false }, { root: true }) } }) diff --git a/core/store/modules/checkout/actions.ts b/core/store/modules/checkout/actions.ts index 6f7950c283..9272262e71 100644 --- a/core/store/modules/checkout/actions.ts +++ b/core/store/modules/checkout/actions.ts @@ -14,6 +14,7 @@ const actions: ActionTree = { placeOrder (context, { order }) { try { context.dispatch('order/placeOrder', order, {root: true}).then(result => { + Vue.prototype.$db.usersCollection.setItem('last-cart-bypass-ts', new Date().getTime()) context.dispatch('cart/clear', {}, {root: true}) if (context.state.personalDetails.createAccount) { context.commit(types.CHECKOUT_DROP_PASSWORD)