CrestApps Orchard Core Customers
A customer is everyone who buys: a person or a business, with an account or as a guest. A customer is not a user; sign-in, registration and passwords stay with Orchard Core Users, and Customer.UserId links the two. Orders, transactions and subscriptions point at one customer whatever later happens to the account.
Related skills: orchardcore-checkout (steps, tenders), orchardcore-orders (orders, gift cards), orchardcore-addresses (the Address value and editor), orchardcore-transactions (guest transactions, reminders, customer credit), orchardcore-commerce (personal data requests, API conventions, webhooks), orchardcore-taxation (tax-exempt customers).
Features
| Feature ID | Name | Depends on |
| --- | --- | --- |
| CrestApps.OrchardCore.Customers | Customers | Commerce Foundation (CommerceConstants.Features.Foundation), OrchardCore.Users, Addresses |
| CrestApps.OrchardCore.Customers.CheckoutDetails | Checkout details | Customers, Orders, Contents, Content Types |
| CrestApps.OrchardCore.Customers.StoreCredit | Store Credit | Customers, Orders |
| CrestApps.OrchardCore.Customers.Loyalty | Loyalty Points | Customers, Orders |
| CrestApps.OrchardCore.Customers.Referrals | Referrals | Customers, Orders |
| CrestApps.OrchardCore.Customers.Api | Customers API | Customers |
Constants: CustomersConstants.Features, ContactStepKey (Contact), CheckoutDetailsContentType, settings groups customers, loyalty, referrals. Install CrestApps.OrchardCore.Customers in the web project.
{
"steps": [
{
"name": "Feature",
"enable": [
"CrestApps.OrchardCore.Customers",
"CrestApps.OrchardCore.Customers.StoreCredit",
"CrestApps.OrchardCore.Customers.Loyalty",
"CrestApps.OrchardCore.Customers.Referrals"
],
"disable": []
}
]
}
The buyer identity foundation
CrestApps.OrchardCore.Customers.Abstractions is used even without the Customers feature:
CustomerOwner(CustomerOwner.ForUser(userId),CustomerOwner.ForGuest(guestCustomerId)) andCustomerOwnerKind(Authenticated,Guest), inCrestApps.OrchardCore.Customers.Models. Transactions and subscriptions storeOwnerIdplusOwnerKind.ICustomerContactResolver.ResolveAsync(owner, guestContact)andICustomerOwnerNotifier.NotifyAsync(owner, guestContact, message): a user throughINotificationService, a guest by email.AddCustomersCore()registers the defaults; the Customers feature replaces the resolver withCustomerRecordContactResolver(name from the customer record, email from the account).ICommercePersonalDataService(ExportAsync,AnonymizeAsync,ExpireAsyncby owner and email) withICommercePersonalDataContributorper feature (IdentifyAsync,ExportAsync,AnonymizeAsync,TakesPartInRetentionExpiry,trueby default andfalsefor Fundraising, Memberships, Marketplace and Reviews). It is one contributor (CommercePersonalDataContributor) of the site-wideIPersonalDataService(CrestApps.OrchardCore.PersonalData.Abstractions, namespaceCrestApps.OrchardCore.PersonalData), which also reaches the CRM, Workforce, Scheduling and other modules. A new module implementsIPersonalDataContributorand registers it withservices.AddPersonalDataContributor<T>(); useICommercePersonalDataContributoronly when it needs the commerce subject (guest owners, checkout sessions, payment-provider customers).ICustomerCreditService(CrestApps.OrchardCore.Customers.Services) is a party's customer credit:CanHold(party),CanSpendAsync(party, userId)(their own, or a party they have billing access for),GetBalanceAsync(party, currency),AddAsync(CustomerCreditChange)andSpendAsync(CustomerCreditChange)(Party,Currency,Amount,Reason,Reference,Actor), returningCustomerCreditResult(Succeeded,AlreadyApplied,Balance,Error:UnsupportedParty,InvalidAmount,InsufficientBalance,Busy). Transactions uses it, when registered, to keep overpayments and credit notes and pay balances with them. The Store Credit feature implements it; a guest never holds credit.IShippingAddressBook(CrestApps.OrchardCore.Addresses.Abstractions) is how Shipping reads and saves the buyer's address book; the Customers feature implements it on the customer record (CustomerShippingAddressBook), so Shipping never references Customers.
The customer record
Customer (CrestApps.OrchardCore.Customers.Core.Models, a CatalogItem in collection Customers): Kind (Person, Business), Status (Active, Disabled, Anonymized; merged guests are Merged), UserId, DisplayName, FirstName, LastName, CompanyName, TaxId, IsTaxExempt, TaxExemptionReason, Email, Phone, AcceptsMarketing, ExternalIds, activity dates, and up to 20 Addresses (CustomerAddress: AddressId, Label, Address) with DefaultBillingAddressId and DefaultShippingAddressId. GetName(), GetDefaultBillingAddress(), ToAddress() (a copy for an order).
| Service (CrestApps.OrchardCore.Customers.Core.Services) | Members |
| --- | --- |
| ICustomerStore | FindByIdAsync, FindByUserIdAsync, ListGuestsByEmailAsync, CreateAsync, UpdateAsync (concurrency checked), paging with CustomerQuery |
| ICustomerService | GetOrCreateForUserAsync(userId) (locked per user), FindForUserAsync, CreateGuestAsync(name, email, phone), TouchAsync |
| ICustomerHandler | CreatedAsync(customer) |
| ICustomerMergeService / ICustomerMergeHandler | MergeVerifiedGuestsAsync(userId) / MergingAsync(CustomerMergeContext) |
| ICustomerPrivacyService / ICustomerPrivacyHandler | EraseAsync, ExportAsync, ExpireAsync / ErasingAsync, ExportingAsync, Order |
CustomerIndex (one row per customer) declares .ExclusiveToDocumentType().SingleRecordPerDocument(), as do StoreCreditAccountIndex, LoyaltyAccountIndex and ReferralProfileIndex.
The customer party
A customer record is a party of kind Customer (PartyKinds.Customer, searched with ViewCustomers):
CustomerBillingProfileSourcefills its billing profile: name, e-mail and phone, the default billing address, the default shipping address when it is another place, the tax id and the exemption.CustomerPartyMemberSourcemakes the record's user its member (a guest's record has none), so a user acts for their own customer record.CustomerPartyTaxProfileProvider(IPartyTaxProfileProvider) adds the customer id, business customers taxed as a business, the exemption and certificates on file.CustomerCheckoutTaxProfileHandleruses the same rules (CustomerTaxProfiles), so a customer is taxed the same at checkout and on a document billed to them (seeorchardcore-taxation).
using CrestApps.OrchardCore.Customers.Core.Services;
public sealed class RegistrationCustomerLink
{
private readonly ICustomerService _customers;
public RegistrationCustomerLink(ICustomerService customers)
{
_customers = customers;
}
public async Task<string> GetCustomerIdAsync(string userId)
=> (await _customers.GetOrCreateForUserAsync(userId)).ItemId;
}
Checkout Contact step
With Orders, CustomerContactCheckoutHandler adds the Contact step to every order checkout (after the hidden order step): name and email required, phone, and a billing address per CustomerCheckoutSettings.BillingAddress (Optional = 0, the default, Off = 1, Required = 2; Settings > Commerce > Customers). It stores CustomerContactStep in SavedSteps and a CheckoutContactInfo on the session; on completion the order is linked to the signed-in customer or a new guest customer, and a guest's billing address becomes their default. A signed-in buyer with Off never sees the step.
With Orders on, CustomerCheckoutContactStep implements ICheckoutContactStep (Checkout.Abstractions): SaveAsync(flow, CheckoutContactDetails) saves the Contact step from code (an API or an AI agent, as Agentic Commerce does) with the page's rules.
Checkout details creates a field-less CheckoutDetails content type; add fields to it (gift message, delivery date) and they are asked on the Contact step, validated like any editor, kept on Order.CheckoutDetails and shown on the order pages.
Store credit, loyalty points and referrals
All three pay toward checkouts as tenders (after tax) for signed-in buyers only. Summary:
| Feature | Tender key | Settings | Service |
| --- | --- | --- | --- |
| Store Credit | store-credit | none | StoreCreditService.ChangeAsync(customerId, currency, amount, reason, actor, sessionId), TryChangeAsync(holder, currency, amount, reason, actor, reference) |
| Loyalty Points | loyalty-points | LoyaltySettings (Settings > Commerce > Rewards) | LoyaltyService.ChangeAsync(customerId, points, kind, reason, actor, orderId) |
| Referrals | rewards in credit or points | ReferralSettings (Settings > Commerce > Referrals) | ReferralService, link refer/{code} |
Store credit can belong to another party than a customer record, such as a business account (StoreCreditHolder.ForParty(party); PartyKind and PartyId on the account and index). With Store Credit on, StoreCreditCustomerCreditService is the ICustomerCreditService: keeping credit for a user without a customer record creates one, spending or reading never does, and a change with a Reference is applied once (AlreadyApplied). Accounts keep their latest 50 changes; older ones move to their own records through IBalanceLedgerArchive.
Details, settings JSON and the account pages are in references/store-credit-loyalty-referrals.md.
Merging guests, privacy and retention
ICustomerMergeService.MergeVerifiedGuestsAsyncruns on sign-in, registration and email confirmation, only for a confirmed email: each active guest with that email is merged through everyICustomerMergeHandler(Orders moves orders and their guest transactions), addresses are copied, and the guest is markedMerged. Resolve the merge service lazily in user event handlers (it depends on the user service).EraseAsync(customer, by)runs everyICustomerPrivacyHandler.ErasingAsync(lowerOrderfirst;PersonalDataCustomerPrivacyHandleris-100), thenCustomer.Anonymize. The Orders module'sOrderCustomerPrivacyHandleranonymizes orders and their checkout sessions (ICheckoutSessionAnonymizer);PersonalDataCustomerPrivacyHandler(formerlyCommercePersonalDataCustomerPrivacyHandler) identifies the customer by account, email and phone and callsIPersonalDataService, so an erasure reaches every module with a contributor (commerce, CRM, Workforce, Scheduling, Bookings, Marketing and more).ExportAsyncreturns aJsonObjectwith each handler's section; the personal data section is nowpersonalData(each record withkind,title,fields) instead ofcommerce. Each action is logged onCustomer.PrivacyLog.- Handlers read
CustomerPrivacyContext.Action(CustomerPrivacyAction:Exported,Erased,Expired) to tell an admin erasure from the retention expiry. OnExpired,IPersonalDataService.ExpireAsyncruns only contributors whoseTakesPartInRetentionExpiryistrue(the commerce records and stock alerts), so a guest's CRM, Workforce and Scheduling records are left alone; only an explicit erasure reaches them. CustomerRetentionBackgroundTask(daily 03:30):CustomerPrivacySettings.InactiveGuestMonths(24) expires inactive guests;GuestOrderMonths(12) anonymizes old guest records through each module'sIGuestRetentionHandler(Orders implements it asOrderGuestRetentionHandler: paid or canceled guest orders with their checkout sessions); zero turns a window off; 500 of each per run.- Admin
POST customers/{customerId}/eraseandGET customers/{customerId}/exportneedManageCustomers.
using CrestApps.OrchardCore.Customers.Core.Services;
public sealed class RegistrationPrivacyHandler : ICustomerPrivacyHandler
{
public Task ErasingAsync(CustomerPrivacyContext context, CancellationToken cancellationToken = default)
{
// context.Customer and context.UserId (the account before it is unlinked): clear your registrations.
return Task.CompletedTask;
}
public Task ExportingAsync(CustomerExportContext context, CancellationToken cancellationToken = default)
{
context.Export["registrations"] = new System.Text.Json.Nodes.JsonArray();
return Task.CompletedTask;
}
}
// services.AddScoped<ICustomerPrivacyHandler, RegistrationPrivacyHandler>();
Recipes
The Customers step adds or updates guest and business customers (matched by ItemId, then by a guest's email; account customers come from their user). The Customers deployment step (CustomersDeploymentStep) writes guest and business customers in the same shape; it is personal data, so an administrator must add it to a plan, and customers with a user account or that were erased or merged are left out.
Store credit, loyalty points and referral codes have their own steps, each with a deployment step (Store credit, Loyalty points, Referral codes). Records are matched by ItemId, then by customer (and currency for store credit), and carry their balance or points and activity. Import customers first.
| Feature | Recipe step | Array | Matched by |
| --- | --- | --- | --- |
| Store Credit | StoreCreditAccounts | Accounts | ItemId, then CustomerId and Currency |
| Loyalty Points | LoyaltyAccounts | Accounts | ItemId, then CustomerId |
| Referrals | ReferralProfiles | Profiles | ItemId, then CustomerId; a Code another customer uses is refused |
{
"steps": [
{
"name": "Customers",
"Customers": [
{
"Kind": "Business",
"CompanyName": "Contoso Supplies",
"TaxId": "123456789RT0001",
"Email": "purchasing@contoso.example",
"Addresses": [
{
"AddressId": "contoso-office",
"Label": "Office",
"Address": { "Company": "Contoso Supplies", "AddressLine1": "100 King Street West", "City": "Toronto", "Region": "ON", "PostalCode": "M5X 1C7", "Country": "CA" }
}
],
"DefaultBillingAddressId": "contoso-office",
"DefaultShippingAddressId": "contoso-office"
}
]
},
{
"name": "StoreCreditAccounts",
"Accounts": [
{ "CustomerId": "4cs00000000000000000000001", "Currency": "USD", "Balance": 25, "Activity": [] }
]
},
{
"name": "Settings",
"CustomerCheckoutSettings": { "BillingAddress": 2 },
"CustomerPrivacySettings": { "InactiveGuestMonths": 24, "GuestOrderMonths": 12 }
}
]
}
Report Builder data source
With Data Pipelines Core (OrchardCore.DataPipelines.Core) enabled, as the Report Builder does, Customers registers the Customers data source (Customers). Each data set is listed only while its feature is on. Tax ids, street lines, the privacy log and referral codes are never exposed; join the Orders data source on Customer ID for what customers bought. See orchardcore-report-builder.
| Data set | Feature | Permission |
| --- | --- | --- |
| Customers | Customers | ViewCustomers |
| LoyaltyAccounts, LoyaltyActivity | Loyalty Points | ViewCustomers |
| StoreCreditAccounts, StoreCreditActivity | Store Credit | ViewCustomers |
| Referrals, ReferralRewards | Referrals | ManageCustomers |
API
Customers API (api/commerce/v1): me and me/addresses (ManageOwnCustomerProfile), customers and customers/{customerId} (ViewCustomers), with Orders and the Checkout API PUT checkout/{id}/contact, and with Store Credit or Loyalty checkout/{id}/store-credit and checkout/{id}/points. With Commerce Webhooks, a customer.created event is published.
Screens and permissions
| Permission | Grants |
| --- | --- |
| ManageCustomers | Add, edit, export, erase; Customers settings; give or take credit and points; Rewards and Referrals settings. Implies ViewCustomers |
| ViewCustomers | List and open customers |
| ManageOwnCustomerProfile | My Account (my-account, a [CustomerAdminPage]) and storefront account/details, account/addresses; Authenticated by default |
Commerce > Customers lists customers on Orchard Core's AdminList with Active, With an account, Guests, Businesses, Disabled filters. Modules add sections to a customer's admin page with a DisplayDriver<Customer> for display type DetailAdmin, placed in Content.
Upgrading from 2.x
New in 3.0. Transactions moved from a null owner to CustomerOwner with OwnerKind; a guest transaction is never shown to an account sharing its id.
CommercePersonalDataCustomerPrivacyHandleris nowPersonalDataCustomerPrivacyHandlerover the site-wideIPersonalDataService; the export section ispersonalData, notcommerce.OrderCustomerMergeHandler,OrderCustomerPrivacyHandlerandOrderGuestRetentionHandlerlive in the Orders module (registered when Customers is on).PhoneNumberNormalization.ToE164OrTrimmed, used by the customer store, the Contact step and the store profile, now stores the E.164 form only when it keeps everything typed; a number with an extension (x12,ext. 12,#12), a second number or a note is kept as typed.