How to convert model to jalo item and vice versa
In Hybris, sometimes its required to access jalo item from the model and sometime it is required to access model from the jalo item.
Example : Getting Order jalo item from OrderModel or getting OrderModel from Order jalo.
How to access jalo item from Model object ?
To get jalo item from Model object, we just need to call getSource() method of ModelService as below
- Order orderItem = modelService.getSource(orderModel);
Order orderItem = modelService.getSource(orderModel);
Where,
orderModel – instance of OrderModel
modelService – injected in the class
orderItem – returned jalo item
How to access Model object from Jalo object ?
To get Model object from Jalo object, we just need to call get() method of ModelService as below
- OrderModel orderModel = modelService.get(order);
OrderModel orderModel = modelService.get(order);
Where,
order – jalo object
modelService – injected in the class
orderModel – returned instance of OrderModel
In the same way we can get cartModel using cart jalo as
- final CartModel cartModel = modelService.get(cart);
final CartModel cartModel = modelService.get(cart);
Note :
This is very important to know as sometime in our logic, its required to do this model to jalo conversion and vice-versa
Hi, Thank you for your article. We are using this in our project. But in which scenario do we need this. What are we acheiving with this.