Price Book ID setup
This guide shows you how to enable Adobe Commerce Optimizer (ACO) Price Book ID functionality in the Adobe Commerce boilerplate. Price Books in Commerce Optimizer allow you to deliver personalized pricing based on customer segments, contracts, or other business rules. Each catalog view defines a default Price Book and may restrict which Price Books are allowed for that view. Customers can have their own assigned Price Books, which are used if they fall within the allowed Price Books for the catalog view.
Prerequisites
Before you begin, ensure you have:
- An active Adobe Commerce Optimizer subscription.
- The storefront is configured to connect to Adobe Commerce Optimizer .
- Access to your boilerplate repository code.
- The Auth drop-in installed and configured in your storefront.
Enable Price Book ID
-
Enable Adobe Commerce Optimizer in the Auth drop-in initializer
Open the Auth drop-in initializer file at
scripts/initializers/auth.jsand add theadobeCommerceOptimizer: trueoption:// Initialize authreturn initializers.mountImmediately(initialize, {langDefinitions,adobeCommerceOptimizer: true // Enable ACO}); -
Replace the customer group header function
Open the main initializers file at
scripts/initializers/index.jsand replace thesetCustomerGroupHeaderfunction with thesetAdobeCommerceOptimizerHeaderfunction:const setAdobeCommerceOptimizerHeader = (adobeCommerceOptimizer) => {if (adobeCommerceOptimizer?.priceBookId) {CS_FETCH_GRAPHQL.setFetchGraphQlHeader('AC-Price-Book-ID', adobeCommerceOptimizer.priceBookId);} else {CS_FETCH_GRAPHQL.removeFetchGraphQlHeader('AC-Price-Book-ID');}}; -
Update the event listener
In the same
scripts/initializers/index.jsfile, replace theauth/group-uidevent listener with theauth/adobe-commerce-optimizerevent :events.on('auth/adobe-commerce-optimizer', setAdobeCommerceOptimizerHeader, { eager: true });The
{ eager: true }option ensures the event handler executes immediately if the event has already been emitted. See Event subscription options for more details. -
Test the implementation
After making these changes, verify that the Price Book ID header is being sent with GraphQL requests:
- Log in to your storefront as a customer.
- Open your browser’s developer tools and navigate to the Network tab.
- Look for GraphQL requests and verify the
AC-Price-Book-IDheader is present in the request headers.
Troubleshooting
Price Book ID header is not being sent
If the AC-Price-Book-ID header is not appearing in your GraphQL requests:
- Verify that
adobeCommerceOptimizer: trueis set in the Auth drop-in initializer. - Confirm that the catalog view has a default Price Book configured in Adobe Commerce Optimizer.
- Verify that the customer has a valid Price Book assigned (or that the default Price Book for the catalog view is configured).
- Check the browser console for any JavaScript errors that might prevent the event from firing.
Pricing is not changing
If the header is being sent but pricing remains unchanged:
- Verify that the default Price Book for the catalog view is correctly configured in Adobe Commerce Optimizer.
- If the customer has an assigned Price Book, confirm it is within the allowed Price Books for the catalog view.
- Confirm that your Adobe Commerce backend is configured to recognize and process the
AC-Price-Book-IDheader . - Check that the Price Book has active pricing rules.
How it works
When Adobe Commerce Optimizer is enabled:
- Each catalog view in Commerce Optimizer defines a default Price Book and may restrict which Price Books are allowed for that view.
- The Auth drop-in emits the
auth/adobe-commerce-optimizerevent when a customer logs in. - The event includes the Price Book ID for the authenticated customer (if the customer has an assigned Price Book).
- Adobe Commerce Optimizer validates that the Price Book for the customer is within the allowed Price Books for the catalog view. If valid, the Price Book for the customer is used. Otherwise, the default Price Book for the catalog view is used.
- The
setAdobeCommerceOptimizerHeaderfunction adds theAC-Price-Book-IDheader to all GraphQL requests. - Adobe Commerce uses this header to return pricing specific to the determined Price Book.