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>
59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Woo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Woo\Concerns\ResolvesWooContext;
|
|
use App\Models\WooStore;
|
|
use App\Services\Woo\SubscriptionService;
|
|
use App\Support\CurrentWooStore;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class StoreController extends Controller
|
|
{
|
|
use ResolvesWooContext;
|
|
|
|
public function __construct(
|
|
private SubscriptionService $subscriptions,
|
|
private CurrentWooStore $currentStore,
|
|
) {}
|
|
|
|
public function index(Request $request): View
|
|
{
|
|
$user = $this->accountUser($request);
|
|
$storeScope = $this->storeScope($request);
|
|
|
|
$stores = WooStore::query()
|
|
->where('user_id', $user->id)
|
|
->when($storeScope !== null, fn ($q) => $q->whereIn('id', $storeScope))
|
|
->latest('updated_at')
|
|
->get();
|
|
|
|
return view('woo.stores.index', [
|
|
'stores' => $stores,
|
|
'currentStore' => $this->currentStore->resolve($user, $storeScope),
|
|
'hasPaidPlan' => $this->subscriptions->hasPaidPlan($user),
|
|
'storeCount' => $this->subscriptions->connectedStoreCount($user),
|
|
'storeLimit' => $this->subscriptions->maxStores($user),
|
|
'canConnectMore' => $this->isStoreOwner($request) && $this->subscriptions->canConnectStore($user),
|
|
'isStoreOwner' => $this->isStoreOwner($request),
|
|
]);
|
|
}
|
|
|
|
public function destroy(Request $request, WooStore $store): RedirectResponse
|
|
{
|
|
abort_if(! $this->isStoreOwner($request), 403);
|
|
abort_if($store->user_id !== $this->accountUser($request)->id, 403);
|
|
|
|
$store->update(['status' => WooStore::STATUS_DISCONNECTED]);
|
|
|
|
if ((int) session(CurrentWooStore::SESSION_KEY) === $store->id) {
|
|
session()->forget(CurrentWooStore::SESSION_KEY);
|
|
}
|
|
|
|
return back()->with('success', 'Store disconnected. Install the Ladill plugin again to reconnect.');
|
|
}
|
|
}
|