Add Woo Manager Pro with multi-store switching and free-tier limits.
Deploy Ladill Woo Manager / deploy (push) Successful in 51s

Free: 1 store and 20 products. Pro/Business mirrors Invoice pricing (GHS 49/149)
with wallet renewals, Paystack prepay, session-based store switcher, and scoped UI.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-07 01:14:08 +00:00
co-authored by Cursor
parent 551473f8e5
commit cebf0d2e61
34 changed files with 1340 additions and 263 deletions
+65 -61
View File
@@ -3,11 +3,12 @@
namespace App\Http\Controllers\Woo;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Woo\Concerns\ResolvesWooContext;
use App\Models\WooProduct;
use App\Models\WooStore;
use App\Services\Woo\CatalogSyncService;
use App\Services\Woo\CatalogWriteService;
use App\Services\Woo\ProductMediaService;
use App\Services\Woo\SubscriptionService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
@@ -15,24 +16,25 @@ use Illuminate\View\View;
class ProductController extends Controller
{
use ResolvesWooContext;
public function __construct(
private CatalogWriteService $write,
private CatalogSyncService $sync,
private ProductMediaService $media,
private SubscriptionService $subscriptions,
) {}
public function index(Request $request): View
{
$user = $request->user();
$user = $this->accountUser($request);
$store = $this->currentStore($request);
$search = trim((string) $request->query('q', ''));
$storeFilter = $request->query('store');
$statusFilter = $request->query('status');
$storeIds = WooStore::query()->where('user_id', $user->id)->pluck('id');
$products = WooProduct::query()
->whereIn('woo_store_id', $storeIds)
->when($storeFilter, fn ($q) => $q->where('woo_store_id', $storeFilter))
->when($store, fn ($q) => $q->where('woo_store_id', $store->id))
->when(! $store, fn ($q) => $q->whereRaw('1 = 0'))
->when($statusFilter, fn ($q) => $q->where('status', $statusFilter))
->when($search !== '', function ($query) use ($search) {
$like = '%'.$search.'%';
@@ -46,82 +48,101 @@ class ProductController extends Controller
->paginate(20)
->withQueryString();
$stores = WooStore::query()->where('user_id', $user->id)->orderBy('site_name')->get();
return view('woo.products.index', compact('products', 'stores', 'search', 'storeFilter', 'statusFilter'));
return view('woo.products.index', [
'products' => $products,
'currentStore' => $store,
'search' => $search,
'statusFilter' => $statusFilter,
'productCount' => $this->subscriptions->productCount($user),
'productLimit' => $this->subscriptions->isPro($user) ? null : (int) config('woo.free.max_products', 20),
]);
}
public function create(Request $request): View
public function create(Request $request): View|RedirectResponse
{
$stores = $this->activeStores($request);
$user = $this->accountUser($request);
$store = $this->currentStoreOrFail($request);
if (! $this->subscriptions->canCreateProduct($user)) {
return redirect()->route('woo.pro.index')
->with('upsell', 'You have reached the free plan limit of '.(int) config('woo.free.max_products', 20).' products. Upgrade to Pro for unlimited products.');
}
return view('woo.products.form', [
'product' => new WooProduct(['status' => WooProduct::STATUS_DRAFT]),
'stores' => $stores,
'categories' => collect(),
'product' => new WooProduct(['status' => WooProduct::STATUS_DRAFT, 'woo_store_id' => $store->id]),
'currentStore' => $store,
'categories' => $store->categories()->orderBy('name')->get(),
]);
}
public function store(Request $request): RedirectResponse
{
$validated = $this->validateProduct($request);
$store = $this->authorizedStore($request, (int) $validated['woo_store_id']);
$user = $this->accountUser($request);
$store = $this->currentStoreOrFail($request);
if (! $this->subscriptions->canCreateProduct($user)) {
return redirect()->route('woo.pro.index')
->with('upsell', 'You have reached the free plan limit of '.(int) config('woo.free.max_products', 20).' products. Upgrade to Pro for unlimited products.');
}
$validated = $this->validateProduct($request, $store);
$validated['images'] = $this->media->buildImagesFromRequest($request, $store);
$this->write->createProduct($store, $validated);
return redirect()->route('woo.products.index', ['store' => $store->id])
return redirect()->route('woo.products.index')
->with('success', 'Product saved.');
}
public function edit(Request $request, WooProduct $product): View
{
$product->load('store');
abort_if($product->store?->user_id !== $request->user()->id, 403);
$store = $this->currentStoreOrFail($request);
abort_if($product->woo_store_id !== $store->id, 404);
$stores = $this->activeStores($request);
$categories = $product->store
? $product->store->categories()->orderBy('name')->get()
: collect();
return view('woo.products.form', compact('product', 'stores', 'categories'));
return view('woo.products.form', [
'product' => $product,
'currentStore' => $store,
'categories' => $store->categories()->orderBy('name')->get(),
]);
}
public function update(Request $request, WooProduct $product): RedirectResponse
{
$product->load('store');
abort_if($product->store?->user_id !== $request->user()->id, 403);
$store = $this->currentStoreOrFail($request);
abort_if($product->woo_store_id !== $store->id, 404);
$validated = $this->validateProduct($request, $product);
$validated['images'] = $this->media->buildImagesFromRequest($request, $product->store);
$validated = $this->validateProduct($request, $store, $product);
$validated['images'] = $this->media->buildImagesFromRequest($request, $store);
$this->write->updateProduct($product, $validated);
return redirect()->route('woo.products.index', ['store' => $product->woo_store_id])
return redirect()->route('woo.products.index')
->with('success', 'Product updated.');
}
public function sync(Request $request): RedirectResponse
{
$validated = $request->validate([
'store' => ['required', 'integer'],
]);
$store = $this->currentStoreOrFail($request);
$user = $this->accountUser($request);
$counts = $this->sync->syncAll($store, $user);
$store = $this->authorizedStore($request, (int) $validated['store']);
$counts = $this->sync->syncAll($store);
return back()->with('success', sprintf(
$message = sprintf(
'Synced %d categories and %d products from %s.',
$counts['categories'],
$counts['products'],
$store->site_name ?? $store->site_url,
));
);
if (! $this->subscriptions->isPro($user) && $this->subscriptions->productCount($user) >= (int) config('woo.free.max_products', 20)) {
$message .= ' Free plan is limited to '.(int) config('woo.free.max_products', 20).' products — upgrade to Pro to sync your full catalog.';
}
return back()->with('success', $message);
}
/** @return array<string, mixed> */
private function validateProduct(Request $request, ?WooProduct $product = null): array
private function validateProduct(Request $request, $store, ?WooProduct $product = null): array
{
return $request->validate([
'woo_store_id' => ['required', 'integer'],
return array_merge($request->validate([
'name' => ['required', 'string', 'max:255'],
'sku' => ['nullable', 'string', 'max:120'],
'status' => ['required', Rule::in(array_keys(WooProduct::STATUSES))],
@@ -141,25 +162,8 @@ class ProductController extends Controller
'gallery_uploads.*' => ['image', 'max:10240'],
'gallery_image_srcs' => ['nullable', 'array'],
'gallery_image_srcs.*' => ['url', 'max:2000'],
]), [
'woo_store_id' => $store->id,
]);
}
private function authorizedStore(Request $request, int $storeId): WooStore
{
return WooStore::query()
->where('user_id', $request->user()->id)
->whereKey($storeId)
->where('status', WooStore::STATUS_ACTIVE)
->firstOrFail();
}
/** @return \Illuminate\Support\Collection<int, WooStore> */
private function activeStores(Request $request)
{
return WooStore::query()
->where('user_id', $request->user()->id)
->where('status', WooStore::STATUS_ACTIVE)
->orderBy('site_name')
->get();
}
}