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.

47 lines
1.7KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Order;
  3. use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
  4. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  5. use Lc\SovBundle\Repository\AbstractStore;
  6. class OrderProductStore extends AbstractStore
  7. {
  8. protected OrderProductRepositoryQuery $query;
  9. public function __construct(OrderProductRepositoryQuery $query)
  10. {
  11. $this->query = $query;
  12. }
  13. // getOrderProductsFormOrderShopsGroupByStorageOrder
  14. public function getByOrderShopsGroupByStorageOrder(array $orderShops): array
  15. {
  16. $orderProductsByStorageOrder = [];
  17. foreach ($orderShops as $orderShop) {
  18. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  19. if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
  20. $storageOrder = 0;
  21. if ($orderProduct->getProduct()->getProductFamily()->getStorageOrder()) $storageOrder = $productFamily->getStorageOrder();
  22. if (!isset($orderProductsByStorageOrder[$storageOrder])) {
  23. $orderProductsByStorageOrder[$productFamily->getId()] = [
  24. 'order_products' => [],
  25. 'total_quantity_weight' => 0,
  26. ];
  27. }
  28. $orderProductsByStorageOrder[$storageOrder]['order_products'][] = $orderProduct;
  29. $orderProductsByStorageOrder[$storageOrder]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()) * $orderProduct->getQuantityOrder();
  30. }
  31. }
  32. }
  33. return $orderProductsByStorageOrder;
  34. }
  35. }