<?php
namespace Boldr\Shop\MultishopBundle\Presenter;
use Boldr\Shop\ShopBundle\Presenter\Order\{ OrderView, OrderViewProcessorInterface };
use Doctrine\ORM\EntityManagerInterface;
use Boldr\Shop\MultishopBundle\Entity\OrderShop;
use Boldr\Shop\ShopBundle\Entity\Order;
use Boldr\Shop\MultishopBundle\DefaultShop\DefaultShopProviderInterface;
class OrderViewProcessor implements OrderViewProcessorInterface
{
private EntityManagerInterface $em;
private ShopPresenter $shopPresenter;
private DefaultShopProviderInterface $defaultShopProvider;
public function __construct(EntityManagerInterface $em, ShopPresenter $shopPresenter, DefaultShopProviderInterface $defaultShopProvider)
{
$this->em = $em;
$this->shopPresenter = $shopPresenter;
$this->defaultShopProvider = $defaultShopProvider;
}
public function processOrderView(OrderView $orderView, Order $order, string $locale): OrderView
{
$shop = $order->getId() === null ? null : $this->em->getRepository(OrderShop::class)->find($order)?->getShop();
if ($shop === null)
{
$shop = $this->defaultShopProvider->getDefaultShop(null, $order->getCustomer());
}
/** @phpstan-ignore-next-line */
$orderView->shop = $this->shopPresenter->createShopView($shop);
return $orderView;
}
}