Stock/EventListener/AbstractStockUnitListener.php
public function onDelete(ResourceEventInterface $event)
    {
        $stockUnit = $this->getStockUnitFromEvent($event);

        if (null !== $item = $stockUnit->getSupplierOrderItem()) {
            // Prevent deletion if the supplier order has a stockable state
            if (SupplierOrderStates::isStockableState($item->getOrder()->getState())) {
                throw new IllegalOperationException(
                    "The stock unit can't be deleted as it is linked to a supplier order with a stockable state."
                ); // TODO message as translation id
            }
        }

        if (!$stockUnit->isEmpty()) {
            throw new IllegalOperationException(
                "The stock unit can't be deleted as it has been received, adjusted, sold or shipped."
            ); // TODO message as translation id
        }

        $this->scheduleSubjectStockUnitChangeEvent($stockUnit);
    }
public function onDelete(ResourceEventInterface $event)
    {
        $stockUnit = $this->getStockUnitFromEvent($event);

        if (null !== $item = $stockUnit->getSupplierOrderItem()) {
            // Prevent deletion if the supplier order has a stockable state
            if (SupplierOrderStates::isStockableState($item->getOrder()->getState())) {
                throw new IllegalOperationException(
                    "The stock unit can't be deleted as it is linked to a supplier order with a stockable state."
                ); // TODO message as translation id
            }
        }

        if (!$stockUnit->isEmpty()) {
            throw new IllegalOperationException(
                "The stock unit can't be deleted as it has been received, adjusted, sold or shipped."
            ); // TODO message as translation id
        }

        $this->scheduleSubjectStockUnitChangeEvent($stockUnit);
    }
Delete event handler.

@param ResourceEventInterface $event

@throws IllegalOperationException