Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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