Hybris Tip 5 – Adding new populator for productData as product options.

0 Comments

There is a list of options to populate product data. We might see the list of configurations below:

<alias name="defaultProductConfiguredPopulator" alias="productConfiguredPopulator"/>
    <bean id="defaultProductConfiguredPopulator" class="de.hybris.platform.commercefacades.converter.impl.DefaultConfigurablePopulator">
        <property name="populators">
            <map key-type="de.hybris.platform.commercefacades.product.ProductOption">
                <entry key="BASIC" value-ref="productBasicPopulatorList"/>
                <entry key="PRICE" value-ref="productPricePopulatorList"/>
                <entry key="PRICE_RANGE" value-ref="productPriceRangePopulator"/>
                <entry key="VOLUME_PRICES" value-ref="productVolumePricesPopulator"/>
                <entry key="GALLERY" value-ref="productGalleryPopulatorList"/>
                <entry key="SUMMARY" value-ref="productSummaryPopulatorList"/>
                <entry key="DESCRIPTION" value-ref="productDescriptionPopulatorList"/>
                <entry key="CATEGORIES" value-ref="productCategoriesPopulatorList"/>
                <entry key="PROMOTIONS" value-ref="productPromotionsPopulatorList"/>
                <entry key="STOCK" value-ref="productStockPopulatorList"/>
                <entry key="REVIEW" value-ref="productReviewPopulatorList"/>
                <entry key="CLASSIFICATION" value-ref="productClassificationPopulatorList"/>
                <entry key="VARIANT_FULL" value-ref="productVariantFullPopulatorList"/>
                <entry key="REFERENCES" value-ref="productReferencesPopulator"/>
                <entry key="DELIVERY_MODE_AVAILABILITY" value-ref="productDeliveryModeAvailabilityPopulator"/>
            </map>
        </property>
    </bean>

Each option has a corresponding populator, and they will populate product data in order.

If we want to create a new populator to populate some new attributes for product data, like specifications, we will do the following steps:

  1. Create a new enum for product option. Ex: SPECIFICATIONS
  2. Create a new populator: Ex: productSpecificationPopulator
  3. In the trainingfacades-spring.xml file, register the new product option in the productConfiguredPopulator as follows:
<bean parent="configurablePopulatorModification">
		<property name="target" ref="productConfiguredPopulator" />
		<property name="keyType" value="de.hybris.platform.commercefacades.product.ProductOption" />
		<property name="key" value="SPECIFICATIONS" />
		<property name="add" ref="productSpecificationPopulator" />
	</bean>

Now, the new product populator option is ready to use.

Example: In the ProductPageController.java file, update the productData by adding a new option into the list of product options.

final List<ProductOption> extraOptions = Arrays.asList(ProductOption.VARIANT_MATRIX_BASE, ProductOption.VARIANT_MATRIX_URL, ProductOption.VARIANT_MATRIX_MEDIA, ProductOption.SPECIFICATIONS);

final ProductData productData = productFacade.getProductForCodeAndOptions(productCode, extraOptions);

NOTE: I assume you could create the attributes related to specifications in the ProductData and ProductModel.

Leave a comment, if you have any questions.

Happy coding.!!!


Leave a Reply

Your email address will not be published. Required fields are marked *