Dynamic buyer group assignment with the Buyer Group extension
Key Takeaway
To assign buyer groups at runtime, extend CommerceBuyGrp.BuyerGroupEvaluationService and override getBuyerGroupIds to return the appropriate buyer group IDs.
Buyer groups decide what a shopper sees in a B2B store, such as products, prices and promotions. The Buyer Group extension lets a developer write custom Apex that decides which buyer groups a shopper belongs to while they browse. Shoppers get personalized experiences without anyone assigning them by hand.
What the extension does and where it works
Out of the box, buyer group membership is limited to account-based, market-based or data segment-based buyer groups. The Buyer Group extension lets you add your own business rules, so you don't have to rely only on fixed membership.
Your custom Apex runs each time a shopper visits a page in the store and assigns them to buyer groups based on your criteria. Product visibility, pricing and promotions are then targeted to that shopper right away, with no manual intervention.
A parts store wants members of its loyalty program to see loyalty prices. A developer writes that rule in custom Apex. When Dana, a loyalty member, opens a product page, the Apex runs and assigns her to the loyalty buyer group. Dana sees the loyalty prices right away, and nobody had to assign her by hand.
The extension works for both guest and authenticated (logged-in) shoppers.
Store support is limited. The extension works for B2B stores and for D2C stores with custom checkout enabled. The extension is not available for stores using managed checkout, so a D2C store on managed checkout must move to custom checkout first.