|
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Order;
-
- use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\SovBundle\Repository\AbstractStore;
-
- class OrderProductStore extends AbstractStore
- {
- protected OrderProductRepositoryQuery $query;
-
- public function __construct(OrderProductRepositoryQuery $query)
- {
- $this->query = $query;
- }
-
- // getOrderProductsFormOrderShopsGroupByStorageOrder
- public function getByOrderShopsGroupByStorageOrder(array $orderShops): array
- {
- $orderProductsByStorageOrder = [];
-
- foreach ($orderShops as $orderShop) {
- foreach ($orderShop->getOrderProducts() as $orderProduct) {
-
- if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
-
- $storageOrder = 0;
- if ($orderProduct->getProduct()->getProductFamily()->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;
- }
- }
|