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-15 13:07:09 +00:00
|
|
|
async check(orderId) {
|
2023-01-30 10:08:26 +00:00
|
|
|
const resultSet = await this.app.conn.execQuery(
|
|
|
|
'CALL myOrder_check(#id)',
|
|
|
|
{id: orderId}
|
|
|
|
);
|
2023-02-15 13:07:09 +00:00
|
|
|
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;
|
2023-01-30 10:08:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
async load(orderId) {
|
2023-02-15 13:07:09 +00:00
|
|
|
this.loadIntoBasket(orderId);
|
|
|
|
if (!await this.checkRedirect(orderId)) return;
|
|
|
|
this.app.hash.setAll({
|
|
|
|
form: 'ecomerce/catalog'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|