|
- <?php
-
- namespace Lc\CaracoleBundle\Factory\Order;
-
- use App\Entity\Order\OrderShop;
- use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent;
- use Lc\CaracoleBundle\Context\SectionContextTrait;
- 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
- {
-
- public function create(
- SectionInterface $section,
- UserInterface $user = null,
- VisitorInterface $visitor = null
- ): OrderShopInterface
- {
-
- $orderShop = $this->createBase($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;
- }
-
- public function createBase(SectionInterface $section): OrderShopInterface
- {
- $orderShop = new OrderShop();
- $orderShop->setSection($section);
- return $orderShop;
- }
-
- }
|