Files
isaaccladandCursor 09359ca86a
Deploy Ladill Woo Manager / deploy (push) Successful in 39s
Add per-store managers for Woo Business accounts.
Agencies can invite store-scoped managers via Identity, with access limited to one WooCommerce store while owners retain full multi-store control.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-08 07:51:08 +00:00

57 lines
1.5 KiB
PHP

<?php
namespace App\Services\Woo;
use App\Models\User;
use App\Models\WooStoreMember;
use App\Services\Identity\IdentityTeamClient;
class TeamMemberProvisioner
{
public function __construct(
protected IdentityTeamClient $identity,
) {}
public function sync(User $user): void
{
WooStoreMember::query()
->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),
],
);
}
}
}