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 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:

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

How it works

When Adobe Commerce Optimizer is enabled:

  1. The Auth drop-in emits the auth/adobe-commerce-optimizer event when a customer logs in.
  2. The event includes the Price Book ID from Adobe Commerce Optimizer for the authenticated customer.
  3. The setAdobeCommerceOptimizerHeader function adds the AC-Price-Book-ID header to all GraphQL requests.
  4. Adobe Commerce uses this header to return pricing specific to the Price Book associated with the catalog view.

Additional resources