Problem/Motivation

AddressBookInterface only knows the user: load() and loadAll() take (UserInterface $customer, $profile_type_id, array $available_countries = []), copy() takes (ProfileInterface $profile, UserInterface $customer), and profiles are looked up by owner.

A decorator therefore cannot tell what a call is for: which order, store or organization (see #3638816: [META] Commerce 4.x roadmap). Falling back to the current request is wrong off-request (order assignment, admin edits, cron).

Proposed resolution

Add a trailing ?Context $context = NULL argument to load(), loadAll() and copy(). A Context rather than the order, because the address book is also used without an order, and the Context already carries the customer and store (and later the organization).

Callers that have an order pass OrderContextFactoryInterface::createForOrder() from #3639232: Add context services to build the pricing Context:

Caller Change
CustomerProfile inline form (address_book_uid config), used by BillingInformation, PaymentInformation, BillingProfileWidget, and commerce_shipping's ShippingInformation and ShippingProfileWidget New optional context config, set by each caller from the order; the form passes it to load(), loadAll() and copy()
AddressBookSubscriber::onOrderPlace() / onOrderAssign() Pass the order Context to copy()
commerce_payment OrderAssignSubscriber Same
PaymentMethodFormBase Unchanged: payment method profiles stay personal
AddressBookController (user address book pages) Unchanged: the personal address book

The core implementation accepts the Context and ignores it for now. Organization behavior (not copying a company address into the buyer's personal address book) comes with the organization work.

Remaining tasks

User interface changes

None.

API changes

Implementations and decorators of AddressBookInterface must add the new argument to their signatures. No other implementer exists among commonly used contrib modules.

Data model changes

None.

Comments

jsacksick created an issue.