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.

преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <?php
  2. namespace Lc\ShopBundle\Controller\Backend;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
  5. use FOS\UserBundle\Model\UserManagerInterface;
  6. use Lc\ShopBundle\Context\OrderPaymentInterface;
  7. use Lc\ShopBundle\Context\OrderProductInterface;
  8. use Lc\ShopBundle\Context\OrderReductionCartInterface;
  9. use Lc\ShopBundle\Context\OrderReductionCreditInterface;
  10. use Lc\ShopBundle\Context\OrderShopInterface;
  11. use Lc\ShopBundle\Context\UserInterface;
  12. use Lc\ShopBundle\Form\Backend\Order\AddPoductToOrderType;
  13. use Lc\ShopBundle\Form\Backend\Order\AddRedeliveryOrderProductType;
  14. use Lc\ShopBundle\Form\Backend\Order\DeleteOrderPaymentType;
  15. use Lc\ShopBundle\Form\Backend\Order\DeleteOrderReductionCartType;
  16. use Lc\ShopBundle\Form\Backend\Order\DeleteOrderReductionCreditType;
  17. use Lc\ShopBundle\Form\Backend\Order\OrderDeliveryAddressType;
  18. use Lc\ShopBundle\Form\Backend\Order\OrderInvoiceAddressType;
  19. use Lc\ShopBundle\Form\Backend\Order\OrderPaymentType;
  20. use Lc\ShopBundle\Form\Backend\Order\OrderProductsType;
  21. use Lc\ShopBundle\Form\Backend\Order\AddOrderReductionCartType;
  22. use Lc\ShopBundle\Form\Backend\Order\AddOrderReductionCreditType;
  23. use Lc\ShopBundle\Form\Backend\Order\OrderSendPaymentLink;
  24. use Lc\ShopBundle\Form\Backend\Order\OrderStatusType;
  25. use Lc\ShopBundle\Model\CreditHistory;
  26. use Lc\ShopBundle\Model\OrderStatus;
  27. use Lc\ShopBundle\Services\MailUtils;
  28. use Lc\ShopBundle\Services\Utils;
  29. use Lc\ShopBundle\Services\UtilsManager;
  30. use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
  31. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  32. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  33. use Symfony\Component\HttpFoundation\Response;
  34. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  35. use Symfony\Component\Security\Core\Security;
  36. use Symfony\Contracts\Translation\TranslatorInterface;
  37. class OrderController extends AdminController
  38. {
  39. protected $creditUtils;
  40. protected $mailUtils;
  41. public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator)
  42. {
  43. $this->creditUtils = $utilsManager->getCreditUtils();
  44. $this->mailUtils = $utilsManager->getMailUtils();
  45. parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator);
  46. }
  47. protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
  48. {
  49. $filterIsOrderStatus = false;
  50. $filterNotOrderStatus = false;
  51. if (isset($dqlFilter['isOrderStatus'])) $filterIsOrderStatus = $dqlFilter['isOrderStatus'];
  52. if (isset($dqlFilter['notOrderStatus'])) $filterNotOrderStatus = $dqlFilter['notOrderStatus'];
  53. $dqlFilter = $dqlFilter['filter'];
  54. $queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter);
  55. $queryBuilder->leftJoin('entity.orderStatus', 'orderStatus');
  56. if ($filterIsOrderStatus) {
  57. $queryBuilder->andWhere('orderStatus.alias IN (:status)');
  58. $queryBuilder->setParameter('status', $filterIsOrderStatus);
  59. }
  60. if ($filterNotOrderStatus) {
  61. $queryBuilder->andWhere('orderStatus.alias NOT IN (:status)');
  62. $queryBuilder->setParameter('status', $filterNotOrderStatus);
  63. }
  64. return $queryBuilder;
  65. }
  66. public function updateEntity($entity)
  67. {
  68. //SI PAS DE problème après le 23/05/2021 à supprimer
  69. die('Une erreur est survenue, merci de contacter FAB : Erreur ligne 80 LC =>OrderController ');
  70. foreach ($entity->getOrderProducts() as $orderProduct) {
  71. //dump($orderProduct);
  72. $orderProduct->setCreatedBy($this->getUser());
  73. $orderProduct->setUpdatedBy($this->getUser());
  74. $orderProduct->setTaxRate($orderProduct->getProduct()->getProductFamily()->getTaxRate());
  75. $orderProduct->setOrderShop($entity);
  76. $this->em->persist($orderProduct);
  77. $entity->addOrderProduct($orderProduct);
  78. }
  79. $this->setUpdated($entity);
  80. parent::updateEntity($entity);
  81. }
  82. public function persistEntity($entity)
  83. {
  84. foreach ($entity->getOrderProducts() as $orderProduct) {
  85. $orderProduct->setUnit($orderProduct->getProduct()->getUnitInherited());
  86. $orderProduct->setTitle($orderProduct->getProduct()->getTitleInherited());
  87. $orderProduct->setPrice($orderProduct->getProduct()->getPriceInherited());
  88. if ($orderProduct->getProduct()->getProductFamily()->getTaxRate()) {
  89. $orderProduct->setTaxRate($orderProduct->getProduct()->getProductFamily()->getTaxRate());
  90. } else {
  91. $orderProduct->setTaxRate($this->security->getUser()->getMerchant()->getTaxRate());
  92. }
  93. $orderProduct->setOrderShop($entity);
  94. $orderProduct->setCreatedBy($this->getUser());
  95. $orderProduct->setUpdatedBy($this->getUser());
  96. $this->em->persist($orderProduct);
  97. $entity->addOrderProduct($orderProduct);
  98. }
  99. parent::persistEntity($entity);
  100. }
  101. public function getUserViaFirstStepForm($entity)
  102. {
  103. $userClass = $this->em->getClassMetadata(UserInterface::class);
  104. $userChoiceForm = $this->createFormBuilder($entity)
  105. ->add('user', EntityType::class, array(
  106. 'class' => $userClass->name
  107. ))
  108. ->add('nextStep', SubmitType::class)
  109. ->getForm();
  110. $userChoiceForm->handleRequest($this->request);
  111. if ($userChoiceForm->isSubmitted() && $userChoiceForm->isValid()) {
  112. return $userChoiceForm->get('user')->getData();
  113. }
  114. $parameters = [
  115. 'form' => $userChoiceForm->createView(),
  116. 'formView' => 'default',
  117. 'entity' => $entity,
  118. ];
  119. return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]);
  120. }
  121. public function addProductToOrderAction()
  122. {
  123. $orderShop = $this->getOrderShopEntity();
  124. $orderProductClass = $this->em->getClassMetadata(OrderProductInterface::class);
  125. $formAddProductToOrder = $this->createForm(AddPoductToOrderType::class);
  126. $formAddProductToOrder->handleRequest($this->request);
  127. if ($formAddProductToOrder->isSubmitted() && $formAddProductToOrder->isValid()) {
  128. $orderProduct = new $orderProductClass->name;
  129. if ($this->orderUtils->isProductAvailable($formAddProductToOrder->get('product')->getData(), $formAddProductToOrder->get('quantity')->getData())) {
  130. $orderProduct->setQuantityOrder($formAddProductToOrder->get('quantity')->getData());
  131. $orderProduct->setProduct($formAddProductToOrder->get('product')->getData());
  132. $this->orderUtils->addOrderProduct($orderShop, $orderProduct);
  133. $this->utils->addFlash('success', 'success.order.addProduct');
  134. } else {
  135. $this->utils->addFlash('error', 'error.order.productUnavailable');
  136. }
  137. } else {
  138. $this->utils->addFlash('error', 'error.form.submitted');
  139. }
  140. return $this->createOrderAjaxReponse($orderShop);
  141. }
  142. public function orderInvoiceAddressAction()
  143. {
  144. $orderShop = $this->getOrderShopEntity();
  145. $formOrderInvoiceAddress = $this->createForm(OrderInvoiceAddressType::class, $orderShop);
  146. $formOrderInvoiceAddress->handleRequest($this->request);
  147. if ($formOrderInvoiceAddress->isSubmitted() && $formOrderInvoiceAddress->isValid()) {
  148. //TODO si la commande est valide on hydrate le champ invoiceAddresText et on vide invoiceAddres
  149. $this->em->persist($orderShop);
  150. $this->em->flush();
  151. $this->utils->addFlash('success', 'success.order.changeInvoiceAddress');
  152. } else {
  153. $this->utils->addFlash('error', 'error.form.submitted');
  154. }
  155. return $this->createOrderAjaxReponse($orderShop);
  156. }
  157. public function orderStatusAction()
  158. {
  159. $orderShop = $this->getOrderShopEntity();
  160. $formOrderStatus = $this->createForm(OrderStatusType::class, $orderShop);
  161. $formOrderStatus->handleRequest($this->request);
  162. if ($formOrderStatus->isSubmitted() && $formOrderStatus->isValid()) {
  163. $oldStatus = $orderShop->getOrderStatus();
  164. $orderShop = $this->orderUtils->changeOrderStatus($formOrderStatus->get('orderStatus')->getData(), $orderShop, true);
  165. if ($oldStatus !== $orderShop->getOrderStatus()) {
  166. $this->utils->addFlash('success', 'success.order.changeStatus');
  167. }
  168. } else {
  169. $this->utils->addFlash('success', 'error.form.submitted');
  170. }
  171. return $this->redirectToRoute('easyadmin', [
  172. 'action' => 'show',
  173. 'entity' => $this->request->query->get('entity'),
  174. 'id' => $orderShop->getId()
  175. ]);
  176. }
  177. public function orderPaymentAction()
  178. {
  179. $orderShop = $this->getOrderShopEntity();
  180. //TODO si édition despayment existant on vérifie qu'il est lié à nla commabde courante
  181. $orderPaymentPost = $this->request->request->get('order_payment');
  182. if ($orderPaymentPost['id']) {
  183. $orderPayment = $this->em->getRepository(OrderPaymentInterface::class)->find($orderPaymentPost['id']);
  184. } else {
  185. $orderPaymentClass = $this->em->getClassMetadata(OrderPaymentInterface::class);
  186. $orderPayment = new $orderPaymentClass->name;
  187. }
  188. $formOrderPayment = $this->createForm(OrderPaymentType::class, $orderPayment);
  189. $formOrderPayment->handleRequest($this->request);
  190. if ($formOrderPayment->isSubmitted() && $formOrderPayment->isValid()) {
  191. $orderPayment->setOrderShop($orderShop);
  192. if ($orderPayment->getMeanPayment() === Utils::MEAN_PAYMENT_CREDIT) {
  193. $orderPayment->setEditable(false);
  194. $params['orderPayment'] = $orderPayment;
  195. $creditHistory = $this->creditUtils->initCreditHistory(CreditHistory::TYPE_DEBIT, $orderShop->getUser(), $params);
  196. if ($this->creditUtils->isCreditSufficientToPay($creditHistory->getUserMerchant(), $creditHistory->getAmountInherited())) {
  197. if ($this->creditUtils->saveCreditHistory($creditHistory)) {
  198. $this->em->persist($orderPayment);
  199. $this->em->flush();
  200. $this->utils->addFlash('success', 'success.credit.debited');
  201. $this->utils->addFlash('success', 'success.order.addPayment');
  202. }
  203. } else {
  204. $this->utils->addFlash('error', 'error.credit.notEnoughCredit');
  205. }
  206. } else {
  207. $orderPayment->setEditable(true);
  208. $this->em->persist($orderPayment);
  209. $this->em->flush();
  210. $this->utils->addFlash('success', 'success.order.addPayment');
  211. }
  212. } else {
  213. $this->utils->addFlash('error', $formOrderPayment->getErrors());
  214. }
  215. return $this->createOrderAjaxReponse($orderShop);
  216. }
  217. public function deleteOrderPaymentAction()
  218. {
  219. $orderShop = $this->getOrderShopEntity();
  220. $formDeleteOrderPayment = $this->createForm(DeleteOrderPaymentType::class);
  221. $formDeleteOrderPayment->handleRequest($this->request);
  222. if ($formDeleteOrderPayment->isSubmitted() && $formDeleteOrderPayment->isValid()) {
  223. $orderPayment = $this->em->getRepository(OrderPaymentInterface::class)->find($formDeleteOrderPayment->get('id')->getData());
  224. if ($orderPayment && $orderShop->getOrderPayments()->contains($orderPayment) && $orderPayment->getEditable()) {
  225. $orderShop->removeOrderPayment($orderPayment);
  226. $this->em->remove($orderPayment);
  227. $this->em->flush();
  228. $this->utils->addFlash('success', 'success.order.removeOrderPayement');
  229. }
  230. } else {
  231. $this->utils->addFlash('error', $formDeleteOrderPayment->getErrors());
  232. }
  233. return $this->createOrderAjaxReponse($orderShop);
  234. }
  235. public function addOrderReductionCartAction()
  236. {
  237. $orderShop = $this->getOrderShopEntity();
  238. $formAddOrderReductionCart = $this->createForm(AddOrderReductionCartType::class, $orderShop);
  239. $formAddOrderReductionCart->handleRequest($this->request);
  240. if ($formAddOrderReductionCart->isSubmitted() && $formAddOrderReductionCart->isValid()) {
  241. $reductionCart = $formAddOrderReductionCart->get('reductionCart')->getData();
  242. $orderShop->reductionError = array();
  243. if ($this->orderUtils->isReductionCartAllowAddToOrder($orderShop, $reductionCart)) {
  244. $orderReductionCart = $this->orderUtils->createOrderReductionCart($orderShop, $reductionCart);
  245. $this->em->persist($orderReductionCart);
  246. $this->em->flush();
  247. $this->utils->addFlash('success', 'success.order.addReductionCart');
  248. }
  249. } else {
  250. $this->utils->addFlash('error', $formAddOrderReductionCart->getErrors());
  251. }
  252. return $this->createOrderAjaxReponse($orderShop);
  253. }
  254. public function addOrderReductionCreditAction()
  255. {
  256. $orderShop = $this->getOrderShopEntity();
  257. $formAddOrderReductionCredit = $this->createForm(AddOrderReductionCreditType::class, $orderShop);
  258. $formAddOrderReductionCredit->handleRequest($this->request);
  259. if ($formAddOrderReductionCredit->isSubmitted() && $formAddOrderReductionCredit->isValid()) {
  260. $reductionCredit = $formAddOrderReductionCredit->get('reductionCredit')->getData();
  261. if ($this->orderUtils->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)) {
  262. $orderReductionCredit = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit);
  263. $this->em->persist($orderReductionCredit);
  264. $this->em->flush();
  265. $this->utils->addFlash('success', 'success.order.addReductionCredit');
  266. }
  267. } else {
  268. $this->utils->addFlash('error', $formAddOrderReductionCredit->getErrors());
  269. }
  270. return $this->createOrderAjaxReponse($orderShop);
  271. }
  272. public function addRedeliveryOrderProductAction()
  273. {
  274. $orderShop = $this->getOrderShopEntity();
  275. $formAddOrderReductionCredit = $this->createForm(AddRedeliveryOrderProductType::class, $orderShop);
  276. //TODO 0 écrire
  277. }
  278. public function deleteOrderReductionCartAction()
  279. {
  280. $orderShop = $this->getOrderShopEntity();
  281. $formDeleteOrderReductionCart = $this->createForm(DeleteOrderReductionCartType::class);
  282. $formDeleteOrderReductionCart->handleRequest($this->request);
  283. if ($formDeleteOrderReductionCart->isSubmitted() && $formDeleteOrderReductionCart->isValid()) {
  284. $orderReductionCart = $this->em->getRepository(OrderReductionCartInterface::class)->find($formDeleteOrderReductionCart->get('id')->getData());
  285. if ($orderReductionCart && $orderShop->getOrderReductionCarts()->contains($orderReductionCart)) {
  286. $orderShop->removeOrderReductionCart($orderReductionCart);
  287. $this->em->remove($orderReductionCart);
  288. $this->em->flush();
  289. $this->utils->addFlash('warning', 'success.order.removeReductionCart');
  290. }
  291. } else {
  292. $this->utils->addFlash('error', $formDeleteOrderReductionCart->getErrors());
  293. }
  294. return $this->createOrderAjaxReponse($orderShop);
  295. }
  296. public function deleteOrderReductionCreditAction()
  297. {
  298. $orderShop = $this->getOrderShopEntity();
  299. $formDeleteOrderReductionCredit = $this->createForm(DeleteOrderReductionCreditType::class);
  300. $formDeleteOrderReductionCredit->handleRequest($this->request);
  301. if ($formDeleteOrderReductionCredit->isSubmitted() && $formDeleteOrderReductionCredit->isValid()) {
  302. $orderReductionCredit = $this->em->getRepository(OrderReductionCreditInterface::class)->find($formDeleteOrderReductionCredit->get('id')->getData());
  303. if ($formDeleteOrderReductionCredit && $orderShop->getOrderReductionCredits()->contains($orderReductionCredit)) {
  304. $orderShop->removeOrderReductionCredit($orderReductionCredit);
  305. $this->em->remove($orderReductionCredit);
  306. $this->em->flush();
  307. $this->utils->addFlash('warning', 'success.order.removeReductionCredit');
  308. }
  309. } else {
  310. $this->utils->addFlash('error', $formDeleteOrderReductionCredit->getErrors());
  311. }
  312. return $this->createOrderAjaxReponse($orderShop);
  313. }
  314. public function orderSendPaymentLinkAction(){
  315. $orderShop = $this->getOrderShopEntity();
  316. $formOrderSendPaymentLink = $this->createForm(OrderSendPaymentLink::class);
  317. $formOrderSendPaymentLink->handleRequest($this->request);
  318. if ($formOrderSendPaymentLink->isSubmitted() && $formOrderSendPaymentLink->isValid()) {
  319. $orderShop->setOrderAllowByAdmin(true);
  320. $this->em->persist($orderShop);
  321. $this->em->flush();
  322. $this->mailUtils->send([
  323. MailUtils::SUBJECT => 'Réglement de votre commande',
  324. MailUtils::TO_EMAIL => $orderShop->getUser()->getEmail(),
  325. MailUtils::TO_NAME => $orderShop->getUser()->getName(),
  326. MailUtils::CONTENT_TEMPLATE => 'mail/order-payment-link',
  327. MailUtils::CONTENT_DATA => [
  328. 'order_shop' => $orderShop,
  329. 'link' => $this->generateUrl('frontend_order_payment',array(),UrlGeneratorInterface::ABSOLUTE_URL)
  330. ],
  331. ]);
  332. $this->utils->addFlash('success', 'success.order.sendPaymentLink');
  333. } else {
  334. $this->utils->addFlash('error', $formOrderSendPaymentLink->getErrors());
  335. }
  336. return $this->createOrderAjaxReponse($orderShop);
  337. }
  338. protected function createOrderAjaxReponse(OrderShopInterface $order)
  339. {
  340. $response['flashMessages'] = $this->utils->getFlashMessages();
  341. $response['data'] = $this->orderUtils->getOrderAsJsonObject($order);
  342. return new Response(json_encode($response));
  343. }
  344. public function renderOrderShopTemplate($actionName, $templatePath, array $parameters = [])
  345. {
  346. if ($actionName == 'show') {
  347. $orderShop = $this->getOrderShopEntity();
  348. switch ($orderShop->getOrderStatus()->getAlias()) {
  349. case OrderStatus::ALIAS_CART :
  350. if (!isset($parameters['form_order_delivery_address'])) {
  351. $parameters['form_order_delivery_address'] = $this->createCustomForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView();
  352. }
  353. $parameters['form_add_order_reduction_credit'] = $this->createCustomForm(AddOrderReductionCreditType::class, 'addOrderReductionCredit', $parameters)->createView();
  354. $parameters['form_add_order_reduction_cart'] = $this->createCustomForm(AddOrderReductionCartType::class, 'addOrderReductionCart', $parameters)->createView();
  355. $parameters['form_delete_order_reduction_cart'] = $this->createCustomForm(DeleteOrderReductionCartType::class, 'deleteOrderReductionCart', $parameters)->createView();
  356. $parameters['form_delete_order_reduction_credit'] = $this->createCustomForm(DeleteOrderReductionCreditType::class, 'deleteOrderReductionCredit', $parameters)->createView();
  357. $parameters['form_add_product_to_order'] = $this->createCustomForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView();
  358. $parameters['form_order_products'] = $this->createCustomForm(OrderProductsType::class, 'orderProducts', $parameters)->createView();
  359. $parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView();
  360. $parameters['form_order_invoice_address'] = $this->createCustomForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView();
  361. $parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView();
  362. break;
  363. case OrderStatus::ALIAS_ERROR_PAYMENT_ONLINE :
  364. case OrderStatus::ALIAS_WAITING_PAYMENT_CREDIT :
  365. case OrderStatus::ALIAS_WAITING_PAYMENT_ONLINE :
  366. $parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView();
  367. $parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView();
  368. $parameters['form_delete_order_payment'] = $this->createCustomForm(DeleteOrderPaymentType::class, 'deleteOrderPayment', $parameters)->createView();
  369. $parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView();
  370. $parameters['form_order_invoice_address'] = $this->createCustomForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView();
  371. break;
  372. case OrderStatus::ALIAS_PAID_BY_CREDIT :
  373. case OrderStatus::ALIAS_PAID_ONLINE :
  374. case OrderStatus::ALIAS_WAITING_DELIVERY :
  375. case OrderStatus::ALIAS_WAITING_BANK_RETURN :
  376. $parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView();
  377. $parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView();
  378. $parameters['form_delete_order_payment'] = $this->createCustomForm(DeleteOrderPaymentType::class, 'deleteOrderPayment', $parameters)->createView();
  379. break;
  380. }
  381. if($orderShop->isValid()){
  382. $templatePath = "@LcShop/backend/order/show-order.html.twig";
  383. }else{
  384. $templatePath = "@LcShop/backend/order/show-cart.html.twig";
  385. }
  386. }
  387. return parent::renderTemplate($actionName, $templatePath, $parameters);
  388. }
  389. protected function newAction()
  390. {
  391. $this->dispatch(EasyAdminEvents::PRE_NEW);
  392. $entity = $this->executeDynamicMethod('createNew<EntityName>Entity');
  393. $easyadmin = $this->request->attributes->get('easyadmin');
  394. $easyadmin['item'] = $entity;
  395. $this->request->attributes->set('easyadmin', $easyadmin);
  396. $fields = $this->entity['new']['fields'];
  397. $newForm = $this->executeDynamicMethod('create<EntityName>NewForm', [$entity, $fields]);
  398. $newForm->handleRequest($this->request);
  399. //ETAPE 1 Choix de l'utilisateur
  400. $user = $newForm->get('user')->getData();
  401. if ($user == null) {
  402. $user = $this->getUserViaFirstStepForm($entity);
  403. }
  404. if (!$user instanceof UserInterface) return $user;
  405. else {
  406. //TODO Utiliser getCartByUserOrCreateIt ds OrderUtils
  407. $orderShopUser = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]);
  408. if ($orderShopUser) {
  409. $this->utils->addFlash('info', 'error.order.otherOrderAlreadyExist');
  410. return $this->redirectToRoute('easyadmin', [
  411. 'action' => 'edit',
  412. 'entity' => $this->entity['name'],
  413. 'id' => $orderShopUser->getId()
  414. ]);
  415. } else {
  416. $orderShop = $this->orderUtils->createOrderShop(array(
  417. 'user' => $user,
  418. 'merchant' => $this->merchantUtils->getMerchantUser()
  419. ));
  420. return $this->redirectToRoute('easyadmin', [
  421. 'action' => 'edit',
  422. 'entity' => $this->entity['name'],
  423. 'id' => $orderShop->getId()
  424. ]);
  425. }
  426. }
  427. }
  428. /**
  429. * The method that is executed when the user performs a 'show' action on an entity.
  430. *
  431. * @return Response
  432. */
  433. public function showAction()
  434. {
  435. $this->dispatch(EasyAdminEvents::PRE_SHOW);
  436. $id = $this->request->query->get('id');
  437. $easyadmin = $this->request->attributes->get('easyadmin');
  438. $entity = $easyadmin['item'];
  439. $fields = $this->entity['show']['fields'];
  440. $deleteForm = $this->createDeleteForm($this->entity['name'], $id);
  441. $this->dispatch(EasyAdminEvents::POST_SHOW, [
  442. 'deleteForm' => $deleteForm,
  443. 'fields' => $fields,
  444. 'entity' => $entity,
  445. ]);
  446. $parameters = [
  447. 'entity' => $entity,
  448. 'fields' => $fields,
  449. 'delete_form' => $deleteForm->createView(),
  450. 'order' => $this->orderUtils->getOrderAsJsonObject($entity)
  451. ];
  452. return $this->executeDynamicMethod('renderOrderShopTemplate', ['show', $this->entity['templates']['show'], $parameters]);
  453. }
  454. /**
  455. * Réécriture de edit action pr rediriger vers le show */
  456. public function editAction()
  457. {
  458. $id = $this->request->query->get('id');
  459. $entity = $this->request->query->get('entity');
  460. return $this->redirectToRoute('easyadmin', [
  461. 'action' => 'show',
  462. 'entity' => $entity,
  463. 'id' => $id
  464. ]);
  465. }
  466. protected function getOrderShopEntity()
  467. {
  468. $easyadmin = $this->request->attributes->get('easyadmin');
  469. $this->orderUtils->initOrderShop($easyadmin['item']);
  470. return $easyadmin['item'];
  471. }
  472. }