2023-01-30 10:08:26 +00:00
|
|
|
|
|
|
|
module.exports = class {
|
|
|
|
constructor(app) {
|
|
|
|
this.app = app;
|
|
|
|
let orderId = localStorage.getItem('hederaBasket');
|
|
|
|
if (orderId) orderId = parseInt(orderId);
|
|
|
|
this.orderId = orderId;
|
|
|
|
}
|
2023-02-23 13:32:13 +00:00
|
|
|
async checkOrder(orderId) {
|
2023-01-30 10:08:26 +00:00
|
|
|
const resultSet = await this.app.conn.execQuery(
|
2023-02-15 16:13:25 +00:00
|
|
|
'CALL myOrder_checkConfig(#id)',
|
2023-01-30 10:08:26 +00:00
|
|
|
{id: orderId}
|
|
|
|
);
|
2023-02-15 13:07:09 +00:00
|
|
|
resultSet.fetchValue();
|
|
|
|
}
|
2023-02-23 13:32:13 +00:00
|
|
|
async check() {
|
|
|
|
if (this.orderId) {
|
|
|
|
return await this.checkRedirect();
|
|
|
|
} else {
|
|
|
|
this.app.hash.setAll({form: 'ecomerce/checkout'});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
async checkRedirect() {
|
2023-02-15 13:07:09 +00:00
|
|
|
try {
|
2023-02-23 13:32:13 +00:00
|
|
|
await this.checkOrder(this.orderId);
|
2023-02-15 13:07:09 +00:00
|
|
|
return true;
|
|
|
|
} catch(err) {
|
2023-02-23 13:32:13 +00:00
|
|
|
if (err.exception == 'Vn.Lib.UserError') {
|
|
|
|
const dst = {
|
|
|
|
form: 'ecomerce/checkout',
|
|
|
|
continue: 'catalog'
|
|
|
|
};
|
|
|
|
|
2023-02-23 15:50:49 +00:00
|
|
|
switch(err.code) {
|
|
|
|
case 'orderConfirmed':
|
|
|
|
case 'orderNotOwnedByUser':
|
|
|
|
this.constructor.unload();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dst.id = this.orderId;
|
|
|
|
Htk.Toast.showError(err.message);
|
2023-02-23 13:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.app.hash.setAll(dst);
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
throw err;
|
2023-01-30 10:08:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
async load(orderId) {
|
2023-02-15 13:07:09 +00:00
|
|
|
this.loadIntoBasket(orderId);
|
2023-02-23 13:32:13 +00:00
|
|
|
if (await this.checkRedirect())
|
|
|
|
this.app.hash.setAll({
|
|
|
|
form: 'ecomerce/catalog'
|
|
|
|
});
|
2023-02-15 13:07:09 +00:00
|
|
|
}
|
|
|
|
loadIntoBasket(orderId) {
|
2023-01-30 10:08:26 +00:00
|
|
|
if (this.orderId != orderId) {
|
|
|
|
localStorage.setItem('hederaBasket', orderId);
|
|
|
|
this.orderId = orderId;
|
2023-02-15 13:07:09 +00:00
|
|
|
Htk.Toast.showMessage(_('OrderLoadedIntoBasket'));
|
2023-01-30 10:08:26 +00:00
|
|
|
}
|
2023-02-15 13:07:09 +00:00
|
|
|
}
|
|
|
|
static unload() {
|
|
|
|
localStorage.removeItem('hederaBasket');
|
2023-01-30 10:08:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|