Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

OrderProductSolver.php 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Lc\CaracoleBundle\Solver\Order;
  3. class OrderProductSolver
  4. {
  5. // groupOrderProductsByProductFamily
  6. public function getOrderProductsByProductFamily(array $orderProducts): array
  7. {
  8. $orderProductsByProductFamily = [];
  9. foreach ($orderProducts as $orderProduct) {
  10. if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
  11. $productFamily = $orderProduct->getProduct()->getProductFamily();
  12. if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
  13. $orderProductsByProductFamily[$productFamily->getId()] = [
  14. 'order_products' => [],
  15. 'total_quantity_weight' => 0,
  16. ];
  17. }
  18. $orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
  19. $orderProductsByProductFamily[$productFamily->getId(
  20. )]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
  21. )->getCoefficient()) * $orderProduct->getQuantityOrder();
  22. }
  23. }
  24. return $orderProductsByProductFamily;
  25. }
  26. // getOrderProductsFormOrderShopsGroupByStorageOrder
  27. public function getOrderProductsByOrderShopsGroupByStorageOrder(array $orderShops): array
  28. {
  29. $orderProductsByStorageOrder = [];
  30. foreach ($orderShops as $orderShop) {
  31. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  32. if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
  33. $productFamily = $orderProduct->getProduct()->getProductFamily();
  34. $storageOrder = 0;
  35. if ($productFamily->getStorageOrder()) {
  36. $storageOrder = $productFamily->getStorageOrder();
  37. }
  38. if (!isset($orderProductsByStorageOrder[$storageOrder])) {
  39. $orderProductsByStorageOrder[$productFamily->getId()] = [
  40. 'order_products' => [],
  41. 'total_quantity_weight' => 0,
  42. ];
  43. }
  44. $orderProductsByStorageOrder[$storageOrder]['order_products'][] = $orderProduct;
  45. $orderProductsByStorageOrder[$storageOrder]['total_quantity_weight'] += ($orderProduct->getQuantityProduct(
  46. ) / $orderProduct->getUnit()->getCoefficient()) * $orderProduct->getQuantityOrder();
  47. }
  48. }
  49. }
  50. return $orderProductsByStorageOrder;
  51. }
  52. }