Как настроить или объединить оба сценария (Ajax параметры проверки и корзины покупок и функции обратного вызова), чтобы я отправлял данные контактной формы (Ajax проверка) и checkoutString (jcitems и jctotal) в «проверку». php "на стороне сервера и получать все данные одним письмом?
jQuery (function ($) {
" use strict ";
//Ajax validation
var order = $('.form-validation');
order.submit(function () {
$this = $(this);
$.post($(this).attr('action'),$(this).serialize(),'json');
return false;
});
//shopping cart options & callback functions
var options = {
currencySymbol: ' FCFA',
classCartIcon: 'my-cart-icon',
classCartBadge: 'my-cart-badge',
classProductQuantity: 'my-product-quantity',
classProductRemove: 'my-product-remove',
classCheckoutCart: 'my-cart-checkout',
affixCartIcon: true,
showCheckoutModal: true,
numberOfDecimals: 0,
cartItems: [],
clickOnAddToCart: function($addTocart){
goToCartIcon($addTocart);
},
afterAddOnCart: function(products, totalPrice, totalQuantity) {
console.log("afterAddOnCart", products, totalPrice, totalQuantity);
},
clickOnCartIcon: function($cartIcon, products, totalPrice, totalQuantity) {
console.log("cart icon clicked", $cartIcon, products, totalPrice, totalQuantity);
},
checkoutCart: function(products, totalPrice, totalQuantity) {
var PayPal="PayPal", GoogleCheckout="GoogleCheckout", Email="Email", checkoutString = "Total Price: " + totalPrice + "\nTotal Quantity: " + totalQuantity;
//checkout method
this.checkoutTo = Email;
// checkout management
this.checkout = function() {
if(options.quantity === 0){
error("Cart is empty");
return;
}
switch(options.checkoutTo){
case PayPal:
options.paypalCheckout();
break;
case GoogleCheckout:
options.googleCheckout();
break;
case Email:
options.emailCheckout();
break;
default:
options.customCheckout();
break;
}
};
this.paypalCheckout = function() {
return;
};
this.googleCheckout = function() {
return;
};
this.emailCheckout = function() {
checkoutString += "\n\n id \t name \t summary \t price \t quantity";
$.each(products, function(){
checkoutString += ("\n " + this.id + " \t " + this.name + " \t " + this.summary + " \t " + this.price + " \t " + this.quantity);
});
var form = document.createElement("form");
form.style.display = "none";
form.method = "POST";
form.action = "validation.php";
form.acceptCharset = "utf-8";
form.appendChild(this.createHiddenElement("jcitems", checkoutString));
form.appendChild(this.createHiddenElement("jctotal", this.total));
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
};
this.customCheckout = function() {
return;
};
// form element
this.createHiddenElement = function (name, value){
var element = document.createElement("input");
element.type = "hidden";
element.name = name;
element.value = value;
return element;
};
// error management
function error(message){
try{
console.log(message);
}catch(err){
// alert(message);
}
}
alert(checkoutString);
console.log("checking out", products, totalPrice, totalQuantity);
},
getDiscountPrice: function(products, totalPrice, totalQuantity) {
console.log("calculating discount", products, totalPrice, totalQuantity);
return totalPrice * 0.9;
}
};
});