Sha256: a0df004d8b413cf00cff3ba287ca136574d497be3b2c9b7c733485d9af83f368
Contents?: true
Size: 1.1 KB
Versions: 14
Compression:
Stored size: 1.1 KB
Contents
Spree.onCouponCodeApply = function(e) { var couponCodeField = $("#order_coupon_code"); var couponCode = $.trim(couponCodeField.val()); if (couponCode === "") { return; } var couponStatus = $("#coupon_status"); var successClass = "success"; var errorClass = "alert"; couponStatus.removeClass([successClass, errorClass].join(" ")); var data = { order_token: Spree.current_order_token, coupon_code: couponCode }; var req = Spree.ajax({ method: "PUT", url: Spree.routes.apply_coupon_code(Spree.current_order_id), data: JSON.stringify(data), contentType: "application/json" }); req.done(function(data) { window.location.reload(); couponCodeField.val(""); couponStatus .addClass(successClass) .html("Coupon code applied successfully."); }); req.fail(function(xhr) { var handler; // handler = JSON.parse(xhr.responseText) handler = xhr.responseJSON; couponStatus.addClass(errorClass).html(handler["error"]); }); }; Spree.ready(function($) { $("#coupon-code-apply-button").click(function(e) { Spree.onCouponCodeApply(e); }); });
Version data entries
14 entries across 14 versions & 1 rubygems