Skip to content

14004 link correct customer to order#14008

Merged
rioug merged 4 commits intoopenfoodfoundation:masterfrom
rioug:14004-link-correct-customer-to-order
Mar 10, 2026
Merged

14004 link correct customer to order#14008
rioug merged 4 commits intoopenfoodfoundation:masterfrom
rioug:14004-link-correct-customer-to-order

Conversation

@rioug
Copy link
Collaborator

@rioug rioug commented Mar 10, 2026

What? Why?

After placing an order shop A, and starting a new order on shop B, the order stayed linked to customer from shop A. This PR update the CartResetService logic to properly update the customer when switching shop.

What should we test?

  • Have a user that is a customer in two different shop (Shop A and Shop B)
  • In the backoffice, update the two customers billing address with a distinct name. ie set first name to Shop A and Shop B
  • Start an order with Shop A, on the checkout details step, you should see "Shop A" as first name for the billing address
  • Finish placing the order
  • Navigate to Shop B
  • Start an order with Shop B, on the checkout details step,
    --> you should see "Shop B" as first name for the billing address.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

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

Dependencies

Documentation updates

@github-project-automation github-project-automation bot moved this to All the things 💤 in OFN Delivery board Mar 10, 2026
@rioug rioug moved this from All the things 💤 to Code review 🔎 in OFN Delivery board Mar 10, 2026
@rioug rioug moved this from Code review 🔎 to In Progress ⚙ in OFN Delivery board Mar 10, 2026
@rioug rioug force-pushed the 14004-link-correct-customer-to-order branch from f8f3ac2 to bca5ee2 Compare March 10, 2026 03:15
@rioug rioug moved this from In Progress ⚙ to Code review 🔎 in OFN Delivery board Mar 10, 2026
@rioug rioug added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Mar 10, 2026
@dacook dacook self-requested a review March 10, 2026 03:28
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.

Great, glad that was a simple fix!

attr_reader :order, :distributor, :current_user

def reset_user_and_customer(current_user)
def reset_user(current_user)
Copy link
Member

Choose a reason for hiding this comment

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

That was a badly named method! I guess something got changed but the method name stayed the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, once upon a time it called associated_customer on the order.

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! I'm just wondering if it's possible that there is not customer record yet. We don't want to keep the old customer record in that case, do we?

reset_user_and_customer(current_user)
reset_user(current_user)
reset_order_cycle(current_customer)
order.customer = current_customer if current_customer.present?
Copy link
Member

Choose a reason for hiding this comment

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

What if it's not present? Maybe you don't have a customer record yet. Should we set it to nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, for instance if you log out after placing an order and start a new order as a guest we end up the scenario where the order has a customer but system doesn't have a current customer.

Fixed here : d706b3a

reset_user_and_customer(current_user)
reset_user(current_user)
reset_order_cycle(current_customer)
order.customer = current_customer if current_customer.present?
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
order.customer = current_customer if current_customer.present?
order.customer = current_customer

@rioug rioug requested review from dacook and mkllnk March 10, 2026 04:29
@mkllnk mkllnk moved this from Code review 🔎 to Test Ready 🧪 in OFN Delivery board Mar 10, 2026
@rioug
Copy link
Collaborator Author

rioug commented Mar 10, 2026

Has discussed with @mkllnk and @dacook we'll merge without testing, it will be covered by payment with credit testing.

@rioug rioug merged commit b50f299 into openfoodfoundation:master Mar 10, 2026
31 checks passed
@github-project-automation github-project-automation bot moved this from Test Ready 🧪 to Done in OFN Delivery board Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

technical changes only These pull requests do not contain user facing changes and are grouped in release notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Wrong customer associated with order when switching shop

3 participants