Skip to content

Commit

Permalink
Send PUT data properly in coupon-code.js.coffee
Browse files Browse the repository at this point in the history
Previously we were sending our data as a query string, instead we should
send it as JSON, since this is a PUT request. This also avoids using the
deprecated Spree.url
  • Loading branch information
jhawthorn committed Jun 13, 2017
1 parent 3a9b1b4 commit d194535
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ Spree.onCouponCodeApply = (e) ->
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(" "))

data =
order_token: Spree.current_order_token,
coupon_code: couponCode

req = Spree.ajax
method: "PUT",
url: url
method: "PUT"
url: Spree.routes.apply_coupon_code(Spree.current_order_id)
data: JSON.stringify(data)
contentType: "application/json"

req.done (data) ->
window.location.reload()
Expand Down

0 comments on commit d194535

Please sign in to comment.