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

  1. Order orderItem = modelService.getSource(orderModel);
Order orderItem = modelService.getSource(orderModel);


Where,
orderModelinstance of OrderModel
modelServiceinjected in the class
orderItemreturned 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

  1. OrderModel orderModel = modelService.get(order);
OrderModel orderModel = modelService.get(order);


Where,
orderjalo object
modelServiceinjected in the class
orderModelreturned instance of OrderModel

In the same way we can get cartModel using cart jalo as

  1. 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

About the Author

Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on