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

[Vouchers] Flat rate of any amount #10761

Merged
merged 7 commits into from
May 19, 2023

Conversation

rioug
Copy link
Collaborator

@rioug rioug commented Apr 28, 2023

What? Why?

Add the ability to have a flat rate voucher of any amount

What should we test?

  • Enable vouchers feature
  • Visit admin/feature-toggle/features and enable or add vouchers feature

In the backoffice logged as an enterprise user:

  • Visit the Enterprise tab and click on "Settings" for a shop of your choosing, and click on the "vouchers" in left hand side menu
  • Click on "Add New button" --> New Voucher page should now have an "Amount" input
  • Enter a voucher code and an amount and click "Save"
    --> It should redirect you to the vouchers page on the enterprise edit page
    --> You should now see a list of vouchers with the one you just created, included the entered amount

On the website logged as a customer :

  • Add one or more product in your cart from the shop above
  • Proceed to checkout
  • Enter details and shipping info, click on "Next - Payment method"
  • Enter the voucher code and click "Apply"
    --> You should see a "$xx Voucher" box where xx is the amount you entered when creating a voucher
  • choose a payment method and click on "Next - Order summary"
    --> you should see the voucher applied to the order in the order summary column, with the correct amount
  • Click on "Complete order"
    --> you should see the voucher applied to the order in the order summary with the correct amount

Release notes

Changelog Category: User facing changes

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@rioug rioug self-assigned this Apr 28, 2023
@rioug rioug force-pushed the vouchers-any-amount branch 2 times, most recently from e6b77fb to b8d25de Compare April 28, 2023 05:02
@rioug rioug changed the title Vouchers any amount Vouchers, flat rate of any amount Apr 28, 2023
@rioug rioug marked this pull request as ready for review April 28, 2023 05:03
Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Nice work!

@@ -0,0 +1,5 @@
class AddAmountToVouchers < ActiveRecord::Migration[7.0]
def change
add_column :vouchers, :amount, :decimal, precision: 10, scale: 2, null: false, default: 0
Copy link
Member

Choose a reason for hiding this comment

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

Hm, the default is 0 but the Rails validation requires it to be greater than that. It's contradictory but I don't have any better ideas either. 🤷

Copy link
Member

Choose a reason for hiding this comment

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

Is a default necessary? If an amount isn't provided, then we want an error to be thrown don't we?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think you are right, my thinking was a voucher with an amount 0 is probably not a big problem, the worse than can happen is you apply a voucher that won't change the order amount..

db/schema.rb Outdated Show resolved Hide resolved
db/schema.rb Outdated Show resolved Hide resolved
app/controllers/admin/vouchers_controller.rb Outdated Show resolved Hide resolved
app/views/admin/vouchers/new.html.haml Show resolved Hide resolved
app/views/split_checkout/_voucher_section.cable_ready.haml Outdated Show resolved Hide resolved
spec/factories/voucher_factory.rb Outdated Show resolved Hide resolved
@rioug rioug force-pushed the vouchers-any-amount branch 2 times, most recently from 4e0e0c6 to 08927e6 Compare May 5, 2023 06:35
@rioug rioug requested a review from mkllnk May 5, 2023 11:53
@rioug
Copy link
Collaborator Author

rioug commented May 5, 2023

New commit start here : 2da76b2

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Great. Thank you for addressing it all.

I noticed that I get weird results in db/schema.rb on master as well. I think that something must have gotten wrong when merging. I'll open a PR to correct master.

@lin-d-hop lin-d-hop added the priority We focus on this issue right now label May 9, 2023
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

I think this is fine as-is, but have a few comments to potentially improve.

.checkout-input
%span.formError.standalone
= t("split_checkout.step2.voucher.warning_forfeit_remaining_amount")
- else
= text_field_tag "[order][voucher_code]", params.dig(:order, :voucher_code), data: { action: "input->toggle-button-disabled#inputIsChanged", }, placeholder: t("split_checkout.step2.voucher.placeholder") , class: "voucher"
= submit_tag t("split_checkout.step2.voucher.apply"), name: "apply_voucher", disabled: true, class: "button cancel voucher", "data-disable-with": false, data: { "toggle-button-disabled-target": "button" }
= submit_tag t("split_checkout.step2.voucher.apply"), name: "apply_voucher", disabled: true, class: "button cancel voucher", "data-disable-with": false, data: { "toggle-button-disabled-target": "button" }
Copy link
Member

Choose a reason for hiding this comment

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

Oops, a couple of spaces were added at end of line here.

@@ -0,0 +1,5 @@
class AddAmountToVouchers < ActiveRecord::Migration[7.0]
def change
add_column :vouchers, :amount, :decimal, precision: 10, scale: 2, null: false, default: 0
Copy link
Member

Choose a reason for hiding this comment

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

Is a default necessary? If an amount isn't provided, then we want an error to be thrown don't we?

app/controllers/admin/vouchers_controller.rb Show resolved Hide resolved
spec/system/admin/vouchers_spec.rb Show resolved Hide resolved
@rioug
Copy link
Collaborator Author

rioug commented May 12, 2023

This will need to be rebased on https://github.com/rioug/openfoodnetwork/tree/10432-vouchers-bare-minimum-checkout (or master if 10432-vouchers-bare-minimum-checkout has been merged)

@mkllnk mkllnk assigned mkllnk and unassigned rioug May 16, 2023
rioug added 6 commits May 16, 2023 16:19
Change value to amount to be more consistent
As vouchers are getting more complicated, it makes sense to use a
factory to simplify writing test.
It should have already been the case...
Speed up testing by removing unnecessarily created record
@sigmundpetersen sigmundpetersen changed the title Vouchers, flat rate of any amount [Vouchers] Flat rate of any amount May 16, 2023
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

I think we should still change the random value in the factory.

spec/factories/voucher_factory.rb Outdated Show resolved Hide resolved
dacook

This comment was marked as duplicate.

dacook

This comment was marked as duplicate.

@mkllnk
Copy link
Member

mkllnk commented May 19, 2023

Yes, I would be happy with a fixed value.

@dacook dacook self-assigned this May 19, 2023
@drummer83 drummer83 self-assigned this May 19, 2023
@drummer83 drummer83 added the pr-staged-au staging.openfoodnetwork.org.au label May 19, 2023
@drummer83
Copy link
Contributor

drummer83 commented May 19, 2023

Hi @rioug and @mkllnk,
So exciting to play with this new feature! Since it was my first time I have also noted some things which we may want to look into at some point, but they are out of scope of this PR.

General remark after staging

  • Previously generated vouchers are set to Amount = 0 (instead of 10 $ when created). I guess we can live with this, since it is not in production yet.

Positive test cases

  • only numbers > 0 are accepted ✔️
  • the new voucher is added to the vouchers list ✔️
  • checkout using the voucher works as expected ✔️
  • order confirmation page shows the voucher ✔️
  • confirmation email shows the voucher ✔️
  • vouchers can be applied unlimited times ✔️
  • vouchers can be applied by any customer ✔️
  • vouchers are not displayed when checking out at an enterprise which has no voucher codes ✔️

Proposed adjustments of backoffice design

Proposed adjustments for backoffice functionality

  • Edit vouchers
  • Delete vouchers

Proposed adjustments for checkout

Negative test cases

Peek.2023-05-19.15-48.mp4
Peek.2023-05-19.15-42.mp4
Peek.2023-05-19.16-40.mp4

Result

The requested feature has been implemented according to specification. We can merge this one here. I will open issues for the negative test cases and some of the improvements.

Thanks! 🙏

@drummer83 drummer83 merged commit fed7c3d into openfoodfoundation:master May 19, 2023
50 checks passed
@drummer83 drummer83 removed the pr-staged-au staging.openfoodnetwork.org.au label May 19, 2023
@mkllnk
Copy link
Member

mkllnk commented May 22, 2023

Thank you, excellent testing. Definitely some edge cases to work out before it can be released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority We focus on this issue right now
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants