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.

OrderProductSolver.php 5.1KB

3 jaren geleden
3 jaren geleden
3 jaren geleden
3 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Lc\CaracoleBundle\Solver\Order;
  3. use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
  4. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  5. use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
  6. use Lc\CaracoleBundle\Solver\Product\ProductSolver;
  7. class OrderProductSolver
  8. {
  9. protected ProductSolver $productSolver;
  10. protected ProductFamilySolver $productFamilySolver;
  11. public function __construct(ProductSolver $productSolver, ProductFamilySolver $productFamilySolver)
  12. {
  13. $this->productSolver = $productSolver;
  14. $this->productFamilySolver = $productFamilySolver;
  15. }
  16. // groupOrderProductsByProductFamily
  17. public function getOrderProductsByProductFamily(array $orderProducts): array
  18. {
  19. $orderProductsByProductFamily = [];
  20. foreach ($orderProducts as $orderProduct) {
  21. if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
  22. $productFamily = $orderProduct->getProduct()->getProductFamily();
  23. if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
  24. $orderProductsByProductFamily[$productFamily->getId()] = [
  25. 'order_products' => [],
  26. 'total_quantity_weight' => 0,
  27. ];
  28. }
  29. $orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
  30. $orderProductsByProductFamily[$productFamily->getId(
  31. )]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
  32. )->getCoefficient()) * $orderProduct->getQuantityOrder();
  33. }
  34. }
  35. return $orderProductsByProductFamily;
  36. }
  37. // getOrderProductsFormOrderShopsGroupByStorageOrder
  38. public function getOrderProductsByOrderShopsGroupByStorageOrder(array $orderShops): array
  39. {
  40. $orderProductsByStorageOrder = [];
  41. foreach ($orderShops as $orderShop) {
  42. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  43. if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
  44. $productFamily = $orderProduct->getProduct()->getProductFamily();
  45. $storageOrder = 0;
  46. if ($productFamily->getStorageOrder()) {
  47. $storageOrder = $productFamily->getStorageOrder();
  48. }
  49. if (!isset($orderProductsByStorageOrder[$storageOrder])) {
  50. $orderProductsByStorageOrder[$productFamily->getId()] = [
  51. 'order_products' => [],
  52. 'total_quantity_weight' => 0,
  53. ];
  54. }
  55. $orderProductsByStorageOrder[$storageOrder]['order_products'][] = $orderProduct;
  56. $orderProductsByStorageOrder[$storageOrder]['total_quantity_weight'] += ($orderProduct->getQuantityProduct(
  57. ) / $orderProduct->getUnit()->getCoefficient()) * $orderProduct->getQuantityOrder();
  58. }
  59. }
  60. }
  61. return $orderProductsByStorageOrder;
  62. }
  63. public function getTitleOrderShop(OrderProductInterface $orderProduct)
  64. {
  65. $product = $orderProduct->getProduct();
  66. $productFamily = $product->getProductFamily();
  67. $titleProduct = $product->getTitle();
  68. $titleProductFamily = $productFamily->getTitle();
  69. if (strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
  70. $title = $titleProductFamily . ' - ' . $titleProduct;
  71. } else {
  72. $title = strlen($titleProduct) ? $titleProduct : $titleProductFamily;
  73. }
  74. if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
  75. $title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product);
  76. }
  77. return $title;
  78. }
  79. public function getTitleSummaryAfterAddCart(OrderProductInterface $orderProduct)
  80. {
  81. $title = '';
  82. $product = $orderProduct->getProduct();
  83. $productFamily = $product->getProductFamily();
  84. $titleProduct = $this->productSolver->getTitleInherited($product);
  85. $titleProductFamily = $productFamily->getTitle();
  86. // multiple
  87. if ($productFamily->getActiveProducts() && $productFamily->getBehaviorAddToCart() == 'multiple') {
  88. $title .= $titleProduct;
  89. if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
  90. $title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product);
  91. }
  92. }
  93. // simple
  94. if ($productFamily->getBehaviorAddToCart() == 'simple') {
  95. if ($productFamily->getActiveProducts()) {
  96. $title .= $titleProduct;
  97. if ($this->productFamilySolver->hasProductsWithVariousWeight($productFamily)) {
  98. $title .= ' - ' . $this->productSolver->getQuantityLabelInherited($product);
  99. }
  100. }
  101. }
  102. return $title;
  103. }
  104. }