Supplier/EventListener/SupplierOrderListener.php
public function onUpdate(ResourceEventInterface $event)
    {
        $order = $this->getSupplierOrderFromEvent($event);

        $changed = $this->updateNumber($order);

        $changed |= $this->updateState($order);

        $changed |= $this->updateTotals($order);

        $changed |= $this->updateExchangeRate($order);

        if ($changed) {
            $this->persistenceHelper->persistAndRecompute($order);
        }

        // Deletable <=> Stockable state change case.
        if ($this->persistenceHelper->isChanged($order, 'state')) {
            $stateCs = $this->persistenceHelper->getChangeSet($order, 'state');

            // If order's state has changed to a non stockable state
            if (SupplierOrderStates::hasChangedFromStockable($stateCs)) {
                // Delete stock unit (if exists) for each supplier order items.
                foreach ($order->getItems() as $item) {
                    $this->stockUnitLinker->unlinkItem($item);
                    //$this->deleteSupplierOrderItemStockUnit($item);
                }
            } // Else if order state's has changed to a stockable state
            elseif (SupplierOrderStates::hasChangedToStockable($stateCs)) {
                // Create stock unit (if not exists) for each supplier order items.
                foreach ($order->getItems() as $item) {
                    $this->stockUnitLinker->linkItem($item);
                    //$this->createSupplierOrderItemStockUnit($item);
                }
            }
        }

        // If order's estimated date of arrival has changed and order's state is stockable
        if (
            $this->persistenceHelper->isChanged($order, 'estimatedDateOfArrival')
            && SupplierOrderStates::isStockableState($order->getState())
        ) {
            // Update stock units estimated date of arrival
            foreach ($order->getItems() as $item) {
                if (!$item->hasSubjectIdentity()) {
                    continue;
                }

                if (null === $stockUnit = $item->getStockUnit()) {
                    throw new RuntimeException("Failed to retrieve stock unit.");
                }

                $this->stockUnitUpdater->updateEstimatedDateOfArrival($stockUnit, $order->getEstimatedDateOfArrival());
            }
        }
    }
public function onUpdate(ResourceEventInterface $event)
    {
        $order = $this->getSupplierOrderFromEvent($event);

        $changed = $this->updateNumber($order);

        $changed |= $this->updateState($order);

        $changed |= $this->updateTotals($order);

        $changed |= $this->updateExchangeRate($order);

        if ($changed) {
            $this->persistenceHelper->persistAndRecompute($order);
        }

        // Deletable <=> Stockable state change case.
        if ($this->persistenceHelper->isChanged($order, 'state')) {
            $stateCs = $this->persistenceHelper->getChangeSet($order, 'state');

            // If order's state has changed to a non stockable state
            if (SupplierOrderStates::hasChangedFromStockable($stateCs)) {
                // Delete stock unit (if exists) for each supplier order items.
                foreach ($order->getItems() as $item) {
                    $this->stockUnitLinker->unlinkItem($item);
                    //$this->deleteSupplierOrderItemStockUnit($item);
                }
            } // Else if order state's has changed to a stockable state
            elseif (SupplierOrderStates::hasChangedToStockable($stateCs)) {
                // Create stock unit (if not exists) for each supplier order items.
                foreach ($order->getItems() as $item) {
                    $this->stockUnitLinker->linkItem($item);
                    //$this->createSupplierOrderItemStockUnit($item);
                }
            }
        }

        // If order's estimated date of arrival has changed and order's state is stockable
        if (
            $this->persistenceHelper->isChanged($order, 'estimatedDateOfArrival')
            && SupplierOrderStates::isStockableState($order->getState())
        ) {
            // Update stock units estimated date of arrival
            foreach ($order->getItems() as $item) {
                if (!$item->hasSubjectIdentity()) {
                    continue;
                }

                if (null === $stockUnit = $item->getStockUnit()) {
                    throw new RuntimeException("Failed to retrieve stock unit.");
                }

                $this->stockUnitUpdater->updateEstimatedDateOfArrival($stockUnit, $order->getEstimatedDateOfArrival());
            }
        }
    }
public function onUpdate ( ResourceEventInterface $ event ) { $ order = $ this -> getSupplierOrderFromEvent ( $ event ) ; $ changed = $ this -> updateNumber ( $ order ) ; $ changed |= $ this -> updateState ( $ order ) ; $ changed |= $ this -> updateTotals ( $ order ) ; $ changed |= $ this -> updateExchangeRate ( $ order ) ; if ( $ changed ) { $ this -> persistenceHelper -> persistAndRecompute ( $ order ) ; } // Deletable <=> Stockable state change case. if ( $ this -> persistenceHelper -> isChanged ( $ order , 'state' ) ) { $ stateCs = $ this -> persistenceHelper -> getChangeSet ( $ order , 'state' ) ; // If order's state has changed to a non stockable state if ( SupplierOrderStates :: hasChangedFromStockable ( $ stateCs ) ) { // Delete stock unit (if exists) for each supplier order items. foreach ( $ order -> getItems ( ) as $ item ) { $ this -> stockUnitLinker -> unlinkItem ( $ item ) ; //$this->deleteSupplierOrderItemStockUnit($item); } } // Else if order state's has changed to a stockable state elseif ( SupplierOrderStates :: hasChangedToStockable ( $ stateCs ) ) { // Create stock unit (if not exists) for each supplier order items. foreach ( $ order -> getItems ( ) as $ item ) { $ this -> stockUnitLinker -> linkItem ( $ item ) ; //$this->createSupplierOrderItemStockUnit($item); } } } // If order's estimated date of arrival has changed and order's state is stockable if ( $ this -> persistenceHelper -> isChanged ( $ order , 'estimatedDateOfArrival' ) && SupplierOrderStates :: isStockableState ( $ order -> getState ( ) ) ) { // Update stock units estimated date of arrival foreach ( $ order -> getItems ( ) as $ item ) { if ( ! $ item -> hasSubjectIdentity ( ) ) { continue ; } if ( null === $ stockUnit = $ item -> getStockUnit ( ) ) { throw new RuntimeException ( "Failed to retrieve stock unit." ) ; } $ this -> stockUnitUpdater -> updateEstimatedDateOfArrival ( $ stockUnit , $ order -> getEstimatedDateOfArrival ( ) ) ; } } }
Update event handler.

@param ResourceEventInterface $event
Update event handler .