custom/plugins/PayonePayment/src/Storefront/Controller/Account/AccountOrderControllerDecorator.php line 39

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace PayonePayment\Storefront\Controller\Account;
  4. use PayonePayment\PaymentHandler\PaymentHandlerGroups;
  5. use Shopware\Core\Framework\Context;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  8. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  9. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  10. use Shopware\Storefront\Controller\AccountOrderController;
  11. use Shopware\Storefront\Controller\StorefrontController;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. /**
  16.  * @Route(defaults={"_routeScope": {"storefront"}})
  17.  * @RouteScope(scopes={"storefront"})
  18.  */
  19. class AccountOrderControllerDecorator extends StorefrontController
  20. {
  21.     /**
  22.      * @var AccountOrderController
  23.      */
  24.     protected $decoratedController;
  25.     protected EntityRepositoryInterface $orderRepository;
  26.     public function __construct(StorefrontController $decoratedControllerEntityRepositoryInterface $orderRepository)
  27.     {
  28.         /** @phpstan-ignore-next-line */
  29.         $this->decoratedController $decoratedController;
  30.         $this->orderRepository $orderRepository;
  31.     }
  32.     public function orderOverview(Request $requestSalesChannelContext $context): Response
  33.     {
  34.         return $this->decoratedController->orderOverview($request$context);
  35.     }
  36.     public function cancelOrder(Request $requestSalesChannelContext $context): Response
  37.     {
  38.         return $this->decoratedController->cancelOrder($request$context);
  39.     }
  40.     public function orderSingleOverview(Request $requestSalesChannelContext $context): Response
  41.     {
  42.         return $this->decoratedController->orderSingleOverview($request$context);
  43.     }
  44.     public function ajaxOrderDetail(Request $requestSalesChannelContext $context): Response
  45.     {
  46.         return $this->decoratedController->ajaxOrderDetail($request$context);
  47.     }
  48.     public function editOrder(string $orderIdRequest $requestSalesChannelContext $context): Response
  49.     {
  50.         if ($this->isRatepayOrder($orderId$context->getContext())) {
  51.             return $this->redirectToRoute('frontend.account.order.page');
  52.         }
  53.         return $this->decoratedController->editOrder($orderId$request$context);
  54.     }
  55.     public function orderChangePayment(string $orderIdRequest $requestSalesChannelContext $context): Response
  56.     {
  57.         return $this->decoratedController->orderChangePayment($orderId$request$context);
  58.     }
  59.     public function updateOrder(string $orderIdRequest $requestSalesChannelContext $context): Response
  60.     {
  61.         if ($this->isRatepayOrder($orderId$context->getContext())) {
  62.             return $this->redirectToRoute('frontend.account.order.page');
  63.         }
  64.         return $this->decoratedController->updateOrder($orderId$request$context);
  65.     }
  66.     protected function isRatepayOrder(string $orderIdContext $context): bool
  67.     {
  68.         $criteria = new Criteria([$orderId]);
  69.         $criteria->addAssociation('transactions.paymentMethod');
  70.         $order $this->orderRepository->search($criteria$context)->first();
  71.         if ($order && $order->getTransactions()) {
  72.             $transaction $order->getTransactions()->last();
  73.             if ($transaction
  74.                 && $transaction->getPaymentMethod()
  75.                 && \in_array($transaction->getPaymentMethod()->getHandlerIdentifier(), PaymentHandlerGroups::RATEPAYtrue)) {
  76.                 return true;
  77.             }
  78.         }
  79.         return false;
  80.     }
  81. }