leftJoin('entity.orderStatus', 'orderStatus'); if ($filterOrderStatus) { $queryBuilder->andWhere('orderStatus.alias IN (:status)'); $queryBuilder->setParameter('status', $filterOrderStatus); } return $queryBuilder; } public function updateEntity($entity) { foreach ($entity->getOrderProducts() as $orderProduct) { //dump($orderProduct); $orderProduct->setCreatedBy($this->getUser()); $orderProduct->setUpdatedBy($this->getUser()); $orderProduct->setTaxRate($orderProduct->getProduct()->getProductFamily()->getTaxRate()); $orderProduct->setOrderShop($entity); $this->em->persist($orderProduct); $entity->addOrderProduct($orderProduct); } $this->setUpdated($entity); parent::updateEntity($entity); } public function persistEntity($entity) { foreach ($entity->getOrderProducts() as $orderProduct) { $orderProduct->setUnit($orderProduct->getProduct()->getUnitInherited()); $orderProduct->setTitle($orderProduct->getProduct()->getTitleInherited()); $orderProduct->setPrice($orderProduct->getProduct()->getPriceInherited()); if ($orderProduct->getProduct()->getProductFamily()->getTaxRate()) { $orderProduct->setTaxRate($orderProduct->getProduct()->getProductFamily()->getTaxRate()); } else { $orderProduct->setTaxRate($this->security->getUser()->getMerchant()->getTaxRate()); } $orderProduct->setOrderShop($entity); $orderProduct->setCreatedBy($this->getUser()); $orderProduct->setUpdatedBy($this->getUser()); $this->em->persist($orderProduct); $entity->addOrderProduct($orderProduct); } parent::persistEntity($entity); } public function getUserViaFirstStepForm($entity) { $userClass = $this->em->getClassMetadata(UserInterface::class); $userChoiceForm = $this->createFormBuilder($entity) ->add('user', EntityType::class, array( 'class' => $userClass->name )) ->add('nextStep', SubmitType::class) ->getForm(); $userChoiceForm->handleRequest($this->request); if ($userChoiceForm->isSubmitted() && $userChoiceForm->isValid()) { return $userChoiceForm->get('user')->getData(); } $parameters = [ 'form' => $userChoiceForm->createView(), 'formView' => 'default', 'entity' => $entity, ]; return $this->executeDynamicMethod('renderTemplate', ['new', $this->entity['templates']['new'], $parameters]); } public function addProductToOrderAction() { $id = $this->request->query->get('id'); $easyadmin = $this->request->attributes->get('easyadmin'); $orderShop = $easyadmin['item']; $orderProductClass = $this->em->getClassMetadata(OrderProductInterface::class); $formAddProductToOrder = $this->createForm(AddPoductToOrderType::class); $formAddProductToOrder->handleRequest($this->request); if ($formAddProductToOrder->get('product')->getData() == null) { $response['status'] = 'error'; $response['message'] = 'Vous devez choisir un produit dans la liste'; } else if ($formAddProductToOrder->get('quantity')->getData() == null) { $response['status'] = 'error'; $response['message'] = 'Vous devez entrer une quantité'; } else if ($formAddProductToOrder->isSubmitted() && $formAddProductToOrder->isValid()) { $orderProduct = new $orderProductClass->name; if ($this->orderUtils->isProductAvailable($formAddProductToOrder->get('product')->getData(), $formAddProductToOrder->get('quantity')->getData())) { $orderProduct->setQuantityOrder($formAddProductToOrder->get('quantity')->getData()); $orderProduct->setProduct($formAddProductToOrder->get('product')->getData()); $this->orderUtils->addOrderProduct($orderShop, $orderProduct); $response['status'] = 'success'; $response['message'] = 'Le produit a bien été ajouté à la commande'; } else { $response['status'] = 'error'; $response['message'] = 'Le produit n\'est pas disponible dans cette quantité'; } } else { $response['status'] = 'error'; $response['message'] = 'Une erreur est survenue'; } $response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);; return new Response(json_encode($response)); } public function orderProductsAction() { $id = $this->request->query->get('id'); $easyadmin = $this->request->attributes->get('easyadmin'); $orderShop = $easyadmin['item']; $formOrderProducts = $this->createForm(OrderProductsType::class, $orderShop); $formOrderProducts->handleRequest($this->request); if ($formOrderProducts->isSubmitted() && $formOrderProducts->isValid()) { $error = false; // dump($formOrderProducts->get('orderProducts')->getData()); foreach ($orderShop->getOrderProducts() as $orderProduct) { if($this->orderUtils->isProductAvailable($orderProduct->getProduct(),$orderProduct->getQuantityOrder())) { if ($orderProduct->getQuantityOrder() <= 0) { $this->em->remove($orderProduct); } else { $this->em->persist($orderProduct); } }else{ $error = true; $response['status'] = 'error'; $response['message'] = 'Le prduit n\'est pas disponible dans cette quantité'; } } if(!$error) { $this->em->flush(); $response['status'] = 'success'; $response['message'] = 'La commande a bien été modifié'; } } else { $response['status'] = 'error'; $response['message'] = 'Une erreur est survenue'; } $response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);; return new Response(json_encode($response)); } public function orderInvoiceAddressAction() { $id = $this->request->query->get('id'); $easyadmin = $this->request->attributes->get('easyadmin'); $orderShop = $easyadmin['item']; $formOrderInvoiceAddress = $this->createForm(OrderInvoiceAddressType::class, $orderShop); $formOrderInvoiceAddress->handleRequest($this->request); if ($formOrderInvoiceAddress->isSubmitted() && $formOrderInvoiceAddress->isValid()) { //TODO si la commande est valide on hydrate le champ invoiceAddresText et on vide invoiceAddres $this->em->persist($orderShop); $this->em->flush(); $response['status'] = 'success'; $response['message'] = 'La commande a bien été modifié'; } else { $response['status'] = 'error'; $response['message'] = 'Une erreur est survenue'; } $response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);; return new Response(json_encode($response)); } public function orderStatusAction() { $id = $this->request->query->get('id'); $easyadmin = $this->request->attributes->get('easyadmin'); $orderShop = $easyadmin['item']; $formOrderStatus = $this->createForm(OrderStatusType::class, $orderShop); $formOrderStatus->handleRequest($this->request); if ($formOrderStatus->isSubmitted() && $formOrderStatus->isValid()) { if ($orderShop = $this->orderUtils->changeOrderStatus($formOrderStatus->get('orderStatus')->getData(), $orderShop)) { $this->addFlash('success', 'La commande a bien été modifié.'); } } else { $this->addFlash('error', 'Une erreur s\'est produite'); } return $this->redirectToRoute('easyadmin', [ 'action' => 'show', 'entity' => $this->request->query->get('entity'), 'id' => $id ]); } public function orderPaymentAction() { $id = $this->request->query->get('id'); $easyadmin = $this->request->attributes->get('easyadmin'); $orderShop = $easyadmin['item']; $orderPaymentClass = $this->em->getClassMetadata(OrderPaymentInterface::class); $orderPayment = new $orderPaymentClass->name; $formOrderPayment = $this->createForm(OrderPaymentType::class, $orderPayment); $formOrderPayment->handleRequest($this->request); if ($formOrderPayment->isSubmitted() && $formOrderPayment->isValid()) { $orderPayment->setOrderShop($orderShop); $this->em->persist($orderPayment); $this->em->flush(); $response['status'] = 'success'; $response['message'] = 'La paiement a bien été ajouté'; } else { $response['status'] = 'error'; $response['message'] = 'Une erreur est survenue'; } $response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);; return new Response(json_encode($response)); } public function orderReductionCartAction() { $id = $this->request->query->get('id'); $easyadmin = $this->request->attributes->get('easyadmin'); $orderShop = $easyadmin['item']; $formOrderReductionCart = $this->createForm(OrderReductionCartType::class, $orderShop); $formOrderReductionCart->handleRequest($this->request); if ($formOrderReductionCart->isSubmitted() && $formOrderReductionCart->isValid()) { $reductionCart = $formOrderReductionCart->get('reductionCart')->getData(); $orderShop->reductionError = array(); if ($this->orderUtils->isReductionCartAllowAddToOrder($orderShop, $reductionCart)) { $orderReductionCart = $this->orderUtils->createOrderReductionCart($orderShop, $reductionCart); $this->em->persist($orderReductionCart); $this->em->flush(); $response['status'] = 'success'; $response['message'] = 'La réduction a bien été ajouté'; } else { $response['status'] = 'error'; $response['message'] = 'Cette réduction ne peut pas être appliqué sur cette commande'; $response['message'] .= ''; } } else { $response['status'] = 'error'; $response['message'] = 'Une erreur est survenue'; } $response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);; return new Response(json_encode($response)); } public function orderReductionCreditAction() { $id = $this->request->query->get('id'); $easyadmin = $this->request->attributes->get('easyadmin'); $orderShop = $easyadmin['item']; $formOrderReductionCredit = $this->createForm(OrderReductionCreditType::class, $orderShop); $formOrderReductionCredit->handleRequest($this->request); if ($formOrderReductionCredit->isSubmitted() && $formOrderReductionCredit->isValid()) { $reductionCredit = $formOrderReductionCredit->get('reductionCredit')->getData(); $orderShop->reductionError = array(); if ($this->orderUtils->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)) { $orderReductionCredit = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit); $this->em->persist($orderReductionCredit); $this->em->flush(); $response['status'] = 'success'; $response['message'] = 'L\'avoir a bien été ajouté'; } else { $response['status'] = 'error'; $response['message'] = 'Cet avoir ne peut pas être appliqué sur cette commande'; $response['message'] .= ''; } } else { $response['status'] = 'error'; $response['message'] = 'Une erreur est survenue'; } $response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);; return new Response(json_encode($response)); } public function renderOrderCartTemplate($actionName, $templatePath, array $parameters = []) { dump($actionName); if ($actionName == 'show') { if (!isset($parameters['form_order_delivery_address'])) { $parameters['form_order_delivery_address'] = $this->createOrderForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView(); } $parameters['form_order_reduction_credit'] = $this->createOrderForm(OrderReductionCreditType::class, 'orderReductionCredit', $parameters)->createView(); $parameters['form_order_reduction_cart'] = $this->createOrderForm(OrderReductionCartType::class, 'orderReductionCart', $parameters)->createView(); $parameters['form_add_product_to_order'] = $this->createOrderForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView(); $parameters['form_order_products'] = $this->createOrderForm(OrderProductsType::class, 'orderProducts', $parameters)->createView(); $parameters['form_order_invoice_address'] = $this->createOrderForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView(); $parameters['form_order_status'] = $this->createOrderForm(OrderStatusType::class, 'orderStatus', $parameters)->createView(); } return parent::renderTemplate($actionName, $templatePath, $parameters); } public function renderOrderShopTemplate($actionName, $templatePath, array $parameters = []) { if ($actionName == 'show') { if (!isset($parameters['form_order_delivery_address'])) { $parameters['form_order_delivery_address'] = $this->createOrderForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView(); } $parameters['form_order_reduction_credit'] = $this->createOrderForm(OrderReductionCreditType::class, 'orderReductionCredit', $parameters)->createView(); $parameters['form_order_reduction_cart'] = $this->createOrderForm(OrderReductionCartType::class, 'orderReductionCart', $parameters)->createView(); $parameters['form_add_product_to_order'] = $this->createOrderForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView(); $parameters['form_order_products'] = $this->createOrderForm(OrderProductsType::class, 'orderProducts', $parameters)->createView(); $parameters['form_order_invoice_address'] = $this->createOrderForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView(); $parameters['form_order_status'] = $this->createOrderForm(OrderStatusType::class, 'orderStatus', $parameters)->createView(); $parameters['form_order_payment'] = $this->createOrderForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView(); } return parent::renderTemplate($actionName, $templatePath, $parameters); } public function createOrderForm($class, $action, $parameters, $data = true) { $options = array(); if ($data) $options['data'] = $parameters['entity']; $options['action'] = $this->generateUrl('easyadmin', array( 'action' => $action, 'entity' => $this->entity['name'], 'id' => $parameters['entity']->getId() )); return $this->createForm($class, null, $options); } protected function newAction() { $this->dispatch(EasyAdminEvents::PRE_NEW); $entity = $this->executeDynamicMethod('createNewEntity'); $easyadmin = $this->request->attributes->get('easyadmin'); $easyadmin['item'] = $entity; $this->request->attributes->set('easyadmin', $easyadmin); $fields = $this->entity['new']['fields']; $newForm = $this->executeDynamicMethod('createNewForm', [$entity, $fields]); $newForm->handleRequest($this->request); //ETAPE 1 Choix de l'utilisateur $user = $newForm->get('user')->getData(); if ($user == null) { $user = $this->getUserViaFirstStepForm($entity); } if (!$user instanceof UserInterface) return $user; else { $orderShop = $this->orderUtils->createOrderShop(array( 'user' => $user, 'merchant' => $this->merchantUtils->getMerchantUser() )); return $this->redirectToRoute('easyadmin', [ 'action' => 'edit', 'entity' => $this->entity['name'], 'id' => $orderShop->getId() ]); } } /** * The method that is executed when the user performs a 'show' action on an entity. * * @return Response */ public function showAction() { $this->dispatch(EasyAdminEvents::PRE_SHOW); $id = $this->request->query->get('id'); $easyadmin = $this->request->attributes->get('easyadmin'); $entity = $easyadmin['item']; $fields = $this->entity['show']['fields']; $deleteForm = $this->createDeleteForm($this->entity['name'], $id); $this->dispatch(EasyAdminEvents::POST_SHOW, [ 'deleteForm' => $deleteForm, 'fields' => $fields, 'entity' => $entity, ]); $parameters = [ 'entity' => $entity, 'fields' => $fields, 'delete_form' => $deleteForm->createView(), 'order' => $this->orderUtils->getOrderAsJsonObject($entity) ]; dump($this->entity['name']); return $this->executeDynamicMethod('renderTemplate', ['show', $this->entity['templates']['show'], $parameters]); } /** * Réécriture de edit action pr rediriger vers le show */ public function editAction() { $id = $this->request->query->get('id'); $entity = $this->request->query->get('entity'); return $this->redirectToRoute('easyadmin', [ 'action' => 'show', 'entity' => $entity, 'id' => $id ]); } }