Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

77 Zeilen
3.5KB

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