Override OrderLineItem label after a customer ordered

Hi there,

I’m trying to override the label or description of an order line item, after a customer placed an order. To do so, I tried to listen to the order.written-event. The event handling looks like this (simplified):

// This is the event-handler
public function onOrderWritten(EntityWrittenEvent $event)
    foreach ($event->getWriteResults() as $result) {
        $orderId = $result->getPrimaryKey();

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('orderId', $orderId));

        $data = $this->orderLineItemRepository->search($criteria, $context);

        $updates = [];
        foreach ($data->getEntities() as $lineItem) {
            $updates[] = [
                'id' => $lineItem->getId(),
                'label' => $lineItem->getLabel() . ' <some more info>',

        if (!empty($updates)) {
            $this->orderLineItemRepository->update($updates, $context);

This runs into an endless loop, I think, this might be, because the order.written-event is called everytime, I update the line item. So it triggers a recursion… Is there another way on how to override the line items?

And, for general understanding: Is there anything like an EntityManager, like the one from Symfony/Doctrine? Or do I always have to look for the correct keys in the entity-table inside the db, to update values on an entity?

Thanks in advance :slight_smile: