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

Coupon and Gateway errors are displayed in flash_messages #4034

Closed
sc0ttman opened this issue Nov 29, 2013 · 8 comments
Closed

Coupon and Gateway errors are displayed in flash_messages #4034

sc0ttman opened this issue Nov 29, 2013 · 8 comments

Comments

@sc0ttman
Copy link
Contributor

The problem with this is that if you are in the checkout process, they take 2 page reloads to disappear. I think this is due to checkout pages being rendered instead of redirected and therefore the errors linger around for an extra page request.

Should these types of errors not be rendered in the checkout errors partial: spree/shared/error_messages?

@radar
Copy link
Contributor

radar commented Nov 29, 2013

Hi Scott, which version of Spree is this on?

On Sat, Nov 30, 2013 at 7:09 AM, Scott notifications@github.com wrote:

The problem with this is that if you are in the checkout process, they take 2 page reloads to disappear. I think this is due to checkout pages being rendered instead of redirected and therefore the errors linger around for an extra page request.

Reply to this email directly or view it on GitHub:
#4034

@sc0ttman
Copy link
Contributor Author

Hey @radar, sorry I forgot to add that I am using: `gem 'spree', '~> 2.1.2'```

@radar
Copy link
Contributor

radar commented Nov 29, 2013

Thanks! I'll take  a look at this next week when I get a chance. Seems pretty straightforward.

On Sat, Nov 30, 2013 at 9:31 AM, Scott notifications@github.com wrote:

Hey @radar, sorry I forgot to add: `gem 'spree', '~> 2.1.2'```

Reply to this email directly or view it on GitHub:
#4034 (comment)

@radar
Copy link
Contributor

radar commented Dec 4, 2013

Hi again @sc0ttman, I have got a fix in for the coupon problem in 2-1-stable and 2-0-stable -- in master we use the API to apply a coupon, so this patch is not needed there.

I wasn't able to get a gateway error to display... do you have some steps to reproduce that kind of problem that I could try?

@sc0ttman
Copy link
Contributor Author

sc0ttman commented Dec 4, 2013

Awesome @radar thanks!

I seemed to have tracked the error message spree_gateway_error_flash_for_checkout from en.yml to where it's displayed in spree_frontend:

def rescue_from_spree_gateway_error(exception)

I would imagine your flash.now fix would work here as well?

@sc0ttman
Copy link
Contributor Author

sc0ttman commented Dec 4, 2013

Hrm, I tried applying your fix as a decorator in my app, and it still seems to be flashing the old way.

Spree::CheckoutController.class_eval do

  private

    def apply_coupon_code
      if params[:order] && params[:order][:coupon_code]
        @order.coupon_code = params[:order][:coupon_code]

        coupon_result = Spree::Promo::CouponApplicator.new(@order).apply
        if coupon_result[:coupon_applied?]
          flash[:success] = coupon_result[:success] if coupon_result[:success].present?
        else
          flash.now[:error] = coupon_result[:error]
          respond_with(@order) { |format| format.html { render :edit } } and return
        end
      end
    end

end

I even tried removing the error flash to make sure it was coming from that line, and it still displayed the error. Any ideas?

@sc0ttman
Copy link
Contributor Author

sc0ttman commented Dec 5, 2013

Turns out the coupon code is being applied in the orders controller. Using your flash.now fix here does the trick!

@radar
Copy link
Contributor

radar commented Dec 6, 2013

Thanks @sc0ttman! I've now got a couple of commits pending for 2-0-stable, 2-1-stable and master which will fix the gateway messages and coupon errors appearing more than they should. Thank you for pointing out where the flash.now calls were lacking.

radar added a commit that referenced this issue Dec 6, 2013
radar added a commit that referenced this issue Dec 6, 2013
radar added a commit that referenced this issue Dec 6, 2013
…ller

Otherwise this will carry over to the next request, which is not fun.

Fixes #4034
@radar radar closed this as completed in 764f57f Dec 10, 2013
radar added a commit that referenced this issue Dec 10, 2013
…ller

Otherwise this will carry over to the next request, which is not fun.

Fixes #4034
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

No branches or pull requests

2 participants