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 Book IDs are assigned to catalog views in Commerce Optimizer and allow you to deliver personalized pricing based on customer segments, contracts, or other business rules.
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 a Price Book ID is assigned to the catalog view in Adobe Commerce Optimizer.
- 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 Price Book ID is correctly configured for the catalog view in Adobe Commerce Optimizer.
- 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:
- The Auth drop-in emits the
auth/adobe-commerce-optimizerevent when a customer logs in. - The event includes the Price Book ID from Adobe Commerce Optimizer for the authenticated customer.
- The
setAdobeCommerceOptimizerHeaderfunction adds theAC-Price-Book-IDheader to all GraphQL requests. - Adobe Commerce uses this header to return pricing specific to the Price Book associated with the catalog view.