Rachit
Rachit

Reputation: 403

Use of proper interceptor logic in Hybris

I have a products.impex file with an attribute gender=MALE or FEMALE in the itemtype MyProduct(which extends Product) I have an attribute "choice" which depends on the values in the gender column so I initially wrote a PrepareInterceptor and checked for isNew condition.Now it works fine for the new rows but when the value is changed it does not work.Should I just remove the isNew condition or use InitDefaultsInterceptor?

Upvotes: 0

Views: 1822

Answers (1)

HybrisHelp
HybrisHelp

Reputation: 5810

if (ctx.isRemoved(productModel))
{
    //TODO
}
else if (ctx.isNew(productModel) || ctx.isModified(productModel, ProductModel.GENDER))
{
    //TODO
}

As far as interceptor concern, you can use PrepareInterceptor for preparing fields value as it called before ValidateInterceptor. If you just want to validate your fields then use ValidateInterceptor. The Init Defaults Interceptor is called when a model is filled with its default values.

Have a look at interceptor life cycle.

Upvotes: 1

Related Questions