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

Improve coupon code JS applicator #1090

Merged
merged 2 commits into from
May 18, 2016
Merged

Improve coupon code JS applicator #1090

merged 2 commits into from
May 18, 2016

Conversation

mtomov
Copy link
Contributor

@mtomov mtomov commented Apr 21, 2016

  • Separate Coupon code application from Saving & processing a payment

    » allows users to first apply a code, and subsequently add payment details when they are certain of the final amount to be paid.

  • Add new button Apply Code

  • Separate payment js from coupon code js - allows for easier override
    as they are now in separate files.

  • Specify your own css class as a main one, ex: callout. The JS applicator will automatically add success or alert classes as appropriate.

  • Allow customisation of the CSS classes applied on success and on error
    via data attributes data-success-class and data-success-error.

  • Fix a refresh bug on coupon code application error - before, the page
    was refreshed even after displaying an AJAX brought error message.
    See issue & fix @spree do not submit form if coupon code is invalid at payment step spree/spree#7040

  • Fixes a JS warning that a Synchronous AJAX request was executed, which could impact JS performance as it waits for response from the server before continuing the execution of the JS. (Was coming from the async:false setting)

  • Switch to using the Spree API action for applying a code instead of the
    Frontend controller one at StoreController#apply_code.

    TODO: Delete the StoreController#apply_code similarly to Spree as
    it's not used anymore. See: Removing Spree::StoreController#apply_coupon_code spree/spree#7284

coupon code applied successfully

coupon code doesnt exist

coupon code already applied

coupon_code = $.trim(coupon_code_field.val())
return if coupon_code == ''

if $('#coupon_status').length == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? The class is defined in the view, we should be able to rely on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Took it from the old script, sort of backwards view compatible, but I guess given that the view needs a button now, I can get rid of this.

@mtomov
Copy link
Contributor Author

mtomov commented Apr 26, 2016

Thanks for reviewing @jhawthorn !

I'd be happy to also hear any other comments if anyone has.

@cbrunsdon
Copy link
Contributor

This looks pretty good to me, thanks @mtomov, 👍. And I have nothing valuable to add to the open conversations.

@mamhoff
Copy link
Contributor

mamhoff commented Apr 27, 2016

I'm just very happy about the submit Event listener being gone. 👍 -- also nothing valuabel to add to the existing conversations.

@mtomov
Copy link
Contributor Author

mtomov commented Apr 29, 2016

Hi @jhawthorn , I've made this one change in the JS (don't auto-create the div tag).

It's good that we don't attach to the submit event, as I have seen payment gateways (Braintree) also attach to it, and it can get a bit messy when one needs to cancel the execution of the other..

Let me know if there's more I can adjust!

@jhawthorn
Copy link
Contributor

👍

@cbrunsdon
Copy link
Contributor

Still good by me, nice work 👍

We're almost definitely going to need a changelog entry for this change though.

</p>
<div id='coupon_status'
data-success-class="success"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these values match the defaults here https://github.com/solidusio/solidus/pull/1090/files#diff-a065997c80be8446e236252c98a12800R7 we don't need to duplicate them here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but they are present for documentation purposes here. Alternatively, I can remove the defaults in the JS, but I thought they don't add much noise, so why not have them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They imply that they are overwriting default behaviour. If we want to document it both the changelog and the JS file make very good candidates for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but frontend developers (and even lazy people like me) don't tend to meddle with the middle of some JavaScript file to find out that they can actually customize the classes.

 - separate Coupon code application from Saving & processing a payment

   => allows users to first apply a code, and subsequently add payment
       details when they are certain of the final amount to be paid.

 - Add new button Apply Code

 - Separate payment js from coupon code js - allows for easier override
   as they are now in separate files.

 - Allow customisation of the CSS classes applied on success and on error
   via data attributes `data-success-class` and `data-success-error`.

 - Fix a refresh bug on coupon code application error - before, the page
   was refreshed even after displaying an AJAX brought error message.
   See issue & fix @spree spree/spree#7040

 - Fixes a JS warning that a Synchronous AJAX request was executed, which
   could impact JS performance as it waits for response from the server
   before continuing the execution of the JS.
   (Was coming from the `async:false` setting in `Spree.ajax`)

 - Switch to using the Spree API action for applying a code instead of the
   Frontend controller one at StoreController#apply_code.

   TODO: Delete the StoreController#apply_code similarly to Spree as
         it's not used anymore. See: spree/spree#7284
@mtomov
Copy link
Contributor Author

mtomov commented May 6, 2016

Changelog added + CSS classes streamlined. Let me know of anything else. Otherwise I can squash it. Thank you for the feedback!

  - Specify your own class as a main one, ex: `callout`

  - The JS applicator will automatically add `success` or `alert` classes
    as appropriate
@jhawthorn
Copy link
Contributor

👍 Thank you

@jhawthorn jhawthorn merged commit 4eaef6c into solidusio:master May 18, 2016
@mtomov
Copy link
Contributor Author

mtomov commented May 19, 2016

👍

@mtomov mtomov deleted the improve-coupon-code-applicator branch May 19, 2016 10:47
kennyadsl added a commit to nebulab/solidus that referenced this pull request Sep 21, 2017
Applying coupon code should be only handled with its own "Apply Code"
button, which will trigger an API call that tries to apply the coupon
code and refresh the page (solidusio#1090).
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 this pull request may close these issues.

5 participants