where('user_ref', strtolower((string) $user->email)) ->update(['user_ref' => $user->public_id]); try { $access = $this->identity->teamAccess($user->public_id); } catch (\Throwable) { return; } foreach ($access as $grant) { if (($grant['self'] ?? false) || ($grant['full_access'] ?? false)) { continue; } $apps = (array) ($grant['apps'] ?? []); if (! in_array('woo', $apps, true)) { continue; } $meta = (array) data_get($grant, 'metadata.woo', []); $storeId = (int) ($meta['store_id'] ?? 0); if ($storeId <= 0) { continue; } WooStoreMember::updateOrCreate( [ 'owner_ref' => (string) ($grant['account'] ?? $user->public_id), 'user_ref' => $user->public_id, 'woo_store_id' => $storeId, ], [ 'role' => (string) ($meta['role'] ?? WooStoreMember::ROLE_MANAGER), ], ); } } }