Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Coupon Code? #1641

Closed
flyfy1 opened this issue Dec 6, 2016 · 9 comments · Fixed by #3047
Closed

Remove Coupon Code? #1641

flyfy1 opened this issue Dec 6, 2016 · 9 comments · Fixed by #3047

Comments

@flyfy1
Copy link
Contributor

flyfy1 commented Dec 6, 2016

Currently, we can apply coupon code via endpoint /api/orders/:id/apply_coupon_code.

However, how to remove a coupon code?

@mtomov
Copy link
Contributor

mtomov commented Dec 6, 2016

There's no in-build way currently. One one occasion I had a custom endpoint built:

class CouponCodesController < Spree::StoreController
  before_action :find_order

  def destroy
    @handler = Spree::PromotionHandler::Coupon.new(@order).destroy!
  end

  private

  def find_order
    @order = current_order
    render_404 unless @order
  end
end
  # added to Spree::PromotionHandler::Coupon
  def destroy!(perform_update: true)
    order.order_promotions.select(&:has_code?).map(&:destroy)

    order.adjustments.promotion.select(&:has_code?).map(&:destroy)
    order.line_item_adjustments.promotion.select(&:has_code?).map(&:destroy)
    order.shipment_adjustments.promotion.select(&:has_code?).map(&:destroy)

    order.update! if perform_update

    set_success_code :coupon_code_removed
    self
  end

@flyfy1
Copy link
Contributor Author

flyfy1 commented Dec 7, 2016

Thanks @mtomov . I ended up building a customized endpoint for remove coupon also, similar idea followed :)

@flyfy1 flyfy1 closed this as completed Dec 7, 2016
@flyfy1
Copy link
Contributor Author

flyfy1 commented Dec 30, 2016

Just in case anyone needs to see how to do, here's what I did:

image

@justinstander
Copy link

undefined method `remove' for #Spree::PromotionHandler::Coupon:0x00007fbf4368ec28

@kennyadsl
Copy link
Member

Reopened since I think Solidus still need this endpoint

@aitbw
Copy link
Contributor

aitbw commented Jan 15, 2019

Working on it!

@kennyadsl
Copy link
Member

@aitbw I think also @loicginoux is working on it, please coordinate 🤝

@loicginoux
Copy link
Contributor

checked on Slack, he is doing it.

@jacobherrington
Copy link
Contributor

We just talked about needing this at Engine. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants