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; } }