Add per-store managers for Woo Business accounts.
Deploy Ladill Woo Manager / deploy (push) Successful in 39s

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>
This commit is contained in:
isaacclad
2026-07-08 07:51:08 +00:00
co-authored by Cursor
parent 1b0831b176
commit 09359ca86a
26 changed files with 921 additions and 28 deletions
+32 -13
View File
@@ -10,27 +10,40 @@ class CurrentWooStore
{
public const SESSION_KEY = 'woo.current_store_id';
public function activeStores(User $user): Collection
/** @param list<int>|null $allowedStoreIds */
public function activeStores(User $account, ?array $allowedStoreIds = null): Collection
{
return WooStore::query()
->where('user_id', $user->id)
$query = WooStore::query()
->where('user_id', $account->id)
->where('status', WooStore::STATUS_ACTIVE)
->orderBy('site_name')
->orderBy('site_url')
->get();
->orderBy('site_url');
if ($allowedStoreIds !== null) {
$query->whereIn('id', $allowedStoreIds);
}
return $query->get();
}
public function resolve(?User $user): ?WooStore
/** @param list<int>|null $allowedStoreIds */
public function resolve(?User $account, ?array $allowedStoreIds = null): ?WooStore
{
if (! $user) {
if (! $account) {
return null;
}
$stores = $this->activeStores($user);
$stores = $this->activeStores($account, $allowedStoreIds);
if ($stores->isEmpty()) {
return null;
}
if ($allowedStoreIds !== null && count($allowedStoreIds) === 1) {
session([self::SESSION_KEY => $stores->first()->id]);
return $stores->first();
}
$selectedId = (int) session(self::SESSION_KEY, 0);
$store = $stores->firstWhere('id', $selectedId);
if ($store) {
@@ -43,13 +56,19 @@ class CurrentWooStore
return $first;
}
public function switch(User $user, int $storeId): WooStore
/** @param list<int>|null $allowedStoreIds */
public function switch(User $account, int $storeId, ?array $allowedStoreIds = null): WooStore
{
$store = WooStore::query()
->where('user_id', $user->id)
$query = WooStore::query()
->where('user_id', $account->id)
->whereKey($storeId)
->where('status', WooStore::STATUS_ACTIVE)
->firstOrFail();
->where('status', WooStore::STATUS_ACTIVE);
if ($allowedStoreIds !== null) {
$query->whereIn('id', $allowedStoreIds);
}
$store = $query->firstOrFail();
session([self::SESSION_KEY => $store->id]);