<?php
namespace App\ViewProcessor;
use App\Entity\{ OrderPickupDelivery, OrderOptions, CustomerOptions, OrderEmployee };
use Boldr\Shop\ShopBundle\Presenter\Order\{ OrderView, OrderViewProcessorInterface };
use Boldr\Shop\ShopBundle\Entity\Order;
use Boldr\Shop\ShopBundle\Presenter\Customer\{ AddressFormatter, CustomerView };
use Doctrine\ORM\EntityManagerInterface;
class OrderViewProcessor implements OrderViewProcessorInterface
{
private EntityManagerInterface $em;
private AddressFormatter $addressFormatter;
public function __construct(EntityManagerInterface $em, AddressFormatter $addressFormatter)
{
$this->em = $em;
$this->addressFormatter = $addressFormatter;
}
public function processOrderView(OrderView $orderView, Order $order, string $locale): OrderView
{
// @TODO 2.x Move into a decorator
$pickupDelivery = $order->getId() === null ? null : $this->em->getRepository(OrderPickupDelivery::class)->find($order);
$orderOptions = $order->getId() === null ? null : $this->em->getRepository(OrderOptions::class)->find($order);
$customerOptions = $order->getCustomer()->getId() === null ? null : $this->em->getRepository(CustomerOptions::class)->find($order->getCustomer());
$orderView->gesnedenInDoos = $orderOptions === null ? false : $orderOptions->getGesnedenInDoos();
if ($order->getId())
{
$orderEmployee = $this->em->getRepository(OrderEmployee::class)->find($order);
if ($orderEmployee)
{
$customerView = new CustomerView(
$order->getCustomer()->getId(),
$orderEmployee->getName(),
$orderEmployee->getDepartment() ? '('. $orderEmployee->getDepartment() .')' : '',
$orderEmployee->getEmailAddress(),
$order->getCustomer()->getPhoneNumber(),
$order->getCustomer()->getCompany(),
false,
$order->getCustomer()->getLocale()
);
$orderView->setCustomer($customerView);
}
}
if ($pickupDelivery)
{
$orderView->delivery = $pickupDelivery->getDelivery();
$orderView->deliveryAddress = $pickupDelivery->getAddress() ? $this->addressFormatter->formatAddress($pickupDelivery->getAddress()) : null;
$orderView->pickupDeliveryDateTime = $pickupDelivery->getDateTime();
$orderView->rit = $customerOptions === null ? false : $customerOptions->getRit();
}
else
{
$orderView->delivery = null;
$orderView->deliveryAddress = null;
$orderView->pickupDeliveryDateTime = null;
}
return $orderView;
}
}