OrderCustomerManager
in package
Matches or creates the Invoicer customer record for an order.
The only place where an order is paired with the customer register; used by the admin save (OrderPresenter::internalActionBuild()) and by the front checkout, so the logic is never duplicated. Talks to Invoicer only through its Api managers, never through direct SQL or an Admin manager.
Table of Contents
Properties
- $customerContactManager : CustomerContactManager
- $customerManager : CustomerManager
- $unitOfWorkReset : UnitOfWorkReset
Methods
- __construct() : mixed
- manualSelection() : array{customerId: int, customerContactId: ?int}|null
- Resolves a customer picked manually in the admin picker; a manual pick takes precedence over `resolve()`.
- resolve() : array{customerId: ?int, customerContactId: ?int}
- createCustomerWithContact() : array{customerId: ?int, customerContactId: ?int}|null
- findContactByEmail() : CustomerContact|null
- reopenEntityManagerIfClosed() : void
- Reopens the EM after a failed flush so the order can still be saved; see {@see \App\Core\Doctrine\EntityManagerReopener}.
- trimOrNull() : string|null
Properties
$customerContactManager read-only
private
CustomerContactManager
$customerContactManager
$customerManager read-only
private
CustomerManager
$customerManager
$unitOfWorkReset read-only
private
UnitOfWorkReset
$unitOfWorkReset
Methods
__construct()
public
__construct(CustomerContactManager $customerContactManager, CustomerManager $customerManager, UnitOfWorkReset $unitOfWorkReset) : mixed
Parameters
- $customerContactManager : CustomerContactManager
- $customerManager : CustomerManager
- $unitOfWorkReset : UnitOfWorkReset
manualSelection()
Resolves a customer picked manually in the admin picker; a manual pick takes precedence over `resolve()`.
public
manualSelection(int $customerId[, int|null $contactId = null ]) : array{customerId: int, customerContactId: ?int}|null
$contactId optionally selects a specific address. When it is missing or belongs to
another customer (ownership guard; it is never used and throws nothing), the first
contact is used. Returns null when the customer no longer exists (deleted between the
pick and the save); the caller must not use the id then, because orders has a real
foreign key and the insert would fail the whole order save.
Parameters
- $customerId : int
- $contactId : int|null = null
Return values
array{customerId: int, customerContactId: ?int}|nullresolve()
public
resolve(string $email, array{companyName?: ?string, firstname?: ?string, lastname?: ?string, street?: ?string, city?: ?string, postcode?: ?string, country?: ?string, countryCode?: ?string, regNo?: ?string, vatId?: ?string, phone?: ?string, informations?: ?string} $snapshot[, int|null $userId = null ]) : array{customerId: ?int, customerContactId: ?int}
Parameters
- $email : string
- $snapshot : array{companyName?: ?string, firstname?: ?string, lastname?: ?string, street?: ?string, city?: ?string, postcode?: ?string, country?: ?string, countryCode?: ?string, regNo?: ?string, vatId?: ?string, phone?: ?string, informations?: ?string}
-
fills a new contact only when no existing one is found by e-mail; a found contact is never overwritten (the register is not edited from an order)
- $userId : int|null = null
-
user account of the order (
Order.userId); linked toCustomer.userIdonly when a new customer is created, so an existing customer'suserIdis never overwritten or cleared
Return values
array{customerId: ?int, customerContactId: ?int}createCustomerWithContact()
private
createCustomerWithContact(string $email, array{companyName?: ?string, firstname?: ?string, lastname?: ?string, street?: ?string, city?: ?string, postcode?: ?string, country?: ?string, countryCode?: ?string, regNo?: ?string, vatId?: ?string, phone?: ?string, informations?: ?string} $snapshot[, int|null $userId = null ]) : array{customerId: ?int, customerContactId: ?int}|null
Parameters
- $email : string
- $snapshot : array{companyName?: ?string, firstname?: ?string, lastname?: ?string, street?: ?string, city?: ?string, postcode?: ?string, country?: ?string, countryCode?: ?string, regNo?: ?string, vatId?: ?string, phone?: ?string, informations?: ?string}
- $userId : int|null = null
-
see resolve(); linked only to the customer created here
Return values
array{customerId: ?int, customerContactId: ?int}|null —null = the insert hit the unique e-mail key, so the caller repeats the lookup
findContactByEmail()
private
findContactByEmail(string $email) : CustomerContact|null
Parameters
- $email : string
Return values
CustomerContact|nullreopenEntityManagerIfClosed()
Reopens the EM after a failed flush so the order can still be saved; see {@see \App\Core\Doctrine\EntityManagerReopener}.
private
reopenEntityManagerIfClosed() : void
trimOrNull()
private
trimOrNull(string|null $value) : string|null
Parameters
- $value : string|null