Extending Product in Spartacus /How to add custom attribute in Product in SAP Spartacus?
In this example, I will add manufacturAid attribute which does not exist in OOB ProductData/ProductWSDTO class
A. Update Your XXXXws-beans.xml file to add below entries.
1. Add bean definition to add additional field on OOB ProductData
<bean class="de.hybris.platform.commercefacades.product.data.ProductData">
<property name="manufacturerAid" type="java.lang.String">
<description>MFG Part#</description>
</property>
</bean>
2. Add bean definition to add additional field on OOB ProductWsDTO<bean class="de.hybris.platform.commercewebservicescommons.dto.product.ProductWsDTO" >
<property name="manufacturerAid" type="java.lang.String">
<description>MFG Part#</description>
</property>
</bean>B. update field mapping in dto-level-mappings-v2-spring.xml file<bean parent="fieldSetLevelMapping" id="productWsDTOFieldSetLevelMapping">
<property name="dtoClass"
value="de.hybris.platform.commercewebservicescommons.dto.product.ProductWsDTO"/>
<property name="levelMapping">
<map>
<entry key="BASIC"
value="purchasable,stock,name,baseProduct,availableForPickup,code,url,price"/>
<entry key="DEFAULT"
value="summary,averageRating,purchasable,stock(DEFAULT),description,variantMatrix(DEFAULT),name,baseOptions(DEFAULT),baseProduct,availableForPickup,variantOptions(DEFAULT),code,url,price(DEFAULT),numberOfReviews,manufacturer,categories(BASIC,name),priceRange,multidimensional,configuratorType,configurable,tags,manufacturerAid"/>
<entry key="FULL"
value="summary,productReferences(FULL),classifications(FULL),averageRating,purchasable,volumePrices(FULL),variantType,stock(FULL),description,variantMatrix(FULL),name,baseOptions(FULL),baseProduct,availableForPickup,variantOptions(FULL),reviews(FULL),code,url,price(FULL),numberOfReviews,manufacturer,volumePricesFlag,futureStocks(FULL),images(FULL),categories(FULL),potentialPromotions(FULL),priceRange,multidimensional,configuratorType,configurable,tags,manufacturerAid"/>
</map>
</property>
</bean>C. create custom populator to populate manufacturerAid Field.here we are extending OOB ProductPopulatorpackage com.bdi.test.facades.populator;
import de.hybris.platform.commercefacades.product.converters.populator.ProductPopulator;
import de.hybris.platform.commercefacades.product.data.ProductData;
import de.hybris.platform.core.model.product.ProductModel;
import javax.annotation.Resource;
public class TestWSProductPopulator extends ProductPopulator {
@Override
public void populate(final ProductModel source, final ProductData target)
{
super.populate(source, target);
target.setManufacturerAid("Test-MFGID");
}
}D. override OOB Product populator to use custom populator.This change needs to add in xxxws-spring.xml file.<alias name="bdiWSProductPopulator" alias="productPopulator"/>
<bean id="bdiWSProductPopulator" class="com.bdi.newexpress.facades.populator.TestWSProductPopulator"
parent="defaultProductPopulator">
</bean>
Comments
Post a Comment