我正在尝试在我的订单中设置优惠券/促销/折扣代码,但是我无法获取优惠券金额以转到 updatePrices 功能。
function updateCoupon() {
var coupon = $('#coupon').val();
if (coupon.length) {
$('#couponContainer .checking').show();
$.ajax({
url: "/includes/pscript/coupon.php",
data: {coupon: coupon},
dataType: 'json',
type: 'POST',
success: function(data) {
if(typeof data.available != 'undefined' && data.available == true) {
coupon_discount = new Number(data.price.discount);
$('#couponStatus').html('<p>'+data.status+'</p > ');
$('#couponContainer .checking').hide();
$('#couponStatus').show();
updatePrices(coupon_discount);
} else {
coupon_discount = 0;
$('#coupon ').val('');
$('#couponContainer .checking').hide();
$('#couponStatus ').hide();
$('#couponStatus ').html('');
alert('Sorry this discount code is no long valid!');
}
},
error: function() {
coupon_discount = 0;
$('#coupon ').val('');
$('#couponContainer .checking').hide();
$('#couponStatus ').hide();
$('#couponStatus ').html('');
alert('Sorry this discount code is no long valid!');
}
});
}
else
{
coupon_discount = 0;
$('#coupon').val('');
$('#couponContainer.checking ').hide();
$('#couponStatus ').hide();
$('#couponStatus ').html('');
alert('Sorry this discount code is no long valid!');
}
}
以上确实有效,并且它收到了金额。一旦它有我希望它发送到 updatePrices() 的金额;
function updatePrices(a, coupon_discount) {
var item_price = 0;
var delivery_price = 0;
var discounts = 0;
if(coupon_discount != 0){
var coupon_discount = coupon_discount;
alert('Coupon '+coupon_discount);
}
var product = $("[name='Product']").val();
...
if(coupon_discount != 0)
{
discounts += coupon_discount;
}
var total = (item_price + delivery_price - discounts);
}
这只是代码的一部分。我想做的就是,updateCoupon 获取价格将其发送到 updatePrices - 如果说产品已更改,则优惠券将被删除,并且会出现一条消息以重新申请。
当前问题:我在 updatePrices() 中未定义