Orchardcore customers

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore customers is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for the CrestApps Orchard Core Customers module (CrestApps.OrchardCore.Customers, Customers.CheckoutDetails, Customers.StoreCredit, Customers.Loyalty, Customers.Referrals, Customers.Api) and the Customers.Abstractions buyer identity foundation. Covers the Customer record linked to a user or a

How to use this skill

Skill file

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:

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):

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

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.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.