Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

OrderShopTransformer.php 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace Lc\CaracoleBundle\Transformer\Order;
  3. use App\Entity\Order\OrderShop;
  4. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  5. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  6. use Lc\CaracoleBundle\Resolver\OrderShopResolver;
  7. use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
  8. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  9. use Lc\SovBundle\Model\User\UserInterface;
  10. use Lc\SovBundle\Translation\TranslatorAdmin;
  11. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  12. class OrderShopTransformer
  13. {
  14. protected PriceSolver $priceSolver;
  15. protected OrderShopSolver $orderShopSolver;
  16. protected OrderShopResolver $orderShopResolver;
  17. protected TranslatorAdmin $translatorAdmin;
  18. protected UrlGeneratorInterface $urlGenerator;
  19. public function __construct(PriceSolver $priceSolver, OrderShopSolver $orderShopSolver, OrderShopResolver $orderShopResolver, TranslatorAdmin $translatorAdmin, UrlGeneratorInterface $urlGenerator)
  20. {
  21. $this->priceSolver = $priceSolver;
  22. $this->orderShopSolver = $orderShopSolver;
  23. $this->orderShopResolver = $orderShopResolver;
  24. $this->translatorAdmin = $translatorAdmin;
  25. $this->urlGenerator = $urlGenerator;
  26. }
  27. // getOrderDatas
  28. public function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array
  29. {
  30. $data = [];
  31. $data['order'] = $orderShop;
  32. if ($orderShop) {
  33. $data['count'] = $this->orderShopSolver->countQuantities($orderShop);
  34. $data['total_with_tax'] = $this->priceSolver->getTotalWithTax($orderShop);
  35. $data['order_products_by_category'] = $this->orderShopSolver->getOrderProductsByParentCategory($orderShop);
  36. $data['total_remaining_to_be_paid'] = $this->orderShopResolver->getTotalRemainingToBePaid($orderShop);
  37. }
  38. return $data;
  39. }
  40. public function getAsArray(OrderShopInterface $orderShop): array
  41. {
  42. $data['id'] = $orderShop->getId();
  43. $data['user'] = $orderShop->getUser()->getSummary();
  44. $data['orderStatus'] = $orderShop->getOrderStatus()->__toString();
  45. $data['deliveryAddress'] = $orderShop->getDeliveryAddress()->getSummary();
  46. $data['invoiceAddress'] = $orderShop->getInvoiceAddress()->getSummary();
  47. $data['total'] = $this->priceSolver->getTotal($orderShop);
  48. $data['totalWithTax'] = $this->priceSolver->getTotalWithTax($orderShop);
  49. $data['totalWithTaxAndReduction'] = $this->priceSolver->getTotalWithTax($orderShop);
  50. $i = 0;
  51. $orderProductsByParentCategory = $this->orderShopSolver->getOrderProductsByParentCategory($orderShop);
  52. foreach ($orderProductsByParentCategory as $labelCategory => $orderProducts) {
  53. foreach ($orderProducts as $orderProduct) {
  54. $data['orderProducts'][$i]['id'] = $orderProduct->getId();
  55. $data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId();
  56. $data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder();
  57. $data['orderProducts'][$i]['labelCategory'] = $labelCategory;
  58. $data['orderProducts'][$i]['title'] = $orderProduct->getTitle();
  59. $data['orderProducts'][$i]['price'] = $this->priceSolver->getPrice($orderProduct);
  60. $data['orderProducts'][$i]['priceWithTax'] = $this->priceSolver->getPriceWithTax($orderProduct);
  61. $data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceSolver->getPriceWithTaxAndReduction(
  62. $orderProduct
  63. );
  64. $data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
  65. $data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceSolver->getTotalOrderProductsWithTaxAndReduction(
  66. array($orderProduct)
  67. );
  68. $i++;
  69. }
  70. }
  71. return $data;
  72. }
  73. public function getOrderReductionCartsInfosAsArray(OrderShop $order): array
  74. {
  75. $data = array();
  76. foreach ($order->getOrderReductionCarts() as $orderReductionCart) {
  77. $data[] = array(
  78. 'title' => $orderReductionCart->__toString(),
  79. 'id' => $orderReductionCart->getId(),
  80. 'orderReference' => $order->getReference(),
  81. 'amount' => $this->priceSolver->getOrderProductsReductionCartAmountWithTax(
  82. $order,
  83. $orderReductionCart
  84. )
  85. );
  86. }
  87. return $data;
  88. }
  89. public function getOrderPaymentsInfosAsArray(OrderShop $order): array
  90. {
  91. $data = array();
  92. foreach ($order->getOrderPayments() as $orderPayment) {
  93. $data[$orderPayment->getId()] = array(
  94. 'id' => $orderPayment->getId(),
  95. 'reference' => $orderPayment->getReference(),
  96. 'orderReference' => $order->getReference(),
  97. 'comment' => $orderPayment->getComment(),
  98. 'meanPayment' => $orderPayment->getMeanPayment(),
  99. 'meanPaymentText' => $this->translatorAdmin->transChoice(
  100. 'OrderPayment', 'meanPayment',$orderPayment->getMeanPayment()
  101. ),
  102. 'paidAtText' => $orderPayment->getPaidAt()->format('d/m/Y'),
  103. 'paidAt' => $orderPayment->getPaidAt()->format('Y-m-d'),
  104. 'amount' => $orderPayment->getAmount(),
  105. 'editable' => $orderPayment->getEditable()
  106. );
  107. }
  108. return $data;
  109. }
  110. public function getOrderStatusHistoriesInfosAsArray(OrderShop $order): array
  111. {
  112. $data = array();
  113. foreach ($order->getOrderStatusHistories() as $orderStatusHistory) {
  114. $data[$orderStatusHistory->getId()] = array(
  115. 'id' => $orderStatusHistory->getId(),
  116. 'createdAt' => $orderStatusHistory->getCreatedAt()->format('d-m-Y H:i'),
  117. 'createdBy' => $orderStatusHistory->getCreatedBy() ? $orderStatusHistory->getCreatedBy(
  118. )->__toString() : 'aucun',
  119. 'orderStatus' => $orderStatusHistory->getOrderStatus()->getAlias(),
  120. 'origin' => $orderStatusHistory->getOrigin(),
  121. 'info' => $orderStatusHistory->__toString(),
  122. );
  123. }
  124. return $data;
  125. }
  126. public function getOrderReductionCreditsInfosAsArray(OrderShop $order): array
  127. {
  128. $data = array();
  129. foreach ($order->getOrderReductionCredits() as $orderReductionCredit) {
  130. $data[] = array(
  131. 'title' => $orderReductionCredit->__toString(),
  132. 'id' => $orderReductionCredit->getId(),
  133. 'orderReference' => $order->getReference(),
  134. 'amount' => $this->priceSolver->getOrderProductsReductionCreditAmountWithTax(
  135. $order,
  136. $orderReductionCredit
  137. )
  138. );
  139. }
  140. return $data;
  141. }
  142. public function getOrderTicketsInfosAsArray(OrderShop $order): array
  143. {
  144. $data = array();
  145. foreach ($order->getTickets() as $ticket) {
  146. $data[$ticket->getId()] = array(
  147. 'id' => $ticket->getId(),
  148. 'date' => $ticket->getCreatedAt()->format('d/m/Y'),
  149. 'status' => $this->translatorAdmin->trans(
  150. 'field.Ticket.statusOptions.' . $ticket->getStatus()
  151. ),
  152. 'subject' => $ticket->getSubject(),
  153. 'orderReference' => $order->getReference(),
  154. 'link' => '',
  155. );
  156. }
  157. return $data;
  158. }
  159. public function getOrderDocumentsInfosAsArray(OrderShop $order): array
  160. {
  161. $data = array();
  162. foreach ($order->getDocuments() as $orderDocument) {
  163. $data[$orderDocument->getId()] = array(
  164. 'id' => $orderDocument->getId(),
  165. 'date' => $orderDocument->getCreatedAt()->format('d/m/Y'),
  166. 'reference' => $orderDocument->getReference(),
  167. 'type' => $orderDocument->getType(),
  168. 'isSent' => $orderDocument->getIsSent(),
  169. 'orderReference' => $order->getReference(),
  170. 'link' => $this->urlGenerator->generate('document_download', ['id'=> $orderDocument->getId()])
  171. );
  172. }
  173. return $data;
  174. }
  175. }