Problem/Motivation

A user buying for several organizations needs one cart per organization, and switching organization must change which carts are returned. Today CartProvider caches carts per uid and filters by store only. Parent: #3638816: [META] Commerce 4.x roadmap.

Proposed resolution

  • Every lookup (getCart(), getCartId(), getCarts(), getCartIds()) is scoped to the organization the account acts for in the store: personal (no organization) returns carts without one. createCart() sets that same organization on the new cart, and its duplicate cart check is per organization.
  • Without a store, getCarts() and getCartIds() resolve the organization per cart's store (once per store), since the organization can differ per store (#3639236: Add OrganizationInterface and an optional organization on the Context).
  • For the current user in the current store, the organization comes from CurrentOrganization: resolved once per request, consistently with the organization cache context and the pricing context. Other accounts and stores go through the resolver chain. Anything changing which organization a user acts for mid-request dispatches OrganizationEvents::SWITCH, which resets CurrentOrganization.
  • The cached cart data includes each cart's organization, and the lookups filter on it.
  • isEligibleCart() also requires the cart's organization, if any, to be published.
  • The cart cache context derives from getCartIds(), so its value follows the current organization.
  • CartProviderInterface keeps its signatures: no organization parameter, since NULL would mean both "resolve it" and "personal cart". Code needing another organization's cart creates the order and calls setOrganization(); code listing carts across organizations queries orders directly.

Remaining tasks

  • Kernel tests: one cart per user per organization, personal carts, switching, duplicate check, carts across stores resolving different organizations, the current organization resolved once per request, unpublished organization, cart cache context. Done, in CartOrganizationTest.

Issue fork commerce-3641082

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jsacksick created an issue. See original summary.

jsacksick’s picture

Status: Active » Needs review
jsacksick’s picture

Issue summary: View changes

  • jsacksick committed bbc4cceb on 4.x
    feat: #3641082 Scope cart lookups to the current organization
    
jsacksick’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.