Customer Groups
Overview
Customer groups segment customers for pricing purposes. Each group can have multiple price lists associated with it, allowing for flexible pricing strategies.
Customer Group Structure
interface CustomerGroup {
id: string;
name: string;
description?: string;
isActive: boolean;
priceLists: Array<{
priceListId: string;
priority: number; // Lower = higher priority
}>;
createdAt: Date;
updatedAt: Date;
}
Use Cases
VIP Customers
{
"name": "VIP",
"description": "VIP customers with 20% discount",
"priceLists": [
{
"priceListId": "vip-pricing",
"priority": 1
}
]
}
Wholesale Customers
{
"name": "Wholesale",
"description": "Bulk purchase pricing",
"priceLists": [
{
"priceListId": "wholesale-pricing",
"priority": 1
}
]
}
Regular Customers
{
"name": "Regular",
"description": "Standard pricing",
"priceLists": []
}
Price List Priority
When a customer group has multiple price lists:
- Price lists are evaluated in priority order (lower number = higher priority)
- First matching override wins
- If no override found, check next price list
- If no price lists match, use base price
Assigning Customers to Groups
Customers are assigned to groups via the customers table:
ALTER TABLE customers
ADD COLUMN customer_group_id UUID REFERENCES customer_groups(id);
Pricing Resolution Flow
API Endpoints
GET /admin/pricing/customer-groups- List all customer groupsPOST /admin/pricing/customer-groups- Create customer groupGET /admin/pricing/customer-groups/:id- Get customer groupPATCH /admin/pricing/customer-groups/:id- Update customer groupDELETE /admin/pricing/customer-groups/:id- Delete customer groupPOST /admin/pricing/customer-groups/:id/price-lists- Add price list to groupDELETE /admin/pricing/customer-groups/:id/price-lists/:priceListId- Remove price list from group
Creating a Customer Group
POST /admin/pricing/customer-groups
Content-Type: application/json
{
"name": "VIP",
"description": "VIP customers",
"isActive": true,
"priceLists": [
{
"priceListId": "vip-pricing-id",
"priority": 1
}
]
}
Assigning Price Lists
Add a price list to a customer group:
POST /admin/pricing/customer-groups/:groupId/price-lists
Content-Type: application/json
{
"priceListId": "price-list-id",
"priority": 1
}
Default Group
Customers without an assigned group use base prices (no price list overrides).
Caching
Customer groups are cached in Redis:
- Cache Key:
pricing:customer-group:{id} - TTL: 1 hour
- Invalidation: On group create/update/delete
Best Practices
- Clear Naming: Use descriptive names (VIP, Wholesale, Regular)
- Consistent Priorities: Use standard priority values (1, 10, 100)
- Test Pricing: Verify price calculations for each group
- Monitor Usage: Track which groups are most used
- Document Rules: Document pricing rules for each group
Edge Cases
- No Group: Customer uses base prices
- Inactive Group: Treated as no group
- Empty Price Lists: Uses base prices
- All Price Lists Inactive: Uses base prices
- No Matching Overrides: Uses base prices