diff --git a/code/app/Jobs/NotifyRemindOrder.php b/code/app/Jobs/NotifyRemindOrder.php index d3705125..10844e7f 100644 --- a/code/app/Jobs/NotifyRemindOrder.php +++ b/code/app/Jobs/NotifyRemindOrder.php @@ -25,9 +25,6 @@ public function __construct($orders_id) public function handle() { $hub = app()->make('GlobalScopeHub'); - $gas = $hub->getGasObj(); - - $aggregate_users = []; foreach($this->orders_id as $order_id) { $order = Order::find($order_id); @@ -36,26 +33,31 @@ public function handle() continue; } - $users = $order->notifiableUsers($gas); + foreach($order->aggregate->gas as $gas) { + $hub->setGas($gas->id); - foreach($users as $user) { - if (isset($aggregate_users[$user->id]) == false) { - $aggregate_users[$user->id] = (object) [ - 'user' => $user, - 'orders' => [], - ]; - } + $aggregate_users = []; + $users = $order->notifiableUsers($gas); - $aggregate_users[$user->id]->orders[] = $order; - } - } + foreach($users as $user) { + if (isset($aggregate_users[$user->id]) == false) { + $aggregate_users[$user->id] = (object) [ + 'user' => $user, + 'orders' => [], + ]; + } - foreach($aggregate_users as $auser) { - try { - $auser->user->notify(new RemindOrderNotification($auser->orders)); - } - catch(\Exception $e) { - \Log::error('Impossibile inoltrare mail di promemoria ordine: ' . $e->getMessage()); + $aggregate_users[$user->id]->orders[] = $order; + } + + foreach($aggregate_users as $auser) { + try { + $auser->user->notify(new RemindOrderNotification($auser->orders)); + } + catch(\Exception $e) { + \Log::error('Impossibile inoltrare mail di promemoria ordine: ' . $e->getMessage()); + } + } } } }