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 {
return $this->pedidos()
->where('confirmed',true)
->with('products')
->with('productos')
->get()
->flatMap(fn($order) => $order->products->map(
fn($product) => [
'product_id' => $product->id,
'product_name' => $product->name,
'total_ordered' => $product->pivot->quantity,
->flatMap(fn($pedido) => $pedido->productos->map(
fn($producto) => [
'producto_id' => $producto->id,
'cantidad' => $producto->pivot->cantidad,
]
))
->groupBy('product_id')
->map(fn($groupedProducts) => [
'product_id' => $groupedProducts->first()['product_id'],
'product_name' => $groupedProducts->first()['product_name'],
'total_ordered' => $groupedProducts->sum('total_ordered'),
->groupBy('producto_id')
->map(fn($productosAgrupados) => [
$productosAgrupados->first()['producto_id'] => $productosAgrupados->sum('cantidad'),
]);
}
}