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

Let people customise which shipping methods are available to customers on order cycles #9262

Merged

Conversation

cillian
Copy link
Contributor

@cillian cillian commented Jun 5, 2022

What? Why?

Closes #8974

This adds a new step 4. Checkout options to editing order cycles. This only applies to order cycles for distributors e.g. sells = 'any'. For 'simple', direct sales, order cycles where :sells = 'own' all shipping methods are to be available by default like they are currently.

checkout-options

This is a bit different from the spec because updating step 3. Outgoing would have be done in Angular and that would have taken a lot longer. I believe the plan is to convert the edit order cycle form to StimulusJs as soon as possible anyway so it was quicker and easier to do this in plain Rails.

Note, the screenshot includes a 'back office only' shipping method which is disabled and cannot be selected. It also includes a shared shipping method which is shared by two enterprises.

The 'Ready for' and 'Customer instructions' fields haven't been moved yet. It might be best to do those in separate PRs are this one is already big enough.

This adds a :shipping_methods_customisable flag to the order cycles table in order to have a record of which order cycles which were created before this feature i.e. order cycles on which it was not possible to customise shipping methods. This excludes active or upcoming order cycles at the time of the migration because shipping methods on these should be customisable so the :shipping_methods_customisable flag will be set to true for these.

What should we test?

See Acceptance criteria & tests in #8974

It would be good to test the migration on a staging instance too.

Release notes

Changelog Category: User facing changes

Documentation updates

The Order Cycles (for hubs) page in the user guide will probably need to be updated.

@cillian cillian force-pushed the order-cycle-shipping-methods branch 4 times, most recently from a56d192 to 89d3e12 Compare June 6, 2022 15:52
@cillian cillian marked this pull request as ready for review June 6, 2022 15:53
@cillian cillian force-pushed the order-cycle-shipping-methods branch from 89d3e12 to a476e22 Compare June 6, 2022 21:43
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.

Wow, great work! ✨

It's a huge chunk of work in one commit though. Would you mind splitting it up? For example, there are some refactors which make it harder to see which logic changed at the same time. And if you have the database migrations in a previous commit then reading the rest of the code makes more sense.

At this stage, I'm still happy to incorporate changes by rewriting the git history.

There are some style violations that need to be address as well.

Your work looks really good and thorough but I didn't read every line. My brain can't keep the whole thing in memory at once.

@lin-d-hop
Copy link
Contributor

So exciting to see this awesome work @cillian 🎉

@cillian cillian force-pushed the order-cycle-shipping-methods branch 3 times, most recently from 7e9e396 to 53b6c15 Compare June 17, 2022 12:11
@cillian
Copy link
Contributor Author

cillian commented Jun 17, 2022

👋 @mkllnk I have changed things so all shipping methods are available if none are specifically selected in the database, it's a lot simpler now. I broke it up into smaller commits too, but it might be good to squash some of them again later.

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.

I reviewed most of this PR but didn't get quite through. I still made quite a few comments below. So maybe let me know what you think about that feedback and then we go from there. It's a big change. 😄

@cillian cillian force-pushed the order-cycle-shipping-methods branch from c0ab024 to 2b1ad3a Compare June 20, 2022 20:27
@cillian cillian force-pushed the order-cycle-shipping-methods branch from f45b73e to 0fdb5bd Compare June 25, 2022 12:07
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 work! I know it's taking some time but I hope that you find it as satisfying as me to produce simpler, more maintainable code. I got a few more comments below.

@@ -71,7 +71,9 @@
%li
= shared_payment_method.name
%p
= "&mdash;<em>#{shared_payment_method.distributors.where(id: @order_cycle.distributor_ids).map(&:name).join(", ")}</em>".html_safe
&mdash;
%em
Copy link
Member

Choose a reason for hiding this comment

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

Do you need the space around the dash? Above, I added the > to the %em because I thought that you wanted to avoid the space. But the syntax is much easier if we omit it like here and have the space in there. I haven't checked how it looks and I'm a poor judge of that. Up to you. 😉

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 think with the space is probably slightly better.

@cillian
Copy link
Contributor Author

cillian commented Jun 29, 2022

@mkllnk 👍 definitely nice to see the size of this PR has been chopped down a good bit since the first draft.

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.

💪

A few more comments.

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! It looks all good to me. 😄

@cillian
Copy link
Contributor Author

cillian commented Jul 8, 2022

@mkllnk great, thank you 🎉

Copy link
Contributor

@jibees jibees left a comment

Choose a reason for hiding this comment

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

What an awesome work you've done here! Congrats! 💪 🙏

Very well broken into atomic commit, nice comment on each one.

I don't see anything wrong, this looks good to me ;)

@drummer83 drummer83 self-assigned this Jul 11, 2022
@drummer83 drummer83 added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Jul 11, 2022
@drummer83
Copy link
Contributor

Hi @cillian,
I have started to test this amazing pull request. I know that many user are waiting for this functionality. 💪

This is a big and complex one. So I decided to take separate testing notes in a document here: https://docs.google.com/document/d/1UhiVRpqWcOZ0HvwDdTBVoGxSS0iiwSL1czd_lBkJE_M/edit?usp=sharing

So far everything seems good. I only was confused by the way the shared payment methods are displayed (see no. 4 in the document). I am asking our @openfoodfoundation/train-drivers-product-owners team to comment on this one.

I have to stop for now, there is still a lot more to test. This is just to let you know your contribution is very much appreciated and we are working on testing it! 👍

@lin-d-hop
Copy link
Contributor

Thanks for all the dev, review and testing on this.

I'm afraid that when the spec changed half way through this introduced some differences in understanding between the spec and what was developed. This is totally my fault.

I'm going to go through the PR now to better understand where we are at and what's possible and then have a chat with @cillian to work out the best route forward. For now, let's pause.

Sorry to delay this everyone.

@drummer83 drummer83 removed their assignment Jul 12, 2022
mkllnk and others added 19 commits September 30, 2022 13:13
The spec was failing from time to time. I hope that this will fix it.

```
Failures:

  1)
    As an administrator
    I want to create/update complex order cycles with a specific time
 creating an order cycle with full interface
     Failure/Error: fill_in 'order_cycle_outgoing_exchange_0_pickup_time', with: 'pickup time'

     Capybara::ElementNotFound:
       Unable to find field "order_cycle_outgoing_exchange_0_pickup_time" that is not disabled

     # ./spec/system/admin/order_cycles/complex_creating_specific_time_spec.rb:138:in `add_distributor_with_fees'
     # ./spec/system/admin/order_cycles/complex_creating_specific_time_spec.rb:66:in `block (2 levels) in <main>'
     # ./spec/system/support/cuprite_setup.rb:39:in `block (2 levels) in <main>'
     # -e:1:in `<main>'
```
…checked

This means the code to set the initial value in the view template isn't needed.
…reating_specific_time_spec.rb

Not sure if this is correct but it removes the Rubocop violations.
…tions form, any shared shipping methods are to be displayed for each distributor e.g. if they belong to multiple distributors they will be displayed multiple times
…ows instead of same one, the select all checkboxes still need to be added back later

This is the new design from openfoodfoundation#9262 (comment)
…ing methods instead of order cycles to shipping methods
…hippingMethods

Before if a shipping method was shared between multiple distributors it could only be disabled/enabled on that order cycle for all the distributors which have that shipping method e.g. you couldn't select that shipping method for one distributor but disable it for another.
…ones by default per distributor, not per all distributors
…ecord::Relation sometimes and Array other times

Now it will return ActiveRecord::Relation consistently.
…into account

Note, this doesn't test checking/unchecking some distributor shipping methods and not others because that is tested in order_cycles/complex_creating_time_specific_spec.rb.
…account that DistributorShippingMethods instead of ShippingMethods are connected to OrderCycles now
… the :schedule_ids was not specified in the parameters

Before this schedules were being deleted when the Checkout Options step of editing order cycles was saved because this step wasn't sending the :schedule_ids parameter. It's more awkard for API users if they always need to explicity send the :schedule_ids parameter even if they don't want to add/remove any of the schedules, for example if they just want to update an order cycle name.
@filipefurtad0 filipefurtad0 force-pushed the order-cycle-shipping-methods branch from 478a519 to f9e29f3 Compare September 30, 2022 12:13
@cillian
Copy link
Contributor Author

cillian commented Sep 30, 2022

So, it looks like somehow the migration did not run. Should I delete this entry up 20220429092052 Create order cycles distributor shipping methods and re-stage?

@filipefurtad0 yes I think that should work. Although the old order_cycle_shipping_methods table might need to be deleted manually, there is no migration to remove it because the migration changed.

The other option would be to checkout the commit which contained the old migration and roll the migration back, then checkout the latest commit and re-run the migration again. That would remove the old table so you wouldn't need to delete it manually.

@filipefurtad0
Copy link
Contributor

Yaayy worked 🎉

image

Resuming testing,
Thanks for your help 🙌

find("body").send_keys(:escape)
def select_opening_and_closing_times
select_time("#order_cycle_orders_open_at", order_cycle_opening_time)
select_time("#order_cycle_orders_close_at", order_cycle_opening_time)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is causing this spec to fail:
https://github.com/openfoodfoundation/openfoodnetwork/actions/runs/3158670190/jobs/5140966992

It should be order_cycle_closing_time.

It does not influence the PR, so I'll continue testing 👍

@filipefurtad0 filipefurtad0 removed the pr-staged-au staging.openfoodnetwork.org.au label Sep 30, 2022
@filipefurtad0
Copy link
Contributor

Ok! Everything looks good now:

Migration


openfoodnetwork=> select * from order_cycles_distributor_shipping_methods;
 order_cycle_id | distributor_shipping_method_id 
----------------+--------------------------------
           3805 |                            853
(1 row)

Which corresponds to:

image

Behavior and acceptance criteria

  • After the latest changes it is not possible to de-select all shipping methods, the guard for this works fine ✔️
Screencast.from.30-09-2022.14.30.26.webm
  • Tested in both legacy and split-checkout: the selected shipping methods appear on the corresponding sections ✔️
  • The design is resilient in edge cases like de-selecting shipping methods (as admin) during the customer checkout process; Once the customer sees the option to select a shipping method it then "sticks" to the order, checkout proceeds with no issues

I think these were the pending issues!

Thanks so much all the work and patience on this one @cillian
Merging.

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.

Enable Shipping Methods to be linked to an Order Cycle
8 participants