You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
3.3KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Transformer\Order;
  3. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  4. use Lc\CaracoleBundle\Resolver\ReductionResolver;
  5. use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
  6. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  7. use Lc\SovBundle\Model\User\UserInterface;
  8. class OrderShopTransformer
  9. {
  10. protected PriceSolver $priceSolver;
  11. protected OrderShopSolver $orderShopSolver;
  12. public function __construct(PriceSolver $priceSolver, OrderShopSolver $orderShopSolver)
  13. {
  14. $this->priceSolver = $priceSolver;
  15. $this->orderShopSolver = $orderShopSolver;
  16. }
  17. // getOrderDatas
  18. public function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array
  19. {
  20. $data = [];
  21. $data['order'] = $orderShop;
  22. if ($orderShop) {
  23. $data['count'] = $this->orderShopSolver->countQuantities($orderShop);
  24. $data['total_with_tax'] = $this->priceSolver->getTotalWithTax($orderShop);
  25. $data['order_products_by_category'] = $this->orderShopSolver->getOrderProductsByParentCategory($orderShop);
  26. $data['total_remaining_to_be_paid'] = $this->orderShopSolver->getTotalRemainingToBePaid($orderShop);
  27. }
  28. return $data;
  29. }
  30. public function getAsJsonObject(OrderShopInterface $orderShop): array
  31. {
  32. $data['id'] = $orderShop->getId();
  33. $data['user'] = $orderShop->getUser()->getSummary();
  34. $data['orderStatus'] = $orderShop->getOrderStatus()->__toString();
  35. $data['deliveryAddress'] = $orderShop->getDeliveryAddress()->getSummary();
  36. $data['invoiceAddress'] = $orderShop->getInvoiceAddress()->getSummary();
  37. $data['total'] = $this->priceSolver->getTotal($orderShop);
  38. $data['totalWithTax'] = $this->priceSolver->getTotalWithTax($orderShop);
  39. $data['totalWithTaxAndReduction'] = $this->priceSolver->getTotalWithTax($orderShop);
  40. $i = 0;
  41. $orderProductsByParentCategory = $this->orderShopSolver->getOrderProductsByParentCategory($orderShop);
  42. foreach ($orderProductsByParentCategory as $labelCategory => $orderProducts) {
  43. foreach ($orderProducts as $orderProduct) {
  44. $data['orderProducts'][$i]['id'] = $orderProduct->getId();
  45. $data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId();
  46. $data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder();
  47. $data['orderProducts'][$i]['labelCategory'] = $labelCategory;
  48. $data['orderProducts'][$i]['title'] = $orderProduct->getTitle();
  49. $data['orderProducts'][$i]['price'] = $this->priceSolver->getPrice($orderProduct);
  50. $data['orderProducts'][$i]['priceWithTax'] = $this->priceSolver->getPriceWithTax($orderProduct);
  51. $data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceSolver->getPriceWithTaxAndReduction(
  52. $orderProduct
  53. );
  54. $data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
  55. $data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceSolver->getTotalOrderProductsWithTaxAndReduction(
  56. array($orderProduct)
  57. );
  58. $i++;
  59. }
  60. }
  61. return $data;
  62. }
  63. }