Skip to content

Commit

Permalink
fix job invio notifica reminder
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Nov 16, 2024
1 parent 271f76f commit eddf5c2
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions code/app/Jobs/NotifyRemindOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
}
}
}
}
}
Expand Down

0 comments on commit eddf5c2

Please sign in to comment.