You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Factory\Order;
  3. use App\Entity\Order\OrderShop;
  4. use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent;
  5. use Lc\CaracoleBundle\Context\SectionContextTrait;
  6. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  7. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  8. use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
  9. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  10. use Lc\CaracoleBundle\Model\User\VisitorInterface;
  11. use Lc\SovBundle\Factory\AbstractFactory;
  12. use Lc\SovBundle\Model\User\UserInterface;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. class OrderShopFactory extends AbstractFactory
  15. {
  16. public function create(
  17. SectionInterface $section,
  18. UserInterface $user = null,
  19. VisitorInterface $visitor = null
  20. ): OrderShopInterface
  21. {
  22. $orderShop = $this->createBase($section);
  23. $orderShopBelongTo = false;
  24. if (!is_null($user)) {
  25. $orderShopBelongTo = true;
  26. $orderShop->setUser($user);
  27. }
  28. if (!is_null($visitor) && !$orderShop->getUser()) {
  29. $orderShopBelongTo = true;
  30. $orderShop->setVisitor($visitor);
  31. }
  32. if (!$orderShopBelongTo) {
  33. /*
  34. * @TODO : lors de la première visite, le cookie visitor n'étant pas encore sur le navigateur du visiteur,
  35. * visitor et user sont à null. Du coup, on ne peut pas déclencher cette exception. Voir s'il n'est pas
  36. * possible d'avoir directement un visitor lors de la première visite.
  37. */
  38. // throw new \ErrorException('La commande doit être liée à un utilisateur ou à un visiteur.');
  39. }
  40. return $orderShop;
  41. }
  42. public function createBase(SectionInterface $section): OrderShopInterface
  43. {
  44. $orderShop = new OrderShop();
  45. $orderShop->setSection($section);
  46. return $orderShop;
  47. }
  48. }