Skip to content

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:

Enable Price Book ID

  1. Enable Adobe Commerce Optimizer in the Auth drop-in initializer

    Open the Auth drop-in initializer file at scripts/initializers/auth.js and add the adobeCommerceOptimizer: true option:

    // Initialize auth
    return initializers.mountImmediately(initialize, {
    langDefinitions,
    adobeCommerceOptimizer: true // Enable ACO
    });
  2. Replace the customer group header function

    Open the main initializers file at scripts/initializers/index.js and replace the setCustomerGroupHeader function with the setAdobeCommerceOptimizerHeader function:

    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');
    }
    };
  3. Update the event listener

    In the same scripts/initializers/index.js file, replace the auth/group-uid event listener with the auth/adobe-commerce-optimizer event :

    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.

  4. 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-ID header 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: true is 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-ID header .
  • Check that the Price Book has active pricing rules.

How it works

When Adobe Commerce Optimizer is enabled:

  1. Each catalog view in Commerce Optimizer defines a default Price Book and may restrict which Price Books are allowed for that view.
  2. The Auth drop-in emits the auth/adobe-commerce-optimizer event when a customer logs in.
  3. The event includes the Price Book ID for the authenticated customer (if the customer has an assigned Price Book).
  4. 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.
  5. The setAdobeCommerceOptimizerHeader function adds the AC-Price-Book-ID header to all GraphQL requests.
  6. Adobe Commerce uses this header to return pricing specific to the determined Price Book.

Additional resources