Sha256: 6c98c8c7532e6657e52150fbf18f69992b03a1023a7ded4c93e448d139aee15a

Contents?: true

Size: 938 Bytes

Versions: 5

Compression:

Stored size: 938 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

5 entries across 5 versions & 1 rubygems

Version Path
solidus_frontend-2.2.2 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.2.1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.2.0 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.2.0.rc1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee
solidus_frontend-2.2.0.beta1 app/assets/javascripts/spree/frontend/checkout/coupon-code.js.coffee