|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
-
- namespace Lc\CaracoleBundle\Solver\Order;
-
- class OrderProductSolver
- {
- // groupOrderProductsByProductFamily
- public function getOrderProductsByProductFamily(array $orderProducts): array
- {
- $orderProductsByProductFamily = [];
- foreach ($orderProducts as $orderProduct) {
- if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
- $productFamily = $orderProduct->getProduct()->getProductFamily();
- if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
- $orderProductsByProductFamily[$productFamily->getId()] = [
- 'order_products' => [],
- 'total_quantity_weight' => 0,
- ];
- }
- $orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
- $orderProductsByProductFamily[$productFamily->getId(
- )]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
- )->getCoefficient()) * $orderProduct->getQuantityOrder();
- }
- }
-
- return $orderProductsByProductFamily;
- }
-
- // getOrderProductsFormOrderShopsGroupByStorageOrder
- public function getOrderProductsByOrderShopsGroupByStorageOrder(array $orderShops): array
- {
- $orderProductsByStorageOrder = [];
-
- foreach ($orderShops as $orderShop) {
- foreach ($orderShop->getOrderProducts() as $orderProduct) {
- if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
- $productFamily = $orderProduct->getProduct()->getProductFamily();
- $storageOrder = 0;
-
- if ($productFamily->getStorageOrder()) {
- $storageOrder = $productFamily->getStorageOrder();
- }
-
- if (!isset($orderProductsByStorageOrder[$storageOrder])) {
- $orderProductsByStorageOrder[$productFamily->getId()] = [
- 'order_products' => [],
- 'total_quantity_weight' => 0,
- ];
- }
-
- $orderProductsByStorageOrder[$storageOrder]['order_products'][] = $orderProduct;
- $orderProductsByStorageOrder[$storageOrder]['total_quantity_weight'] += ($orderProduct->getQuantityProduct(
- ) / $orderProduct->getUnit()->getCoefficient()) * $orderProduct->getQuantityOrder();
- }
- }
- }
-
- return $orderProductsByStorageOrder;
- }
- }
|