forked from verdnatura/hedera-web
Merge pull request 'Unload order when order check fails' (!83) from wbuezas/hedera-web-mindshore:feature/UnloadOrder into 4922-vueMigration
Reviewed-on: verdnatura/hedera-web#83
This commit is contained in:
commit
facb565d26
|
@ -5,6 +5,7 @@ import { i18n } from 'src/boot/i18n';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
|
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
|
const storageOrderName = 'hederaBasket';
|
||||||
|
|
||||||
export const useAppStore = defineStore('hedera', {
|
export const useAppStore = defineStore('hedera', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
|
@ -72,7 +73,7 @@ export const useAppStore = defineStore('hedera', {
|
||||||
},
|
},
|
||||||
|
|
||||||
getBasketOrderId() {
|
getBasketOrderId() {
|
||||||
this.basketOrderId = localStorage.getItem('hederaBasket');
|
this.basketOrderId = localStorage.getItem(storageOrderName);
|
||||||
},
|
},
|
||||||
|
|
||||||
async checkOrder(orderId) {
|
async checkOrder(orderId) {
|
||||||
|
@ -97,22 +98,21 @@ export const useAppStore = defineStore('hedera', {
|
||||||
await this.checkOrder(this.basketOrderId);
|
await this.checkOrder(this.basketOrderId);
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.exception === 'Vn.Lib.UserError') {
|
switch (err.code) {
|
||||||
switch (err.code) {
|
case 'orderConfirmed':
|
||||||
case 'orderConfirmed':
|
case 'orderNotOwnedByUser':
|
||||||
case 'orderNotOwnedByUser':
|
this.unloadOrder();
|
||||||
await this.redirect();
|
await this.redirect();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.router.push({
|
this.router.push({
|
||||||
name: 'checkout',
|
name: 'checkout',
|
||||||
params: { id: this.basketOrderId },
|
params: { id: this.basketOrderId },
|
||||||
query: { continue: checkoutContinue }
|
query: { continue: checkoutContinue }
|
||||||
});
|
});
|
||||||
notify(err.message, 'negative');
|
notify(err.message, 'negative');
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else throw err;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -131,9 +131,14 @@ export const useAppStore = defineStore('hedera', {
|
||||||
loadIntoBasket(orderId) {
|
loadIntoBasket(orderId) {
|
||||||
if (this.basketOrderId !== orderId) {
|
if (this.basketOrderId !== orderId) {
|
||||||
this.basketOrderId = orderId;
|
this.basketOrderId = orderId;
|
||||||
localStorage.setItem('hederaBasket', orderId);
|
localStorage.setItem(storageOrderName, orderId);
|
||||||
notify('orderLoadedIntoBasket', 'positive');
|
notify('orderLoadedIntoBasket', 'positive');
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
unloadOrder() {
|
||||||
|
localStorage.removeItem(storageOrderName);
|
||||||
|
this.basketOrderId = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
|
|
Loading…
Reference in New Issue