I wanted to implement custom dynamic attribute handler class for ProductBundle
class, but it expects AbstractItemModel
type instead of my ProductBundle
:
public class BundlePriceAttributeHandler extends AbstractDynamicAttributeHandler<Double, ProductModel> {
It gives error: type argument ProductModel is not within bounds of type-variable MODEL hybris
Then I tried
<itemtype code="ProductBundle" autocreate="true" generate="true" extends="ProductModel">
<attributes>
<attribute qualifier="bundlePrice" type="java.lang.Double">
<persistence type="dynamic" attributeHandler="bundlePriceAttributeHandler"/>
</attribute>
</attributes>
</itemtype>
but, there is error YComposedType due to missing super type 'ProductModel'
(even using de.hybris.platform.core.model.product.ProductModel
)
if I try extend just "Product"
my ProductBundle
will extend just Product
jalo class not ProductModel
, and it will cause error: type argument ProductModel is not within bounds of type-variable MODEL hybris
again.
As per this error
YComposedType due to missing super type 'ProductModel' (even using de.hybris.platform.core.model.product.ProductModel)
It is saying that type ProductModel is not available, and that's correct. This platform's default itemtype name is "product," not "ProductModel".
Naming convention follows as below:
so correct entry should be as below.
<itemtype code="ProductBundle" autocreate="true" generate="true" extends="Product">
<attributes>
<attribute qualifier="bundlePrice" type="java.lang.Double">
<persistence type="dynamic" attributeHandler="bundlePriceAttributeHandler"/>
</attribute>
</attributes>
</itemtype>
and attribute handler class :
package com.customer.attributeHandler;
import com.core.model.ProductBundleModel;
import de.hybris.platform.servicelayer.model.attribute.DynamicAttributeHandler;
public class BundlePriceAttributeHandler implements DynamicAttributeHandler<Double, ProductBundleModel> {
@Override
public Double get(ProductBundleModel model) {
//Random return
return model.getAverageRating();
}
@Override
public void set(ProductBundleModel model, Double aDouble) {
}
}
Bean entry as below:
<alias name="bundlePriceAttributeHandler" alias="bundlePriceAttributeHandler"/>
<bean class="com.customer.attributeHandler.BundlePriceAttributeHandler" id="bundlePriceAttributeHandler"/>