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.6KB

3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. throw new \ErrorException('La commande doit être liée à un utilisateur ou à un visiteur.');
  34. }
  35. return $orderShop;
  36. }
  37. public function createBase(SectionInterface $section): OrderShopInterface
  38. {
  39. $orderShop = new OrderShop();
  40. $orderShop->setSection($section);
  41. return $orderShop;
  42. }
  43. }