49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
|
|
module.exports = class {
|
|
constructor(app) {
|
|
this.app = app;
|
|
let orderId = localStorage.getItem('hederaBasket');
|
|
if (orderId) orderId = parseInt(orderId);
|
|
this.orderId = orderId;
|
|
}
|
|
async check(orderId) {
|
|
const resultSet = await this.app.conn.execQuery(
|
|
'CALL myOrder_checkConfig(#id)',
|
|
{id: orderId}
|
|
);
|
|
resultSet.fetchValue();
|
|
}
|
|
async checkRedirect(orderId) {
|
|
try {
|
|
await this.check(orderId);
|
|
return true;
|
|
} catch(err) {
|
|
Htk.Toast.showError(err.message);
|
|
this.app.hash.setAll({
|
|
form: 'ecomerce/checkout',
|
|
id: orderId,
|
|
continue: 'catalog'
|
|
});
|
|
return false;
|
|
}
|
|
}
|
|
async load(orderId) {
|
|
this.loadIntoBasket(orderId);
|
|
if (!await this.checkRedirect(orderId)) return;
|
|
this.app.hash.setAll({
|
|
form: 'ecomerce/catalog'
|
|
});
|
|
}
|
|
loadIntoBasket(orderId) {
|
|
if (this.orderId != orderId) {
|
|
localStorage.setItem('hederaBasket', orderId);
|
|
this.orderId = orderId;
|
|
Htk.Toast.showMessage(_('OrderLoadedIntoBasket'));
|
|
}
|
|
}
|
|
static unload() {
|
|
localStorage.removeItem('hederaBasket');
|
|
}
|
|
};
|
|
|