|
- <?php
-
- namespace Lc\CaracoleBundle\Factory\Order;
-
- use App\Entity\Order\OrderShop;
- use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent;
- use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
- use Lc\CaracoleBundle\Model\User\VisitorInterface;
- use Lc\SovBundle\Factory\AbstractFactory;
- use Lc\SovBundle\Model\User\UserInterface;
- use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-
- class OrderShopFactory extends AbstractFactory
- {
- protected EventDispatcherInterface $eventDispatcher;
- protected OrderStatusHistoryFactory $orderStatusHistoryFactory;
-
- public function __construct(
- EventDispatcherInterface $eventDispatcher,
- OrderStatusHistoryFactory $orderStatusHistoryFactory
- ) {
- $this->eventDispatcher = $eventDispatcher;
- $this->orderStatusHistoryFactory = $orderStatusHistoryFactory;
- }
-
- public function create(
- SectionInterface $section,
- UserInterface $user = null,
- VisitorInterface $visitor = null
- ): OrderShopInterface {
-
- $orderShop = new OrderShop();
-
- $orderShop->setSection($section);
-
- $orderShopBelongTo = false;
-
- if (!is_null($user)) {
- $orderShopBelongTo = true;
- $orderShop->setUser($user);
- }
-
- if (!is_null($visitor) && !$orderShop->getUser()) {
- $orderShopBelongTo = true;
- $orderShop->setVisitor($visitor);
- }
-
- if (!$orderShopBelongTo) {
- throw new \ErrorException('La commande doit être liée à un utilisateur ou à un visiteur.');
- }
-
- return $orderShop;
- }
-
- }
|