Skip to content

Commit

Permalink
Merge pull request #61 from TEAM-7-SAD/Shotgun
Browse files Browse the repository at this point in the history
Shotgun test for add to cart button fixed
  • Loading branch information
Carl-Tabuso authored Jul 5, 2024
2 parents 76146c1 + e81314b commit 1900fa6
Showing 1 changed file with 45 additions and 41 deletions.
86 changes: 45 additions & 41 deletions src/get-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,49 +394,53 @@ function updatePrice() {
}

function addToCart() {
let productId = $('#product').data('product-id');
let productType = $('#product').data('product-type');
let productName = $('#productName').text();
let servingOrType = $('#servingOrTypeGroup .active').text() || $('#defaultServingOrType').val() || $('#noneServingOrType').val();
let flavorOrSize = $('#flavorOrSizeGroup .active').text() || $('#defaultFlavorOrSize').val() || $('#noneFlavorOrSize').val();
let quantity = $('#quantityInput').val();
let price = $('#priceDisplay').val();

if (servingOrType === 'Default' || servingOrType === 'None') servingOrType = '';
if (flavorOrSize === 'Default' || flavorOrSize === 'None') flavorOrSize = '';

$.ajax({
url: 'add_to_order_cart.php',
type: 'POST',
data: {
product_id: productId,
product_type: productType,
product_name: productName,
serving_or_type: servingOrType,
flavor_or_size: flavorOrSize,
quantity: quantity,
price: price
},
success: function(response) {
let data = JSON.parse(response);
if (data.status === 'success') {
fetchCartItems();
calculateSubtotal();
$('#product').modal('hide');
} else {
alert('Failed to add item to order cart');
}
},
error: function() {
alert('An error occurred. Please try again.');
let productId = $('#product').data('product-id');
let productType = $('#product').data('product-type');
let productName = $('#productName').text();
let servingOrType = $('#servingOrTypeGroup .active').text() || $('#defaultServingOrType').val() || $('#noneServingOrType').val();
let flavorOrSize = $('#flavorOrSizeGroup .active').text() || $('#defaultFlavorOrSize').val() || $('#noneFlavorOrSize').val();
let quantity = $('#quantityInput').val();
let price = $('#priceDisplay').val();

if (servingOrType === 'Default' || servingOrType === 'None') servingOrType = '';
if (flavorOrSize === 'Default' || flavorOrSize === 'None') flavorOrSize = '';

$.ajax({
url: 'add_to_order_cart.php',
type: 'POST',
data: {
product_id: productId,
product_type: productType,
product_name: productName,
serving_or_type: servingOrType,
flavor_or_size: flavorOrSize,
quantity: quantity,
price: price
},
success: function(response) {
let data = JSON.parse(response);
if (data.status === 'success') {
fetchCartItems();
calculateSubtotal();
$('#product').modal('hide');
} else {
alert('Failed to add item to order cart');
}
});
}

$("#addToOrderCart").on("click", function(event) {
event.preventDefault();
addToCart();
$("#addToOrderCart").prop("disabled", false);
},
error: function() {
alert('An error occurred. Please try again.');
$("#addToOrderCart").prop("disabled", false);
}
});
}

$("#addToOrderCart").on("click", function(event) {
event.preventDefault();
$(this).prop("disabled", true);
addToCart();
});


function fetchCartItems() {
$.ajax({
Expand Down

0 comments on commit 1900fa6

Please sign in to comment.