custom/static-plugins/K3nExtendVioRepresentativeLogin/src/Subscriber/AccountOrderPageSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. namespace K3nExtendVioRepresentativeLogin\Subscriber;
  3. use Shopware\Core\Checkout\Order\OrderEntity;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Storefront\Page\Account\Order\AccountOrderPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  9. class AccountOrderPageSubscriber implements EventSubscriberInterface
  10. {
  11.     private EntityRepositoryInterface $stateMachineTransitionRepository;
  12.     public function __construct(EntityRepositoryInterface $stateMachineTransitionRepository)
  13.     {
  14.         $this->stateMachineTransitionRepository $stateMachineTransitionRepository;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             AccountOrderPageLoadedEvent::class => 'onAccountOrderDetailPageLoaded'
  20.         ];
  21.     }
  22.     public function onAccountOrderDetailPageLoaded(AccountOrderPageLoadedEvent $event): void
  23.     {
  24.         $orders $event->getPage()->getOrders()->getEntities();
  25.         $context $event->getContext();
  26.         $stateMachineTransitions = [];
  27.         /** @var OrderEntity $order */
  28.         foreach ($orders as $order) {
  29.             $orderStateId $order->getStateId();
  30.             if(!isset($stateMachineTransitions[$orderStateId])) {
  31.                 $criteria = new Criteria();
  32.                 $criteria->addAssociation('toStateMachineState');
  33.                 $criteria->addFilter(new EqualsFilter('fromStateId'$orderStateId));
  34.                 $allowedStates $this->stateMachineTransitionRepository->search($criteria$context)->getEntities();
  35.                 $stateMachineTransitions[$orderStateId] = $allowedStates;
  36.             }
  37.             $order->addExtension('stateMachineAllowedTransitions'$stateMachineTransitions[$orderStateId]);
  38.             $orders->add($order);
  39.         }
  40.     }
  41. }