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.

OrderShopTransformer.php 8.6KB

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