Order post content change event handler.

@param OrderEvent $event
501778
public function onPostContentChange(OrderEvent $event)
    {
        $order = $event->getOrder();
        if ($order->getType() == OrderTypes::TYPE_CART) {
            $this->provider->setCart($order);
        }
    }
38119
public function onStateChange(OrderEvent $event)
    {
        $order = $event->getOrder();

        // If new state is Accepted or Completed and type is not order
        if (in_array($order->getState(), [OrderStates::STATE_ACCEPTED, OrderStates::STATE_COMPLETED])
            && $order->getType() != OrderTypes::TYPE_ORDER
        ) {
            // Transform to an order
            $order
                ->setType(OrderTypes::TYPE_ORDER)
                ->setCreatedAt(new \DateTime())
                ->setNumber(null)
                ->setKey(null)
            ;

            $this->generateNumberAndKey($order);
            $this->handleAddresses($order);

            $errorList = $this->validator->validate($order, ['Default', 'Order']);
            if ($errorList->count() > 0) {
                $messages = [];
                foreach ($errorList as $error) {
                    $messages[] = $error->getMessage();
                }
                throw new OrderException('Invalid order : ' . implode('<br>', $messages));
            }
        }

        // Set completed at
        if ($order->getState() === OrderStates::STATE_COMPLETED && null === $order->getCompletedAt()) {
            $order->setCompletedAt(new \DateTime());
        }
    }
10071
public function beforeRender(Event $event)
    {

        parent::beforeRender($event);

        // when a shop order was placed, the pdfs that are rendered for the order confirmation email
        // called this method and therefore called resetOriginalLoggedCustomer() => email was sent t
        // the user who placed the order for a member and not to the member
        if ($this->getResponse()->getType() != 'text/html') {
            return;
        }

        $this->resetOriginalLoggedCustomer();

        $categoriesForMenu = [];
        if (Configure::read('appDb.FCS_SHOW_PRODUCTS_FOR_GUESTS') || $this->AppAuth->user()) {
            $this->Category = TableRegistry::getTableLocator()->get('Categories');
            $allProductsCount = $this->Category->getProductsByCategoryId(Configure::read('app.categoryAllProducts'), false, '', 0, true);
            $newProductsCount = $this->Category->getProductsByCategoryId(Configure::read('app.categoryAllProducts'), true, '', 0, true);
            $categoriesForMenu = $this->Category->getForMenu();
            array_unshift($categoriesForMenu, [
                'slug' => Configure::read('app.slugHelper')->getNewProducts(),
                'name' => __('New_products') . ' <span class="additional-info"> (' . $newProductsCount . ')</span>',
                'options' => [
                    'fa-icon' => 'fa-star' . ($newProductsCount > 0 ? ' gold' : '')
                ]
            ]);
            array_unshift($categoriesForMenu, [
                'slug' => Configure::read('app.slugHelper')->getAllProducts(),
                'name' => __('All_products') . ' <span class="additional-info"> (' . $allProductsCount . ')</span>',
                'options' => [
                    'fa-icon' => 'fa-tags'
                ]
            ]);
        }
        $this->set('categoriesForMenu', $categoriesForMenu);

        $this->Manufacturer = TableRegistry::getTableLocator()->get('Manufacturers');
        $manufacturersForMenu = $this->Manufacturer->getForMenu($this->AppAuth);
        $this->set('manufacturersForMenu', $manufacturersForMenu);

        $this->Page = TableRegistry::getTableLocator()->get('Pages');
        $conditions = [];
        $conditions['Pages.active'] = APP_ON;
        $conditions[] = 'Pages.position > 0';
        if (! $this->AppAuth->user()) {
            $conditions['Pages.is_private'] = APP_OFF;
        }

        $pages = $this->Page->getThreaded($conditions);
        $pagesForHeader = [];
        $pagesForFooter = [];
        foreach ($pages as $page) {
            if ($page->menu_type == 'header') {
                $pagesForHeader[] = $page;
            }
            if ($page->menu_type == 'footer') {
                $pagesForFooter[] = $page;
            }
        }
        $this->set('pagesForHeader', $pagesForHeader);
        $this->set('pagesForFooter', $pagesForFooter);
    }
975075
public function afterSave(Event $event, Entity $entity): void
    {
        $fields = array_merge([
            $this->_table->getPrimaryKey(),
            $this->getConfig('sortField'),
        ], $this->getConfig('columnScope'));
        $savedEntity = $this->_table->get($entity->get($this->_table->getPrimaryKey()), [
            'fields' => $fields,
        ]);
        $scope = $this->getConfig('scope');

        foreach ($this->getConfig('columnScope') as $column) {
            $scope[$column] = $savedEntity->get($column);
        }
        $entitySort = $savedEntity->{$this->getConfig('sortField')};
        $entityId = $entity->get($this->_table->getPrimaryKey());

        if (empty($entitySort)) {
            $nextSortValue = $this->getNextSortValue($scope);
            $this->_table->updateAll([
                $this->getConfig('sortField') => $nextSortValue,
            ], [
                $this->_table->getPrimaryKey() => $entityId,
            ]);
        } else {
            if ($entitySort < $this->__originalSortValue) {
                $currentScope = $scope;
                $currentScope[] = "{$this->getConfig('sortField')} <" . $this->__originalSortValue;
                $currentScope[] = "{$this->getConfig('sortField')} >=" . $entitySort;
                $currentScope[] = [
                    $this->_table->getPrimaryKey() . ' !=' => $entity->id,
                ];

                $query = $this->_table->query()->update();
                $query->where($currentScope);
                $query->set([
                    $this->getConfig('sortField') => $query->newExpr($this->getConfig('sortField') . ' + 1'),
                ]);
                $query->execute();
            } elseif ($entitySort > $this->__originalSortValue) {
                $currentScope = $scope;
                $currentScope[] = "{$this->getConfig('sortField')} >" . $this->__originalSortValue;
                $currentScope[] = "{$this->getConfig('sortField')} <=" . $entitySort;
                $currentScope[] = [
                    $this->_table->getPrimaryKey() . ' !=' => $entity->id,
                ];

                $query = $this->_table->query()->update();
                $query->where($currentScope);
                $query->set([
                    $this->getConfig('sortField') => $query->newExpr($this->getConfig('sortField') . ' - 1'),
                ]);
                $query->execute();
            } elseif ($entitySort == $this->__originalSortValue) {
                $currentScope = $scope;
                $currentScope[] = "{$this->getConfig('sortField')} >=" . $entitySort;
                $currentScope[] = [
                    $this->_table->getPrimaryKey() . ' !=' => $entity->id,
                ];

                $query = $this->_table->query()->update();
                $query->where($currentScope);
                $query->set([
                    $this->getConfig('sortField') => $query->newExpr($this->getConfig('sortField') . ' + 1'),
                ]);
                $query->execute();
            }
        }
        $this->__originalSortValue = null;
    }
982751
public function orderCartClear(/** @noinspection PhpUnusedParameterInspection */ OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        // Empty cart and clear current order
        $session = $this->getSession();

        $session->clearSessionCart($dispatcher);

        $session->setOrder(new OrderModel());
    }
526612
public function sendConfirmationEmail(OrderEvent $event)
    {
        $this->mailer->sendEmailToCustomer(
            'order_confirmation',
            $event->getOrder()->getCustomer(),
            [
                'order_id' => $event->getOrder()->getId(),
                'order_ref' => $event->getOrder()->getRef()
            ]
        );
    }
1310731
public function persistPageDataOnReorder(ReorderEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticlePageDocument) {
            return;
        }

        $document = $document->getParent();
        $node = $this->documentInspector->getNode($document);

        $this->setPageData($document, $node, $document->getLocale());

        $document->setWorkflowStage(WorkflowStage::TEST);
        $this->documentManager->persist($document, $this->documentInspector->getLocale($document));

        $this->documents[$document->getUuid()] = [
            'uuid' => $document->getUuid(),
            'locale' => $document->getLocale(),
        ];
    }
676570
public function updatePosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $this->genericUpdatePosition(OrderStatusQuery::create(), $event, $dispatcher);
    }
1361743
public static function onFlushContent(Event $event)
    {
        if (null === self::getEntityManager($event)) {
            return;
        }

        $contents_inserted = ScheduledEntities::getScheduledAClassContentInsertions(self::$em, true, true);
        $contents_updated = ScheduledEntities::getScheduledAClassContentUpdates(self::$em, true, true);
        $contents_deleted = ScheduledEntities::getSchedulesAClassContentDeletions(self::$em, true);

        // Updates content-content indexes
        self::updateIdxContentContents(array_merge($contents_inserted, $contents_updated), $contents_deleted);

        // Updates site-content indexes
        self::updateIdxSiteContents($contents_inserted, $contents_deleted);

        $content = $event->getTarget();
        if (!($content instanceof AbstractClassContent)) {
            return;
        }
        $dispatcher = $event->getDispatcher();
        $application = $dispatcher->getApplication();
        if (null === $application) {
            return;
        }

        $uow = self::$em->getUnitOfWork();

        if ($uow->isScheduledForInsert($content) || $uow->isScheduledForUpdate($content)) {
            self::$em->getRepository('BackBee\ClassContent\Indexes\OptContentByModified')
                    ->replaceOptContentTable($content);

            self::indexContent($content);
            self::updateSuperContentIndexes($content);
        } elseif ($uow->isScheduledForDelete($content)) {
            self::$em
                ->getRepository('BackBee\ClassContent\Indexes\OptContentByModified')
                ->removeOptContentTable($content)
            ;

            foreach ($content->getIndexation() as $index) {
                self::$em->remove($index);
                self::$em
                    ->getUnitOfWork()
                    ->computeChangeSet(self::$em->getClassMetadata('BackBee\ClassContent\Indexation'), $index)
                ;
            }
        }
    }
263072
public function onContentChange(OrderEvent $event)
    {
        $order = $event->getOrder();

        $this->calculator->updateTotals($order);
        $this->stateResolver->resolve($order, $event);
    }
1080875
public function onAfterRespond(Event $event)
    {
        /** @var ResponseInterface $response */
        $response = $event['response'];

        if (strpos($response->getHeaderLine('Content-Type'), 'html') === false) {
            DebuggerHelper::disableConsole();
        }
    }
1252659
public static function postUpdate( \Composer\Script\Event $event )
    {
        $_composer = $event->getComposer();
        $_package = $_composer->getPackage();
        // do stuff
    }
36150
public function handleReorder(ReorderEvent $event)
    {
        $document = $event->getDocument();

        if (!$document instanceof OrderBehavior) {
            return;
        }

        $parentDocument = $this->documentInspector->getParent($document);

        if (null === $parentDocument) {
            return;
        }

        $count = 1;
        foreach ($this->documentInspector->getChildren($parentDocument) as $childDocument) {
            if (!$childDocument instanceof OrderBehavior) {
                continue;
            }

            $order = $count * 10;
            $childDocument->setSuluOrder($order);

            // TODO move to NodeHelper once integrated in sulu/sulu?
            $childNode = $this->documentInspector->getNode($childDocument);
            $childNode->setProperty($this->propertyEncoder->systemName(static::FIELD), $order);

            ++$count;
        }
    }
603227
public function onPostDelete(OrderEvent $event)
    {
        $order = $event->getOrder();
        if ($order->getType() === OrderTypes::TYPE_CART) {
            $this->provider->clearCart();
        }
    }
817362
protected function isOrderLocked(OrderEvent $event)
    {
        if (!$event->getForce() && $event->getOrder()->getLocked()) {
            $event->addMessage(new ResourceMessage('ekyna_order.event.locked', ResourceMessage::TYPE_ERROR));
            return true;
        }
        return false;
    }
1086924
public function onPostSerialize(ObjectEvent $event)
    {
        /** @var RedirectTypeBehavior $document */
        $document = $event->getObject();

        if (!$document instanceof WorkflowStageBehavior) {
            return;
        }

        $visitor = $event->getVisitor();
        $visitor->addData('publishedState', WorkflowStage::PUBLISHED === $document->getWorkflowStage());
    }
1102739
public function handlePersist(PersistEvent $event)
    {
        $document = $event->getDocument();

        if (false == $document instanceof OrderBehavior) {
            return;
        }

        if ($document->getSuluOrder()) {
            return;
        }

        $node = $event->getNode();
        $parent = $node->getParent();
        $nodeCount = count($parent->getNodes());
        $order = ($nodeCount + 1) * 10;

        $document->setSuluOrder($order);
    }