Another day another funny story. I updated a plugin from 6.4 to 6.5 and one of the requirement was to update the backend view on order save.
First try: this.$root.$on
On the sw-order-detail plugin the onSaveEdits method emits an event on the root node. Many events on the shopware administration are emitted on the component itself, that means you need to access the component to register a subscriber to do anything.
This looks for example like this:
this.$emit('save-edits');
But as already said, in our case we have the luck, that the event is dispatched on the root component:
this.$root.$emit('order-edit-save');
To register a subscriber, you call $on(event, function) method on the component and as already explained, in this case on the root component:
This happens, because the Promise of this.orderRepository.save is evaluated after the AJAX call is done – and this happens maybe before, maybe after the $emit.
State.watch
Looking into the onSaveEdits, another idea was to listen on the commit. Thanks to free ChatGPT 3.5 I fiddled out, how this can work. This is how my subscriber looks like: