vendor/boldr/multishop-bundle/src/Presenter/OrderViewProcessor.php line 25

Open in your IDE?
  1. <?php
  2. namespace Boldr\Shop\MultishopBundle\Presenter;
  3. use Boldr\Shop\ShopBundle\Presenter\Order\{ OrderView, OrderViewProcessorInterface };
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Boldr\Shop\MultishopBundle\Entity\OrderShop;
  6. use Boldr\Shop\ShopBundle\Entity\Order;
  7. use Boldr\Shop\MultishopBundle\DefaultShop\DefaultShopProviderInterface;
  8. class OrderViewProcessor implements OrderViewProcessorInterface
  9. {
  10. private EntityManagerInterface $em;
  11. private ShopPresenter $shopPresenter;
  12. private DefaultShopProviderInterface $defaultShopProvider;
  13. public function __construct(EntityManagerInterface $em, ShopPresenter $shopPresenter, DefaultShopProviderInterface $defaultShopProvider)
  14. {
  15. $this->em = $em;
  16. $this->shopPresenter = $shopPresenter;
  17. $this->defaultShopProvider = $defaultShopProvider;
  18. }
  19. public function processOrderView(OrderView $orderView, Order $order, string $locale): OrderView
  20. {
  21. $shop = $order->getId() === null ? null : $this->em->getRepository(OrderShop::class)->find($order)?->getShop();
  22. if ($shop === null)
  23. {
  24. $shop = $this->defaultShopProvider->getDefaultShop(null, $order->getCustomer());
  25. }
  26. /** @phpstan-ignore-next-line */
  27. $orderView->shop = $this->shopPresenter->createShopView($shop);
  28. return $orderView;
  29. }
  30. }