From d13b823c7de87d88779ef098117875f0ff86f650 Mon Sep 17 00:00:00 2001 From: Codencode Date: Thu, 19 Sep 2024 18:27:44 +0200 Subject: [PATCH 1/2] Check quantities --- 202/_dev/js/shortcut.js | 40 ++++++++++++++++++++++++++++++++++-- controllers/front/ScInit.php | 1 + 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/202/_dev/js/shortcut.js b/202/_dev/js/shortcut.js index 3f174780..2525108e 100644 --- a/202/_dev/js/shortcut.js +++ b/202/_dev/js/shortcut.js @@ -124,8 +124,14 @@ const Shortcut = { style: Shortcut.getStyleSetting(), - createOrder: function(data, actions) { - return Shortcut.getIdOrder(); + createOrder: async function(data, actions) { + let result = await Shortcut.checkCartStillOrderable(); + + if (!result) { + window.location.reload(); + } else { + return Shortcut.getIdOrder(); + } }, onApprove: function(data, actions) { @@ -275,6 +281,36 @@ const Shortcut = { if (mark.isEligible()) { mark.render(markContainer); } + }, + + checkCartStillOrderable() { + let data = new Object(); + let url = new URL(this.controller); + url.searchParams.append('ajax', '1'); + url.searchParams.append('action', 'CheckAvailability'); + this.updateInfo(); + data['page'] = this.page; + data['sc'] = true; + + if (this.page == 'product') { + data['idProduct'] = this.idProduct; + data['quantity'] = this.productQuantity; + data['combination'] = this.combination.join('|'); + data['sc'] = true; + } + + return fetch(url.toString(), + { + method: 'post', + headers: { + 'content-type': 'application/json;charset=utf-8' + }, + body: JSON.stringify(data), + }).then(function(res){ + return res.json(); + }).then(function (json) { + return json.success; + }); } }; diff --git a/controllers/front/ScInit.php b/controllers/front/ScInit.php index 24f20c12..9877da9a 100644 --- a/controllers/front/ScInit.php +++ b/controllers/front/ScInit.php @@ -62,6 +62,7 @@ public function displayAjaxCheckAvailability() switch ($request->page) { case 'cart': + case 'payment-step': if ($this->context->cart->checkQuantities() && $this->context->cart->nbProducts()) { $this->jsonValues = ['success' => true]; } else { From 3de20ccd81851212efd021c65901826c36511084 Mon Sep 17 00:00:00 2001 From: Codencode Date: Fri, 20 Sep 2024 09:20:54 +0200 Subject: [PATCH 2/2] Update shortcut.js --- 202/_dev/js/shortcut.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/202/_dev/js/shortcut.js b/202/_dev/js/shortcut.js index 2525108e..dfad861b 100644 --- a/202/_dev/js/shortcut.js +++ b/202/_dev/js/shortcut.js @@ -127,13 +127,15 @@ const Shortcut = { createOrder: async function(data, actions) { let result = await Shortcut.checkCartStillOrderable(); - if (!result) { - window.location.reload(); - } else { + if (result) { return Shortcut.getIdOrder(); } }, + onError(err) { + window.location.reload(); + }, + onApprove: function(data, actions) { Shortcut.sendData(data); },