Here is some test code provided by FoxyCart to add a coupon field to your FoxyCart checkout template. You must be using store 60 or higher.
This has not been tested with all features of foxee and foxycart
If it works for you let us know, if it doesn’t, let us know
// FOR TESTING PURPOSES ONLY
FC.checkout.InitCoupon = function() {
fc_cart_foot_discount_new = '<tr id="fc_cart_foot_discount_new"><td class="fc_col1" colspan="2"><a href="#">Add a coupon</a></td><td class="fc_col2"><input type="text" name="coupon" id="fc_coupon" class="fc_text fc_text_short" value="" style="display:none;" /><a id="fc_coupon_apply" href="[removed];" style="display:none;">Apply!</a></td></tr>';
if (jQuery('#fc_cart_foot_discount_new').length == 0) {
jQuery(fc_cart_foot_discount_new).insertBefore('#fc_cart_foot_shipping');
}
jQuery('#fc_coupon_apply').unbind('click').click(function(){
coupon = jQuery('#fc_coupon').val();
if (coupon != '') {
FC.checkout.ApplyCoupon(coupon);
} else {
alert('Please enter a coupon code.');
}
});
}
FC.checkout.AddCoupon = function() {
jQuery("#fc_coupon, #fc_coupon_apply").toggle();
if (jQuery("#fc_coupon").is(":visible")) {
jQuery("#fc_coupon")[0].focus();
}
}
FC.checkout.ApplyCoupon = function(coupon) {
jQuery('#fc_coupon_apply').html('Loading...');
console.info('getJSON?');
jQuery.getJSON('https://' + [removed].hostname + '/cart?output=json&' + FC.checkout.config.session + '&coupon;=' + coupon + '&callback;=?',
function(data) {
console.info(data);
if (data.messages.errors.length > 0) {
alert("We're sorry. An error occurred: " + data.messages.errors[0]);
} else {
console.info('Coupon: ' + data.coupons);
FC.checkout.BuildCouponTR(data.coupons);
}
jQuery('#fc_coupon_apply').html('Apply!');
}
);
}
FC.checkout.BuildCouponTR = function(coupons) {
console.info('Coupons: ' + coupons)
fc_cart_foot_discounts = '';
FC.checkout.config.orderDiscount = 0;
for (coupon in coupons) {
fc_cart_foot_discounts += '<tr class="fc_cart_foot_discount"><td class="fc_col1" colspan="2">' + coupon + ':</td><td class="fc_col2"><span class="fc_discount">' + FC.formatter.currency(coupons[coupon], true) + '</span></td></tr>';
FC.checkout.config.orderDiscount += coupons[coupon];
}
jQuery(fc_cart_foot_discounts).insertAfter('#fc_cart_foot_subtotal');
// Set the subtotal amounts
jQuery('#discount, label[for=discount]').remove();
if (FC.checkout.config.orderDiscount != 0) {
discount_total = '<li class="fc_row fc_discount"><label for="discount" class="fc_pre">Discount</label><input type="text" name="discount" id="discount" class="fc_text fc_text_short fc_text_readonly" readonly="readonly"></li>';
jQuery(discount_total).insertAfter('li.fc_shipping_cost');
}
FC.checkout.updatePriceDisplay();
}
jQuery(document).ready(function(){
FC.checkout.InitCoupon();
});
