PDP initialization
Customizing the product details page (PDP) drop-in component initializers can help you meet your project requirements and use cases.
Configuration options
The PDP drop-in component initializers allow you to define the language definitions, default locale, and models that your project will use.
Example
The following code shows the default implementation of the PDP drop-in component initializer in the Commerce boilerplate:
// Define the models object with a ProductDetails propertyconst models = { ProductDetails: { initialData: { ...product }, },};
// Initialize drop-in componentsinitializers.mountImmediately(initialize, { langDefinitions, models,});
Scope Configuration
The scope
option enables scoped contexts for the PDP drop-in. When provided, the component runs in an isolated context. This allows multiple independent PDP instances on the same page without conflicts.
Use cases for scoped PDP initialization:
- Product Comparison: Initialize multiple PDP instances for side-by-side product comparison
- Quick View: Initialize PDP instances for modal or overlay product previews
Example
The following example demonstrates how to initialize multiple scoped PDP instances:
// Initialize PDPinitializers.mountImmediately(initialize, { sku: 'SKU-001', langDefinitions,});
// Initialize PDP with different scopeinitializers.mountImmediately(initialize, { sku: 'SKU-002', langDefinitions, scope: 'modal',});
Set default product options
When a user navigates to the product detail page (PDP) on your site, you can set certain options as preselected defaults for complex products. This use case allows merchandisers to set default options through the Adobe Commerce Admin, which provides a more customized and streamlined shopping experience.
Default option selection is not supported out-of-the-box for complex products. Instead, you must use product attributes and customize the PDP drop-in component initializers to define which attribute and value is used by default.
-
Log in to the Adobe Commerce Admin.
-
Create a custom attribute (
default_options
) to define default options for each product. -
Ensure that the
default_options
attribute has been exported to the Catalog Service and that the attribute’sroles
field includesvisible_in_pdp
. See theProductViewAttribute
type documentation for details. -
Use the
products
query to find theid
of thedefault_options
attribute for each product. -
Add the
id
of thedefault_options
attribute to theinitialData
object for each complex product. -
Use the
id
to set theoptionsUIDs
in theinitialData
object.// Define the models object with a ProductDetails propertyconst models = {ProductDetails: {initialData: {...initialData,// Set the optionsUIDs for each productoptionsUIDs: ['<id>', // Use the id of the default_options attribute for product 1'<id>', // Use the id of the default_options attribute for product 2],},},};// Register Initializersinitializers.mountImmediately(initialize, {langDefinitions,models,});