Sha256: 92f3e48b090542621326f7508235f2acc8375721dfbca757e18b2fc485b3ec7f

Contents?: true

Size: 940 Bytes

Versions: 15

Compression:

Stored size: 940 Bytes

Contents

Spree.onCouponCodeApply = (e) ->
  couponCodeField = $('#order_coupon_code')
  couponCode = $.trim(couponCodeField.val())
  return if couponCode == ''

  couponStatus = $("#coupon_status")
  successClass = 'success'
  errorClass = 'alert'
  url = Spree.url(Spree.routes.apply_coupon_code(Spree.current_order_id),
    {
      order_token: Spree.current_order_token,
      coupon_code: couponCode
    }
  )

  couponStatus.removeClass([successClass,errorClass].join(" "));

  req = Spree.ajax
    method: "PUT",
    url: url

  req.done (data) ->
    window.location.reload();
    couponCodeField.val('')
    couponStatus.addClass(successClass).html("Coupon code applied successfully.")

  req.fail (xhr) ->
    # handler = JSON.parse(xhr.responseText)
    handler = xhr.responseJSON
    couponStatus.addClass(errorClass).html(handler["error"])

Spree.ready ($) ->
  $('#coupon-code-apply-button').click (e) ->
    Spree.onCouponCodeApply(e)

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
solidus_frontend-2.1.1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.0.3 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-1.4.2 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.0.2 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-1.4.1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.1.0 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.1.0.rc1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.0.1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.1.0.beta1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.0.0 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-1.4.0 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.0.0.rc1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-1.4.0.rc1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.0.0.beta1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-1.4.0.beta1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee