0

I'm working in a Hybris Commerce custom project and this is my case:

1 - I have an Interceptor for AddressModel, it's run when I do insert or Update.

2 - I have to change the Order.Status value when I update a value in Address.

If someone knows how to get de OrderModel from Address to set a value it will be nice!

www.hybriscx.com
  • 1,129
  • 4
  • 22

2 Answers2

1

In your address interceptor, take the hold of the OrderModel and use model service to save your order model object.

Something like modelService.save(order);

You can get the handle of owner order from address model by addressModel.getOwner() if Order is owner of the address. Else you may choose to load it from database by using flexibleSearch.getModelByExample or firing up a custom flexible query.

hope it helps!

Note : Hybris saves Order into Addeess as Owner during order creation. Hence order can be fetched from calling orderModel.getOwner() on delivery or payment address of an order.

www.hybriscx.com
  • 1,129
  • 4
  • 22
0

My solution was..

 OrderModel orderModel = (OrderModel) addressModel.getOwner();

Casting you can get de full object and to change the status. I save it after set my value, using model service:

orderModel.setValue(true);
modelService.save(orderModel);

Thanks guys!

  • 3
    of-course you need to cast it because `Owner` attribute at its definition can accept any `ItemModel`. Don't see any different from the answer given above. Anyways... Good Luck! – www.hybriscx.com Nov 16 '19 at 02:03
  • 2
    If none of the answers worked for you and you got a different solution then you can always answer your question and mark it accepted. But in this case, @hybriscx has already answered it. – HybrisHelp Nov 18 '19 at 04:37