orderUtils = $orderUtils ; $this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetaData(ProductFamilyInterface::class)->getName()) ; $this->orderProductRepository = $this->em->getRepository($this->em->getClassMetaData(OrderProductInterface::class)->getName()) ; } public function addProductFamily(Request $request) { $return = [] ; $data = $request->request->all() ; if(isset($data['order_products']['id_product_family'])) { $idProductFamily = $data['order_products']['id_product_family'] ; $this->productFamily = $this->productFamilyRepository->find($idProductFamily) ; if($this->productFamily) { $form = $this->createForm(OrderProductsType::class, ['id_product_family' => $this->productFamily->getId()]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $orderShop = $this->orderUtils->getOrderShopCurrent() ; $data = $form->getData() ; foreach($data as $orderProduct) { if($orderProduct instanceof OrderProductInterface) { $this->orderUtils->addOrderProduct($orderShop, $orderProduct) ; if($orderProduct->getQuantityorder() > 0) { $this->orderProducts[] = $orderProduct ; } } } } } } return new JsonResponse($return) ; } }