Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: The quantities in stock are not verified in case of payment with PayPal #365

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions 202/_dev/js/shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,16 @@ const Shortcut = {

style: Shortcut.getStyleSetting(),

createOrder: function(data, actions) {
return Shortcut.getIdOrder();
createOrder: async function(data, actions) {
let result = await Shortcut.checkCartStillOrderable();

if (result) {
return Shortcut.getIdOrder();
}
},

onError(err) {
window.location.reload();
},

onApprove: function(data, actions) {
Expand Down Expand Up @@ -275,6 +283,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
Loading