Skip to content

Commit

Permalink
Merge pull request #598 from alma/fix/insurance-no-qty
Browse files Browse the repository at this point in the history
Prevent crash when there is not quantity input on product page
  • Loading branch information
olance authored Nov 13, 2024
2 parents f2ffd85 + 96044bc commit b85c770
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions alma/views/js/alma-product-insurance.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

let loaded = false;
let insuranceSelected = false;
let selectedAlmaInsurance = null;
let addToCartFlow = false;
let quantity = getQuantity();
let almaEligibilityAnswer = false;
Expand Down Expand Up @@ -105,11 +104,15 @@
}


function getQuantityInput() {
return document.querySelector('.qty [name="qty"]');
}

// Retrieve wanted product quantity from the quantity selector
function getQuantity() {
let quantity = 1;

const qtyInput = document.querySelector('.qty [name="qty"]');
const qtyInput = getQuantityInput();
if (qtyInput) {
quantity = Number(qtyInput.value);
}
Expand All @@ -126,8 +129,10 @@
quantity = 1;
}

const qtyInput = document.querySelector('.qty [name="qty"]');
qtyInput.value = quantity;
const qtyInput = getQuantityInput();
if (qtyInput) {
qtyInput.value = quantity;
}
}

// Display/hide a spinner on the add to cart button
Expand Down Expand Up @@ -176,7 +181,8 @@

// Widget is sending us selected insurance data
case 'getSelectedInsuranceData':
if (parseInt(document.querySelector('.qty [name="qty"]').value) !== quantity) {
const qtyInput = getQuantityInput();
if (qtyInput && parseInt(qtyInput.value) !== quantity) {
quantity = getQuantity();
}

Expand Down

0 comments on commit b85c770

Please sign in to comment.