diff --git a/code/app/BookedProduct.php b/code/app/BookedProduct.php index 21870eb7..f8423f79 100644 --- a/code/app/BookedProduct.php +++ b/code/app/BookedProduct.php @@ -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; } } diff --git a/code/app/Jobs/NotifyClosedOrder.php b/code/app/Jobs/NotifyClosedOrder.php index 7dfcc26d..bdd98fcb 100644 --- a/code/app/Jobs/NotifyClosedOrder.php +++ b/code/app/Jobs/NotifyClosedOrder.php @@ -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); /* diff --git a/code/app/Order.php b/code/app/Order.php index 25702578..2085b395 100644 --- a/code/app/Order.php +++ b/code/app/Order.php @@ -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 @@ -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()