cambio logica de productos pedidos

This commit is contained in:
Alejandro Tasistro 2024-03-20 00:46:08 -03:00
parent c2a59495be
commit 5703e92f8d
1 changed files with 8 additions and 11 deletions

View File

@ -117,20 +117,17 @@ private function armarColumnasPedido() : array {
private function productosCantidadesPedidas() : array { private function productosCantidadesPedidas() : array {
return $this->pedidos() return $this->pedidos()
->where('confirmed',true) ->where('confirmed',true)
->with('products') ->with('productos')
->get() ->get()
->flatMap(fn($order) => $order->products->map( ->flatMap(fn($pedido) => $pedido->productos->map(
fn($product) => [ fn($producto) => [
'product_id' => $product->id, 'producto_id' => $producto->id,
'product_name' => $product->name, 'cantidad' => $producto->pivot->cantidad,
'total_ordered' => $product->pivot->quantity,
] ]
)) ))
->groupBy('product_id') ->groupBy('producto_id')
->map(fn($groupedProducts) => [ ->map(fn($productosAgrupados) => [
'product_id' => $groupedProducts->first()['product_id'], $productosAgrupados->first()['producto_id'] => $productosAgrupados->sum('cantidad'),
'product_name' => $groupedProducts->first()['product_name'],
'total_ordered' => $groupedProducts->sum('total_ordered'),
]); ]);
} }
} }