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.

OrderShopFactory.php 1.4KB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\Factory\SectionFactoryTrait;
  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. $orderShop = new OrderShop();
  22. $orderShop->setSection($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. throw new \ErrorException('La commande doit être liée à un utilisateur ou à un visiteur.');
  34. }
  35. return $orderShop;
  36. }
  37. }