Skip to content

Commit

Permalink
Check quantities
Browse files Browse the repository at this point in the history
  • Loading branch information
Codencode committed Sep 19, 2024
1 parent 0771af6 commit d13b823
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
40 changes: 38 additions & 2 deletions 202/_dev/js/shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
});
}

};
Expand Down
1 change: 1 addition & 0 deletions controllers/front/ScInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d13b823

Please sign in to comment.