您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

190 行
8.2KB

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