Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

589 lines
29KB

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