Skip to content

Commit

Permalink
esteso logging in fase di rimozione di un prodotto dall'ordine
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed May 4, 2024
1 parent 97fb339 commit ed847d3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 1 addition & 7 deletions code/app/BookedProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ private function fixQuantity($attribute, $rectify)
$content = 0;
}

if ($this->product) {
return $this->product->getPrice($rectify) * $content;
}
else {
\Log::error('Prodotto non trovato: ' . $this->product_id . ' - ' . $this->booking->order_id);
return 0;
}
return $this->product->getPrice($rectify) * $content;
}
}

Expand Down
7 changes: 7 additions & 0 deletions code/app/Jobs/NotifyClosedOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,20 @@ public function handle()
$aggregates = [];

$hub = app()->make('GlobalScopeHub');
$hub->enable(false);

foreach($this->orders as $order_id) {
$order = Order::find($order_id);
if (is_null($order)) {
\Log::error('Non trovato ordine in fase di notifica chiusura: ' . $order_id . ' / ' . env('DB_DATABASE'));
continue;
}

$aggregate = $order->aggregate;
$closed_aggregate = ($aggregate->last_notify == null && $aggregate->status == 'closed');

foreach($aggregate->gas as $gas) {
$hub->enable(true);
$hub->setGas($gas->id);

/*
Expand Down
11 changes: 10 additions & 1 deletion code/app/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,20 @@ public function attachProduct($product)

public function detachProduct($product)
{
$altered_bookings = 0;

/*
Se vengono rimossi dei prodotti dall'ordine, ne elimino tutte le
relative prenotazioni sinora avvenute
*/
foreach($this->bookings as $booking) {
$booking->products()->where('product_id', $product->id)->delete();
$products = $booking->products()->where('product_id', $product->id)->get();
if ($products->isEmpty() == false) {
$altered_bookings++;
foreach($products as $p) {
$p->delete();
}
}

/*
Se i prodotti rimossi erano gli unici contemplati nella
Expand All @@ -370,6 +378,7 @@ public function detachProduct($product)
}

$this->products()->detach($product->id);
\Log::info('Rimosso prodotto ' . $product->id . ' da ordine ' . $this->id . ', alterate ' . $altered_bookings . ' prenotazioni');
}

public function showableContacts()
Expand Down

0 comments on commit ed847d3

Please sign in to comment.