Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

OrderController.php 27KB

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