Add WooCommerce product and category management.
Deploy Ladill Woo Manager / deploy (push) Successful in 55s

Sync catalog via plugin webhooks and REST proxy, with list/create/edit UI and updated logo from monolith assets.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-06 23:40:14 +00:00
co-authored by Cursor
parent 2a79f0fcca
commit e4b6c2c1ba
24 changed files with 1593 additions and 31 deletions
@@ -0,0 +1,161 @@
<?php
namespace App\Http\Controllers\Woo;
use App\Http\Controllers\Controller;
use App\Models\WooCategory;
use App\Models\WooStore;
use App\Services\Woo\CatalogSyncService;
use App\Services\Woo\CatalogWriteService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class CategoryController extends Controller
{
public function __construct(
private CatalogWriteService $write,
private CatalogSyncService $sync,
) {}
public function index(Request $request): View
{
$user = $request->user();
$storeFilter = $request->query('store');
$search = trim((string) $request->query('q', ''));
$storeIds = WooStore::query()->where('user_id', $user->id)->pluck('id');
$categories = WooCategory::query()
->whereIn('woo_store_id', $storeIds)
->when($storeFilter, fn ($q) => $q->where('woo_store_id', $storeFilter))
->when($search !== '', fn ($q) => $q->where('name', 'like', '%'.$search.'%'))
->with('store')
->orderBy('name')
->paginate(30)
->withQueryString();
$stores = WooStore::query()->where('user_id', $user->id)->orderBy('site_name')->get();
return view('woo.categories.index', compact('categories', 'stores', 'storeFilter', 'search'));
}
public function create(Request $request): View
{
$stores = $this->activeStores($request);
$storeId = (int) $request->query('store', $stores->first()?->id ?? 0);
$parentCategories = $storeId > 0
? WooCategory::query()->where('woo_store_id', $storeId)->orderBy('name')->get()
: collect();
return view('woo.categories.form', [
'category' => new WooCategory,
'stores' => $stores,
'parentCategories' => $parentCategories,
'selectedStoreId' => $storeId,
]);
}
public function store(Request $request): RedirectResponse
{
$validated = $this->validateCategory($request);
$store = $this->authorizedStore($request, (int) $validated['woo_store_id']);
$this->write->createCategory($store, $validated);
return redirect()->route('woo.categories.index', ['store' => $store->id])
->with('success', 'Category saved.');
}
public function edit(Request $request, WooCategory $category): View
{
$category->load('store');
abort_if($category->store?->user_id !== $request->user()->id, 403);
$stores = $this->activeStores($request);
$parentCategories = $category->store
? $category->store->categories()
->where('external_id', '!=', $category->external_id)
->orderBy('name')
->get()
: collect();
return view('woo.categories.form', [
'category' => $category,
'stores' => $stores,
'parentCategories' => $parentCategories,
'selectedStoreId' => $category->woo_store_id,
]);
}
public function update(Request $request, WooCategory $category): RedirectResponse
{
$category->load('store');
abort_if($category->store?->user_id !== $request->user()->id, 403);
$validated = $this->validateCategory($request);
$this->write->updateCategory($category, $validated);
return redirect()->route('woo.categories.index', ['store' => $category->woo_store_id])
->with('success', 'Category updated.');
}
public function destroy(Request $request, WooCategory $category): RedirectResponse
{
$category->load('store');
abort_if($category->store?->user_id !== $request->user()->id, 403);
$storeId = $category->woo_store_id;
$this->write->deleteCategory($category);
return redirect()->route('woo.categories.index', ['store' => $storeId])
->with('success', 'Category removed.');
}
public function sync(Request $request): RedirectResponse
{
$validated = $request->validate([
'store' => ['required', 'integer'],
]);
$store = $this->authorizedStore($request, (int) $validated['store']);
$count = $this->sync->syncCategories($store);
return back()->with('success', sprintf(
'Synced %d categories from %s.',
$count,
$store->site_name ?? $store->site_url,
));
}
/** @return array<string, mixed> */
private function validateCategory(Request $request): array
{
return $request->validate([
'woo_store_id' => ['required', 'integer'],
'name' => ['required', 'string', 'max:255'],
'slug' => ['nullable', 'string', 'max:255'],
'description' => ['nullable', 'string', 'max:10000'],
'parent_external_id' => ['nullable', 'integer', 'min:0'],
]);
}
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();
}
}
@@ -4,6 +4,8 @@ namespace App\Http\Controllers\Woo;
use App\Http\Controllers\Controller;
use App\Models\WooOrder;
use App\Models\WooProduct;
use App\Models\WooCategory;
use App\Models\WooStore;
use Illuminate\Http\Request;
use Illuminate\View\View;
@@ -22,6 +24,8 @@ class DashboardController extends Controller
WooOrder::FULFILLMENT_DELIVERED,
WooOrder::FULFILLMENT_CANCELLED,
])->count(),
'products' => WooProduct::query()->whereIn('woo_store_id', $storeIds)->count(),
'categories' => WooCategory::query()->whereIn('woo_store_id', $storeIds)->count(),
];
$recent = WooOrder::query()
@@ -0,0 +1,153 @@
<?php
namespace App\Http\Controllers\Woo;
use App\Http\Controllers\Controller;
use App\Models\WooProduct;
use App\Models\WooStore;
use App\Services\Woo\CatalogSyncService;
use App\Services\Woo\CatalogWriteService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\View\View;
class ProductController extends Controller
{
public function __construct(
private CatalogWriteService $write,
private CatalogSyncService $sync,
) {}
public function index(Request $request): View
{
$user = $request->user();
$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($statusFilter, fn ($q) => $q->where('status', $statusFilter))
->when($search !== '', function ($query) use ($search) {
$like = '%'.$search.'%';
$query->where(function ($inner) use ($like) {
$inner->where('name', 'like', $like)
->orWhere('sku', 'like', $like);
});
})
->with('store')
->latest('updated_at')
->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'));
}
public function create(Request $request): View
{
$stores = $this->activeStores($request);
return view('woo.products.form', [
'product' => new WooProduct(['status' => WooProduct::STATUS_DRAFT]),
'stores' => $stores,
'categories' => collect(),
]);
}
public function store(Request $request): RedirectResponse
{
$validated = $this->validateProduct($request);
$store = $this->authorizedStore($request, (int) $validated['woo_store_id']);
$this->write->createProduct($store, $validated);
return redirect()->route('woo.products.index', ['store' => $store->id])
->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);
$stores = $this->activeStores($request);
$categories = $product->store
? $product->store->categories()->orderBy('name')->get()
: collect();
return view('woo.products.form', compact('product', 'stores', 'categories'));
}
public function update(Request $request, WooProduct $product): RedirectResponse
{
$product->load('store');
abort_if($product->store?->user_id !== $request->user()->id, 403);
$validated = $this->validateProduct($request, $product);
$this->write->updateProduct($product, $validated);
return redirect()->route('woo.products.index', ['store' => $product->woo_store_id])
->with('success', 'Product updated.');
}
public function sync(Request $request): RedirectResponse
{
$validated = $request->validate([
'store' => ['required', 'integer'],
]);
$store = $this->authorizedStore($request, (int) $validated['store']);
$counts = $this->sync->syncAll($store);
return back()->with('success', sprintf(
'Synced %d categories and %d products from %s.',
$counts['categories'],
$counts['products'],
$store->site_name ?? $store->site_url,
));
}
/** @return array<string, mixed> */
private function validateProduct(Request $request, ?WooProduct $product = null): array
{
return $request->validate([
'woo_store_id' => ['required', 'integer'],
'name' => ['required', 'string', 'max:255'],
'sku' => ['nullable', 'string', 'max:120'],
'status' => ['required', Rule::in(array_keys(WooProduct::STATUSES))],
'regular_price' => ['nullable', 'numeric', 'min:0'],
'sale_price' => ['nullable', 'numeric', 'min:0'],
'manage_stock' => ['sometimes', 'boolean'],
'stock_quantity' => ['nullable', 'integer', 'min:0'],
'short_description' => ['nullable', 'string', 'max:5000'],
'description' => ['nullable', 'string', 'max:20000'],
'category_external_ids' => ['nullable', 'array'],
'category_external_ids.*' => ['integer', 'min:1'],
]);
}
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();
}
}
+51 -2
View File
@@ -3,7 +3,9 @@
namespace App\Http\Controllers;
use App\Models\WooStore;
use App\Services\Woo\CategoryIngestService;
use App\Services\Woo\OrderIngestService;
use App\Services\Woo\ProductIngestService;
use App\Services\Woo\WooWebhookVerifier;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -12,7 +14,9 @@ class WooWebhookController extends Controller
{
public function __construct(
private WooWebhookVerifier $verifier,
private OrderIngestService $ingest,
private OrderIngestService $orders,
private ProductIngestService $products,
private CategoryIngestService $categories,
) {}
public function __invoke(Request $request, string $storePublicId): JsonResponse
@@ -41,11 +45,56 @@ class WooWebhookController extends Controller
return response()->json(['ignored' => true]);
}
$order = $this->ingest->ingest($store, $payload);
return match (true) {
str_starts_with($topic, 'order.') => $this->handleOrder($store, $payload),
str_starts_with($topic, 'product_category.') => $this->handleCategory($store, $topic, $payload),
str_starts_with($topic, 'product.') => $this->handleProduct($store, $topic, $payload),
default => response()->json(['ignored' => true]),
};
}
/** @param array<string, mixed> $payload */
private function handleOrder(WooStore $store, array $payload): JsonResponse
{
$order = $this->orders->ingest($store, $payload);
return response()->json([
'ok' => true,
'order_id' => $order->id,
]);
}
/** @param array<string, mixed> $payload */
private function handleProduct(WooStore $store, string $topic, array $payload): JsonResponse
{
if ($topic === 'product.deleted') {
$this->products->delete($store, (int) ($payload['id'] ?? 0));
return response()->json(['ok' => true, 'deleted' => true]);
}
$product = $this->products->ingest($store, $payload);
return response()->json([
'ok' => true,
'product_id' => $product->id,
]);
}
/** @param array<string, mixed> $payload */
private function handleCategory(WooStore $store, string $topic, array $payload): JsonResponse
{
if ($topic === 'product_category.deleted') {
$this->categories->delete($store, (int) ($payload['id'] ?? 0));
return response()->json(['ok' => true, 'deleted' => true]);
}
$category = $this->categories->ingest($store, $payload);
return response()->json([
'ok' => true,
'category_id' => $category->id,
]);
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class WooCategory extends Model
{
protected $fillable = [
'woo_store_id',
'external_id',
'parent_external_id',
'name',
'slug',
'description',
'product_count',
'wc_updated_at',
'metadata',
];
protected $casts = [
'wc_updated_at' => 'datetime',
'metadata' => 'array',
];
public function store(): BelongsTo
{
return $this->belongsTo(WooStore::class, 'woo_store_id');
}
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_external_id', 'external_id')
->whereColumn('woo_store_id', 'woo_categories.woo_store_id');
}
public function parentLabel(): ?string
{
if (! $this->parent_external_id) {
return null;
}
return self::query()
->where('woo_store_id', $this->woo_store_id)
->where('external_id', $this->parent_external_id)
->value('name');
}
}
+92
View File
@@ -0,0 +1,92 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class WooProduct extends Model
{
public const STATUS_PUBLISH = 'publish';
public const STATUS_DRAFT = 'draft';
public const STATUS_PENDING = 'pending';
public const STATUS_PRIVATE = 'private';
public const STATUSES = [
self::STATUS_PUBLISH => 'Published',
self::STATUS_DRAFT => 'Draft',
self::STATUS_PENDING => 'Pending review',
self::STATUS_PRIVATE => 'Private',
];
protected $fillable = [
'woo_store_id',
'external_id',
'name',
'slug',
'sku',
'status',
'type',
'regular_price_minor',
'sale_price_minor',
'stock_quantity',
'manage_stock',
'category_external_ids',
'images',
'short_description',
'description',
'wc_updated_at',
'metadata',
];
protected $casts = [
'manage_stock' => 'boolean',
'category_external_ids' => 'array',
'images' => 'array',
'wc_updated_at' => 'datetime',
'metadata' => 'array',
];
public function store(): BelongsTo
{
return $this->belongsTo(WooStore::class, 'woo_store_id');
}
public function priceMinor(): ?int
{
return $this->sale_price_minor ?? $this->regular_price_minor;
}
public function priceFormatted(): string
{
$minor = $this->priceMinor();
if ($minor === null) {
return '—';
}
$currency = strtoupper((string) ($this->store?->metadata['currency'] ?? 'GHS'));
return $currency.' '.number_format($minor / 100, 2);
}
public function statusLabel(): string
{
return self::STATUSES[$this->status] ?? ucfirst((string) $this->status);
}
/** @return list<string> */
public function categoryNames(): array
{
$ids = array_filter((array) $this->category_external_ids);
if ($ids === []) {
return [];
}
return WooCategory::query()
->where('woo_store_id', $this->woo_store_id)
->whereIn('external_id', $ids)
->orderBy('name')
->pluck('name')
->all();
}
}
+10
View File
@@ -56,6 +56,16 @@ class WooStore extends Model
return $this->hasMany(WooOrder::class);
}
public function products(): HasMany
{
return $this->hasMany(WooProduct::class);
}
public function categories(): HasMany
{
return $this->hasMany(WooCategory::class);
}
public function webhookUrl(): string
{
return rtrim((string) config('app.url'), '/').'/webhooks/woocommerce/'.$this->public_id;
+70
View File
@@ -0,0 +1,70 @@
<?php
namespace App\Services\Woo;
use App\Models\WooStore;
class CatalogSyncService
{
public function __construct(
private PluginClient $client,
private ProductIngestService $products,
private CategoryIngestService $categories,
) {}
public function syncAll(WooStore $store): array
{
return [
'categories' => $this->syncCategories($store),
'products' => $this->syncProducts($store),
];
}
public function syncCategories(WooStore $store): int
{
$response = $this->client->get($store, 'categories', ['per_page' => 100]);
if (! is_array($response)) {
return 0;
}
$items = $response['data'] ?? $response;
if (! is_array($items)) {
return 0;
}
$count = 0;
foreach ($items as $item) {
if (! is_array($item)) {
continue;
}
$this->categories->ingest($store, $item);
$count++;
}
return $count;
}
public function syncProducts(WooStore $store): int
{
$response = $this->client->get($store, 'products', ['per_page' => 100]);
if (! is_array($response)) {
return 0;
}
$items = $response['data'] ?? $response;
if (! is_array($items)) {
return 0;
}
$count = 0;
foreach ($items as $item) {
if (! is_array($item)) {
continue;
}
$this->products->ingest($store, $item);
$count++;
}
return $count;
}
}
+219
View File
@@ -0,0 +1,219 @@
<?php
namespace App\Services\Woo;
use App\Models\WooCategory;
use App\Models\WooProduct;
use App\Models\WooStore;
class CatalogWriteService
{
public function __construct(
private PluginClient $client,
private ProductIngestService $productIngest,
private CategoryIngestService $categoryIngest,
) {}
/** @param array<string, mixed> $input */
public function createProduct(WooStore $store, array $input): WooProduct
{
$payload = $this->productPayload($input);
$response = $this->client->post($store, 'products', $payload);
if (is_array($response) && isset($response['id'])) {
return $this->productIngest->ingest($store, $response);
}
return $this->createLocalProduct($store, $payload);
}
/** @param array<string, mixed> $input */
public function updateProduct(WooProduct $product, array $input): WooProduct
{
$product->loadMissing('store');
$store = $product->store;
abort_if(! $store, 404);
$payload = $this->productPayload($input);
$response = $this->client->put($store, 'products/'.$product->external_id, $payload);
if (is_array($response) && isset($response['id'])) {
return $this->productIngest->ingest($store, $response);
}
$product->update($this->localProductAttributes($payload));
return $product->fresh();
}
/** @param array<string, mixed> $input */
public function createCategory(WooStore $store, array $input): WooCategory
{
$payload = $this->categoryPayload($input);
$response = $this->client->post($store, 'categories', $payload);
if (is_array($response) && isset($response['id'])) {
return $this->categoryIngest->ingest($store, $response);
}
return $this->createLocalCategory($store, $payload);
}
/** @param array<string, mixed> $input */
public function updateCategory(WooCategory $category, array $input): WooCategory
{
$category->loadMissing('store');
$store = $category->store;
abort_if(! $store, 404);
$payload = $this->categoryPayload($input);
$response = $this->client->put($store, 'categories/'.$category->external_id, $payload);
if (is_array($response) && isset($response['id'])) {
return $this->categoryIngest->ingest($store, $response);
}
$category->update($this->localCategoryAttributes($payload));
return $category->fresh();
}
public function deleteCategory(WooCategory $category): bool
{
$category->loadMissing('store');
$store = $category->store;
abort_if(! $store, 404);
if ($this->client->delete($store, 'categories/'.$category->external_id)) {
$category->delete();
return true;
}
$category->delete();
return true;
}
/** @param array<string, mixed> $input */
private function productPayload(array $input): array
{
$categories = collect($input['category_external_ids'] ?? [])
->map(fn ($id) => ['id' => (int) $id])
->filter(fn (array $row) => $row['id'] > 0)
->values()
->all();
return array_filter([
'name' => (string) ($input['name'] ?? ''),
'sku' => $input['sku'] ?? null,
'status' => (string) ($input['status'] ?? WooProduct::STATUS_DRAFT),
'regular_price' => $this->majorPrice($input['regular_price'] ?? null),
'sale_price' => $this->majorPrice($input['sale_price'] ?? null),
'manage_stock' => (bool) ($input['manage_stock'] ?? false),
'stock_quantity' => isset($input['stock_quantity']) ? (int) $input['stock_quantity'] : null,
'short_description' => $input['short_description'] ?? null,
'description' => $input['description'] ?? null,
'categories' => $categories,
], fn ($value) => $value !== null && $value !== '');
}
/** @param array<string, mixed> $input */
private function categoryPayload(array $input): array
{
$parent = (int) ($input['parent_external_id'] ?? 0);
return array_filter([
'name' => (string) ($input['name'] ?? ''),
'slug' => $input['slug'] ?? null,
'description' => $input['description'] ?? null,
'parent' => $parent > 0 ? $parent : 0,
], fn ($value) => $value !== null && $value !== '');
}
/** @param array<string, mixed> $payload */
private function createLocalProduct(WooStore $store, array $payload): WooProduct
{
$externalId = (int) (WooProduct::query()->where('woo_store_id', $store->id)->max('external_id') ?? 0) + 1;
return WooProduct::query()->create(array_merge(
$this->localProductAttributes($payload),
[
'woo_store_id' => $store->id,
'external_id' => $externalId,
'slug' => \Illuminate\Support\Str::slug((string) ($payload['name'] ?? 'product')).'-'.$externalId,
],
));
}
/** @param array<string, mixed> $payload */
private function createLocalCategory(WooStore $store, array $payload): WooCategory
{
$externalId = (int) (WooCategory::query()->where('woo_store_id', $store->id)->max('external_id') ?? 0) + 1;
$parent = (int) ($payload['parent'] ?? 0);
return WooCategory::query()->create(array_merge(
$this->localCategoryAttributes($payload),
[
'woo_store_id' => $store->id,
'external_id' => $externalId,
'parent_external_id' => $parent > 0 ? $parent : null,
'slug' => (string) ($payload['slug'] ?? \Illuminate\Support\Str::slug((string) ($payload['name'] ?? 'category')).'-'.$externalId),
],
));
}
/** @param array<string, mixed> $payload */
private function localProductAttributes(array $payload): array
{
$categoryIds = collect($payload['categories'] ?? [])
->map(fn (array $row) => (int) ($row['id'] ?? 0))
->filter(fn (int $id) => $id > 0)
->values()
->all();
return [
'name' => (string) ($payload['name'] ?? 'Product'),
'sku' => $payload['sku'] ?? null,
'status' => (string) ($payload['status'] ?? WooProduct::STATUS_DRAFT),
'regular_price_minor' => $this->minorPrice($payload['regular_price'] ?? null),
'sale_price_minor' => $this->minorPrice($payload['sale_price'] ?? null),
'manage_stock' => (bool) ($payload['manage_stock'] ?? false),
'stock_quantity' => isset($payload['stock_quantity']) ? (int) $payload['stock_quantity'] : null,
'short_description' => $payload['short_description'] ?? null,
'description' => $payload['description'] ?? null,
'category_external_ids' => $categoryIds,
];
}
/** @param array<string, mixed> $payload */
private function localCategoryAttributes(array $payload): array
{
$parent = (int) ($payload['parent'] ?? 0);
return [
'name' => (string) ($payload['name'] ?? 'Category'),
'slug' => (string) ($payload['slug'] ?? \Illuminate\Support\Str::slug((string) ($payload['name'] ?? 'category'))),
'description' => $payload['description'] ?? null,
'parent_external_id' => $parent > 0 ? $parent : null,
];
}
private function majorPrice(mixed $value): ?string
{
if ($value === null || $value === '') {
return null;
}
return number_format(((float) $value), 2, '.', '');
}
private function minorPrice(mixed $value): ?int
{
if ($value === null || $value === '') {
return null;
}
return (int) round(((float) $value) * 100);
}
}
@@ -0,0 +1,62 @@
<?php
namespace App\Services\Woo;
use App\Models\WooCategory;
use App\Models\WooStore;
use Carbon\Carbon;
class CategoryIngestService
{
/** @param array<string, mixed> $payload */
public function ingest(WooStore $store, array $payload): WooCategory
{
$externalId = (int) ($payload['id'] ?? 0);
if ($externalId === 0) {
throw new \InvalidArgumentException('WooCommerce category id missing.');
}
$parent = (int) ($payload['parent'] ?? 0);
return WooCategory::query()->updateOrCreate(
[
'woo_store_id' => $store->id,
'external_id' => $externalId,
],
[
'parent_external_id' => $parent > 0 ? $parent : null,
'name' => (string) ($payload['name'] ?? 'Category'),
'slug' => (string) ($payload['slug'] ?? 'category-'.$externalId),
'description' => $this->nullableString($payload['description'] ?? null),
'product_count' => max(0, (int) ($payload['count'] ?? 0)),
'wc_updated_at' => $this->updatedAt($payload),
'metadata' => [
'image' => $payload['image'] ?? null,
],
],
);
}
public function delete(WooStore $store, int $externalId): void
{
WooCategory::query()
->where('woo_store_id', $store->id)
->where('external_id', $externalId)
->delete();
}
/** @param array<string, mixed> $payload */
private function updatedAt(array $payload): ?Carbon
{
$raw = $payload['date_modified_gmt'] ?? $payload['date_modified'] ?? null;
return is_string($raw) && $raw !== '' ? Carbon::parse($raw) : null;
}
private function nullableString(mixed $value): ?string
{
$text = trim((string) $value);
return $text === '' ? null : $text;
}
}
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace App\Services\Woo;
use App\Models\WooStore;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class PluginClient
{
/** @return array<string, mixed>|null */
public function get(WooStore $store, string $path, array $query = []): ?array
{
return $this->request($store, 'GET', $path, $query);
}
/** @param array<string, mixed> $payload */
public function post(WooStore $store, string $path, array $payload = []): ?array
{
return $this->request($store, 'POST', $path, $payload);
}
/** @param array<string, mixed> $payload */
public function put(WooStore $store, string $path, array $payload = []): ?array
{
return $this->request($store, 'PUT', $path, $payload);
}
public function delete(WooStore $store, string $path): bool
{
return $this->raw($store, 'DELETE', $path)->successful();
}
/** @return array<string, mixed>|null */
private function request(WooStore $store, string $method, string $path, array $data = []): ?array
{
$response = $this->raw($store, $method, $path, $data);
if (! $response->successful()) {
Log::warning('Woo plugin API request failed', [
'store_id' => $store->id,
'method' => $method,
'path' => $path,
'status' => $response->status(),
]);
return null;
}
/** @var array<string, mixed>|null $json */
$json = $response->json();
return is_array($json) ? $json : null;
}
private function raw(WooStore $store, string $method, string $path, array $data = []): Response
{
$site = rtrim((string) $store->site_url, '/');
$url = $site.'/wp-json/ladill-woo/v1/'.ltrim($path, '/');
$pending = Http::acceptJson()
->timeout(20)
->withHeaders(['X-Ladill-Store' => $store->public_id]);
return match (strtoupper($method)) {
'GET' => $pending->get($url, $data),
'POST' => $pending->asJson()->post($url, $data),
'PUT' => $pending->asJson()->put($url, $data),
'DELETE' => $pending->delete($url, $data),
default => throw new \InvalidArgumentException("Unsupported method: {$method}"),
};
}
}
+97
View File
@@ -0,0 +1,97 @@
<?php
namespace App\Services\Woo;
use App\Models\WooProduct;
use App\Models\WooStore;
use Carbon\Carbon;
class ProductIngestService
{
/** @param array<string, mixed> $payload */
public function ingest(WooStore $store, array $payload): WooProduct
{
$externalId = (int) ($payload['id'] ?? 0);
if ($externalId === 0) {
throw new \InvalidArgumentException('WooCommerce product id missing.');
}
$regular = $this->priceMinor($payload['regular_price'] ?? null);
$sale = $this->priceMinor($payload['sale_price'] ?? null);
$images = collect((array) ($payload['images'] ?? []))
->map(fn (array $image) => [
'id' => (int) ($image['id'] ?? 0),
'src' => (string) ($image['src'] ?? ''),
'alt' => (string) ($image['alt'] ?? ''),
])
->filter(fn (array $image) => $image['src'] !== '')
->values()
->all();
$categoryIds = collect((array) ($payload['categories'] ?? []))
->map(fn (array $category) => (int) ($category['id'] ?? 0))
->filter(fn (int $id) => $id > 0)
->values()
->all();
return WooProduct::query()->updateOrCreate(
[
'woo_store_id' => $store->id,
'external_id' => $externalId,
],
[
'name' => (string) ($payload['name'] ?? 'Product'),
'slug' => (string) ($payload['slug'] ?? 'product-'.$externalId),
'sku' => $this->nullableString($payload['sku'] ?? null),
'status' => (string) ($payload['status'] ?? WooProduct::STATUS_DRAFT),
'type' => (string) ($payload['type'] ?? 'simple'),
'regular_price_minor' => $regular,
'sale_price_minor' => $sale,
'stock_quantity' => isset($payload['stock_quantity']) ? (int) $payload['stock_quantity'] : null,
'manage_stock' => (bool) ($payload['manage_stock'] ?? false),
'category_external_ids' => $categoryIds,
'images' => $images,
'short_description' => $this->nullableString($payload['short_description'] ?? null),
'description' => $this->nullableString($payload['description'] ?? null),
'wc_updated_at' => $this->updatedAt($payload),
'metadata' => [
'permalink' => $payload['permalink'] ?? null,
'featured' => (bool) ($payload['featured'] ?? false),
],
],
);
}
public function delete(WooStore $store, int $externalId): void
{
WooProduct::query()
->where('woo_store_id', $store->id)
->where('external_id', $externalId)
->delete();
}
private function priceMinor(mixed $value): ?int
{
if ($value === null || $value === '') {
return null;
}
return (int) round(((float) $value) * 100);
}
/** @param array<string, mixed> $payload */
private function updatedAt(array $payload): ?Carbon
{
$raw = $payload['date_modified_gmt'] ?? $payload['date_modified'] ?? null;
return is_string($raw) && $raw !== '' ? Carbon::parse($raw) : null;
}
private function nullableString(mixed $value): ?string
{
$text = trim(strip_tags((string) $value));
return $text === '' ? null : $text;
}
}
+1
View File
@@ -22,6 +22,7 @@ return [
['name' => 'POS', 'url' => 'https://pos.'.$root.'/sso/connect?redirect='.urlencode('https://pos.'.$root.'/dashboard'), 'icon' => 'pos.svg'],
['name' => 'Mini', 'url' => 'https://mini.'.$root.'/sso/connect?redirect='.urlencode('https://mini.'.$root.'/dashboard'), 'icon' => 'mini.svg'],
['name' => 'Give', 'url' => 'https://give.'.$root.'/sso/connect?redirect='.urlencode('https://give.'.$root.'/dashboard'), 'icon' => 'give.svg'],
['name' => 'Woo Manager', 'url' => 'https://woo.'.$root.'/sso/connect?redirect='.urlencode('https://woo.'.$root.'/dashboard'), 'icon' => 'woo.svg'],
['name' => 'Transfer', 'url' => 'https://transfer.'.$root.'/sso/connect?redirect='.urlencode('https://transfer.'.$root.'/dashboard'), 'icon' => 'transfer.svg'],
['name' => 'Accounting', 'url' => 'https://accounting.'.$root.'/sso/connect?redirect='.urlencode('https://accounting.'.$root.'/dashboard'), 'icon' => 'accounting.svg'],
['name' => 'Invoice', 'url' => 'https://invoice.'.$root.'/sso/connect?redirect='.urlencode('https://invoice.'.$root.'/dashboard'), 'icon' => 'invoice.svg'],
+10 -1
View File
@@ -4,5 +4,14 @@ return [
'plugin_client_id' => env('WOO_MANAGER_PLUGIN_CLIENT_ID'),
'plugin_client_secret' => env('WOO_MANAGER_PLUGIN_CLIENT_SECRET'),
'install_token_ttl_minutes' => (int) env('WOO_INSTALL_TOKEN_TTL', 10),
'webhook_topics' => ['order.created', 'order.updated'],
'webhook_topics' => [
'order.created',
'order.updated',
'product.created',
'product.updated',
'product.deleted',
'product_category.created',
'product_category.updated',
'product_category.deleted',
],
];
@@ -0,0 +1,60 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('woo_categories', function (Blueprint $table) {
$table->id();
$table->foreignId('woo_store_id')->constrained('woo_stores')->cascadeOnDelete();
$table->unsignedBigInteger('external_id');
$table->unsignedBigInteger('parent_external_id')->nullable();
$table->string('name');
$table->string('slug');
$table->text('description')->nullable();
$table->unsignedInteger('product_count')->default(0);
$table->timestamp('wc_updated_at')->nullable();
$table->json('metadata')->nullable();
$table->timestamps();
$table->unique(['woo_store_id', 'external_id']);
$table->index(['woo_store_id', 'parent_external_id']);
});
Schema::create('woo_products', function (Blueprint $table) {
$table->id();
$table->foreignId('woo_store_id')->constrained('woo_stores')->cascadeOnDelete();
$table->unsignedBigInteger('external_id');
$table->string('name');
$table->string('slug');
$table->string('sku')->nullable();
$table->string('status')->default('draft');
$table->string('type')->default('simple');
$table->unsignedBigInteger('regular_price_minor')->nullable();
$table->unsignedBigInteger('sale_price_minor')->nullable();
$table->integer('stock_quantity')->nullable();
$table->boolean('manage_stock')->default(false);
$table->json('category_external_ids')->nullable();
$table->json('images')->nullable();
$table->text('short_description')->nullable();
$table->text('description')->nullable();
$table->timestamp('wc_updated_at')->nullable();
$table->json('metadata')->nullable();
$table->timestamps();
$table->unique(['woo_store_id', 'external_id']);
$table->index(['woo_store_id', 'status']);
$table->index(['woo_store_id', 'sku']);
});
}
public function down(): void
{
Schema::dropIfExists('woo_products');
Schema::dropIfExists('woo_categories');
}
};
+24 -27
View File
@@ -1,49 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 629.8 76.2">
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 479.7 75.3">
<defs>
<style>
.cls-1 {
fill: #a277ff;
fill: #33669a;
}
.cls-1, .cls-2, .cls-3, .cls-4 {
.cls-1, .cls-2, .cls-3, .cls-4, .cls-5 {
stroke-width: 0px;
}
.cls-2 {
fill: #b6362f;
fill: #ffd05a;
}
.cls-3 {
fill: #000;
fill: #f16667;
}
.cls-4 {
fill: #0091ac;
fill: #000;
}
.cls-5 {
fill: #319966;
}
</style>
</defs>
<g>
<path class="cls-3" d="M165.4,53.9v8.6h-34.8V12.2h8.6v41.8h26.2Z"/>
<path class="cls-3" d="M169.1,44.5c0-2.7.5-5.3,1.5-7.7s2.4-4.4,4.2-6.2,3.9-3.1,6.2-4.2c2.4-1,4.9-1.5,7.7-1.5s5.3.5,7.7,1.5,4.4,2.4,6.2,4.2c1.8,1.8,3.1,3.8,4.2,6.2,1,2.4,1.5,4.9,1.5,7.7v18.1h-8.4v-2c-3.3,2.4-7.1,3.5-11.2,3.5s-5.7-.5-8.1-1.5-4.5-2.4-6.2-4.2-3-3.9-4-6.2c-.9-2.4-1.4-4.9-1.4-7.7,0,0,.1,0,.1,0ZM177.5,44.5c0,1.5.3,3,.9,4.4s1.4,2.6,2.4,3.6,2.2,1.8,3.6,2.4c1.4.6,2.8.9,4.4.9s3-.3,4.4-.8c1.4-.6,2.6-1.3,3.6-2.3s1.8-2.2,2.4-3.6c.6-1.4.9-2.9.9-4.5s-.3-3-.9-4.4c-.6-1.4-1.4-2.6-2.4-3.6s-2.2-1.8-3.6-2.4c-1.4-.6-2.8-.9-4.4-.9s-3,.3-4.4.9-2.6,1.4-3.6,2.4-1.8,2.2-2.4,3.6c-.6,1.4-.9,2.8-.9,4.4h0Z"/>
<path class="cls-3" d="M252.2,44.5c0,2.8-.5,5.4-1.5,7.7-1,2.4-2.4,4.4-4.2,6.2s-3.9,3.1-6.2,4.1-4.9,1.5-7.7,1.5-5.3-.5-7.7-1.5-4.4-2.4-6.2-4.2-3.1-3.8-4.2-6.2c-1-2.4-1.5-4.9-1.5-7.7s.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" y="0" width="43.2" height="24.7" rx="12.3" ry="12.3"/>
<rect class="cls-2" x="18.4" y="0" width="24.8" height="74.8" rx="12.4" ry="12.4"/>
<rect class="cls-5" x="43.5" y="-9.7" width="24.8" height="95.2" rx="12.4" ry="12.4" transform="translate(43.2 -28.4) rotate(45)"/>
<rect class="cls-1" x="68.6" y=".5" width="24.8" height="74.8" rx="12.4" ry="12.4"/>
<rect class="cls-3" x="93.3" y="-9.1" width="24.8" height="94.6" rx="12.4" ry="12.4" transform="translate(58 -63.5) rotate(45)"/>
<path class="cls-4" d="M370.4,40.1l-16.1,22h-5V11.7h5v41.8l16.1-21.9,16.2,22V11.7h5v50.4h-5l-16.2-22Z"/>
<path class="cls-4" d="M396.3,44c0-2.7.5-5.3,1.5-7.7,1-2.4,2.4-4.5,4.2-6.3,1.8-1.8,3.9-3.2,6.3-4.2,2.4-1,5-1.5,7.7-1.5s5.3.5,7.7,1.5c2.4,1,4.5,2.4,6.3,4.2,1.8,1.8,3.2,3.9,4.2,6.3,1,2.4,1.5,5,1.5,7.7s-.5,5.3-1.5,7.7c-1,2.4-2.4,4.5-4.2,6.3-1.8,1.8-3.9,3.2-6.3,4.2-2.4,1-5,1.5-7.7,1.5s-5.3-.5-7.7-1.5c-2.4-1-4.5-2.4-6.3-4.2-1.8-1.8-3.2-3.9-4.2-6.3-1-2.4-1.5-5-1.5-7.7ZM401.3,44c0,2,.4,3.9,1.2,5.7.8,1.8,1.8,3.4,3.2,4.7,1.3,1.3,2.9,2.4,4.7,3.2,1.8.8,3.7,1.2,5.7,1.2s3.9-.4,5.7-1.2c1.8-.8,3.4-1.8,4.7-3.2,1.3-1.3,2.4-2.9,3.2-4.7.8-1.8,1.2-3.7,1.2-5.7s-.4-3.9-1.2-5.7c-.8-1.8-1.8-3.4-3.2-4.7-1.3-1.3-2.9-2.4-4.7-3.2-1.8-.8-3.7-1.2-5.7-1.2s-3.9.4-5.7,1.2c-1.8.8-3.4,1.8-4.7,3.2-1.3,1.3-2.4,2.9-3.2,4.7-.8,1.8-1.2,3.7-1.2,5.7Z"/>
<path class="cls-4" d="M439.7,44c0-2.7.5-5.3,1.5-7.7,1-2.4,2.4-4.5,4.2-6.3,1.8-1.8,3.9-3.2,6.3-4.2,2.4-1,5-1.5,7.7-1.5s5.3.5,7.7,1.5c2.4,1,4.5,2.4,6.3,4.2,1.8,1.8,3.2,3.9,4.2,6.3,1,2.4,1.5,5,1.5,7.7s-.5,5.3-1.5,7.7c-1,2.4-2.4,4.5-4.2,6.3-1.8,1.8-3.9,3.2-6.3,4.2-2.4,1-5,1.5-7.7,1.5s-5.3-.5-7.7-1.5c-2.4-1-4.5-2.4-6.3-4.2-1.8-1.8-3.2-3.9-4.2-6.3-1-2.4-1.5-5-1.5-7.7ZM444.8,44c0,2,.4,3.9,1.2,5.7.8,1.8,1.8,3.4,3.2,4.7,1.3,1.3,2.9,2.4,4.7,3.2,1.8.8,3.7,1.2,5.7,1.2s3.9-.4,5.7-1.2c1.8-.8,3.4-1.8,4.7-3.2,1.3-1.3,2.4-2.9,3.2-4.7.8-1.8,1.2-3.7,1.2-5.7s-.4-3.9-1.2-5.7c-.8-1.8-1.8-3.4-3.2-4.7-1.3-1.3-2.9-2.4-4.7-3.2-1.8-.8-3.7-1.2-5.7-1.2s-3.9.4-5.7,1.2c-1.8.8-3.4,1.8-4.7,3.2-1.3,1.3-2.4,2.9-3.2,4.7-.8,1.8-1.2,3.7-1.2,5.7Z"/>
</svg>

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

@@ -10,6 +10,10 @@
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12 11.2 3.05c.44-.44 1.15-.44 1.59 0L21.75 12M4.5 9.75v10.5a.75.75 0 0 0 .75.75H9.75v-6a.75.75 0 0 1 .75-.75h3a.75.75 0 0 1 .75.75v6h4.5a.75.75 0 0 0 .75-.75V9.75" />'],
['name' => 'Orders', 'route' => route('woo.orders.index'), 'active' => request()->routeIs('woo.orders.*'),
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M9 12h3.75M9 15h3.75M9 18h3.75m3 .75H18a2.25 2.25 0 0 0 2.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 0 0-1.123-.08m-5.801 0c-.065.21-.1.433-.1.664 0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75 2.25 2.25 0 0 0-.1-.664m-5.8 0A2.251 2.251 0 0 1 13.5 2.25H15c1.012 0 1.867.668 2.15 1.586m-5.8 0c-.376.023-.75.05-1.124.08C9.095 4.01 8.25 4.973 8.25 6.108V8.25m0 0H4.875c-.621 0-1.125.504-1.125 1.125v11.25c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V9.375c0-.621-.504-1.125-1.125-1.125H8.25ZM6.75 12h.008v.008H6.75V12Zm0 3h.008v.008H6.75V15Zm0 3h.008v.008H6.75V18Z" />'],
['name' => 'Products', 'route' => route('woo.products.index'), 'active' => request()->routeIs('woo.products.*'),
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M20.25 7.5l-.625 10.632a2.25 2.25 0 0 1-2.247 2.118H6.622a2.25 2.25 0 0 1-2.247-2.118L3.75 7.5M10 11.25h4M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125Z" />'],
['name' => 'Categories', 'route' => route('woo.categories.index'), 'active' => request()->routeIs('woo.categories.*'),
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M9.568 3H5.25A2.25 2.25 0 0 0 3 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 0 0 5.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 0 0 9.568 3Z" /><path stroke-linecap="round" stroke-linejoin="round" d="M6 6h.008v.008H6V6Z" />'],
['name' => 'Stores', 'route' => route('woo.stores.index'), 'active' => request()->routeIs('woo.stores.*'),
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M13.5 21v-7.5a.75.75 0 0 1 .75-.75h3a.75.75 0 0 1 .75.75V21m-4.5 0H2.36m11.14 0H18m0 0h3.64m-1.39 0V9.349M3.75 21V9.349m0 0a3.001 3.001 0 0 0 3.75-.615A2.993 2.993 0 0 0 9.75 9.75c.896 0 1.7-.393 2.25-1.016a2.993 2.993 0 0 0 2.25 1.016c.896 0 1.7-.393 2.25-1.016a3.001 3.001 0 0 0 3.75.614m-16.5 0a3.004 3.004 0 0 1-.621-4.72L4.318 3.44A1.5 1.5 0 0 1 5.378 3h13.243a1.5 1.5 0 0 1 1.06.44l1.19 1.189a3 3 0 0 1-.621 4.72M6.75 18h3.75a.75.75 0 0 0 .75-.75V13.5a.75.75 0 0 0-.75-.75H6.75a.75.75 0 0 0-.75.75v3.75c0 .414.336.75.75.75Z" />'],
];
@@ -0,0 +1,62 @@
<x-user-layout>
<x-slot name="title">{{ $category->exists ? 'Edit category' : 'New category' }}</x-slot>
<div class="mx-auto max-w-2xl space-y-6">
<div>
<h1 class="text-xl font-semibold text-slate-900">{{ $category->exists ? 'Edit category' : 'New category' }}</h1>
<p class="mt-1 text-sm text-slate-500">Changes sync to WooCommerce when the Ladill plugin is connected.</p>
</div>
<form method="post" action="{{ $category->exists ? route('woo.categories.update', $category) : route('woo.categories.store') }}" class="space-y-6 rounded-2xl border border-slate-200 bg-white p-6">
@csrf
@if($category->exists) @method('patch') @endif
<div>
<label class="block text-sm font-medium text-slate-700">Store</label>
<select name="woo_store_id" required class="mt-1 w-full rounded-xl border-slate-200 text-sm" @disabled($category->exists)>
@foreach($stores as $store)
<option value="{{ $store->id }}" @selected(old('woo_store_id', $selectedStoreId) == $store->id)>{{ $store->site_name ?? $store->site_url }}</option>
@endforeach
</select>
</div>
<div>
<label class="block text-sm font-medium text-slate-700">Name</label>
<input type="text" name="name" value="{{ old('name', $category->name) }}" required class="mt-1 w-full rounded-xl border-slate-200 text-sm">
</div>
<div>
<label class="block text-sm font-medium text-slate-700">Slug</label>
<input type="text" name="slug" value="{{ old('slug', $category->slug) }}" class="mt-1 w-full rounded-xl border-slate-200 text-sm" placeholder="auto-generated if blank">
</div>
@if($parentCategories->isNotEmpty())
<div>
<label class="block text-sm font-medium text-slate-700">Parent category</label>
<select name="parent_external_id" class="mt-1 w-full rounded-xl border-slate-200 text-sm">
<option value="">None</option>
@foreach($parentCategories as $parent)
<option value="{{ $parent->external_id }}" @selected((string) old('parent_external_id', $category->parent_external_id) === (string) $parent->external_id)>{{ $parent->name }}</option>
@endforeach
</select>
</div>
@endif
<div>
<label class="block text-sm font-medium text-slate-700">Description</label>
<textarea name="description" rows="4" class="mt-1 w-full rounded-xl border-slate-200 text-sm">{{ old('description', $category->description) }}</textarea>
</div>
<div class="flex items-center justify-end gap-3">
<a href="{{ route('woo.categories.index') }}" class="text-sm font-medium text-slate-600 hover:text-slate-900">Cancel</a>
<button type="submit" class="rounded-xl bg-indigo-600 px-4 py-2 text-sm font-semibold text-white hover:bg-indigo-700">Save category</button>
</div>
</form>
@if($category->exists)
<form method="post" action="{{ route('woo.categories.destroy', $category) }}" onsubmit="return confirm('Remove this category?')" class="rounded-2xl border border-red-100 bg-red-50 p-4">
@csrf @method('delete')
<button type="submit" class="text-sm font-medium text-red-700 hover:text-red-900">Delete category</button>
</form>
@endif
</div>
</x-user-layout>
@@ -0,0 +1,73 @@
<x-user-layout>
<x-slot name="title">Categories</x-slot>
<div class="space-y-6">
<div class="flex flex-wrap items-start justify-between gap-4">
<div>
<h1 class="text-xl font-semibold text-slate-900">Categories</h1>
<p class="mt-1 text-sm text-slate-500">Organize products with WooCommerce categories.</p>
</div>
<div class="flex flex-wrap items-center gap-2">
@if($stores->isNotEmpty())
<form method="post" action="{{ route('woo.categories.sync') }}">
@csrf
<input type="hidden" name="store" value="{{ $storeFilter ?: $stores->first()->id }}">
<button type="submit" class="rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">Sync from store</button>
</form>
@endif
<a href="{{ route('woo.categories.create', ['store' => $storeFilter]) }}" class="rounded-xl bg-indigo-600 px-4 py-2 text-sm font-semibold text-white hover:bg-indigo-700">New category</a>
</div>
</div>
<form method="get" class="flex flex-wrap items-end gap-3">
<div class="min-w-[12rem] flex-1 max-w-md">
<input type="search" name="q" value="{{ $search }}" placeholder="Search categories…"
class="w-full rounded-xl border-slate-200 text-sm focus:border-indigo-500 focus:ring-indigo-500">
</div>
@if($stores->isNotEmpty())
<select name="store" class="rounded-xl border-slate-200 text-sm" onchange="this.form.submit()">
<option value="">All stores</option>
@foreach($stores as $store)
<option value="{{ $store->id }}" @selected((string) $storeFilter === (string) $store->id)>{{ $store->site_name ?? $store->site_url }}</option>
@endforeach
</select>
@endif
</form>
<div class="overflow-hidden rounded-2xl border border-slate-200 bg-white">
@if($categories->isEmpty())
<p class="px-6 py-10 text-sm text-slate-500">No categories yet. Sync from a connected store or create one here.</p>
@else
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-slate-100 text-sm">
<thead class="bg-slate-50 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">
<tr>
<th class="px-6 py-3">Category</th>
<th class="px-6 py-3">Store</th>
<th class="px-6 py-3">Parent</th>
<th class="px-6 py-3">Products</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@foreach($categories as $category)
<tr>
<td class="px-6 py-4">
<p class="font-medium text-slate-900">{{ $category->name }}</p>
<p class="text-xs text-slate-500">{{ $category->slug }}</p>
</td>
<td class="px-6 py-4 text-slate-600">{{ $category->store?->site_name ?? parse_url($category->store?->site_url ?? '', PHP_URL_HOST) }}</td>
<td class="px-6 py-4 text-slate-600">{{ $category->parentLabel() ?: '—' }}</td>
<td class="px-6 py-4 text-slate-600">{{ $category->product_count }}</td>
<td class="px-6 py-4 text-right">
<a href="{{ route('woo.categories.edit', $category) }}" class="font-medium text-indigo-600 hover:text-indigo-800">Edit</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@if($categories->hasPages())<div class="border-t border-slate-100 px-6 py-4">{{ $categories->links() }}</div>@endif
@endif
</div>
</div>
</x-user-layout>
+9 -1
View File
@@ -6,11 +6,19 @@
<p class="mt-1 text-sm text-slate-500">Fulfill WooCommerce orders from Ladill payments stay in your store.</p>
</div>
<div class="grid gap-4 sm:grid-cols-3">
<div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-5">
<div class="rounded-2xl border border-slate-200 bg-white p-5">
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Connected stores</p>
<p class="mt-2 text-3xl font-bold text-slate-900">{{ $stats['stores'] }}</p>
</div>
<div class="rounded-2xl border border-slate-200 bg-white p-5">
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Products</p>
<p class="mt-2 text-3xl font-bold text-slate-900">{{ $stats['products'] }}</p>
</div>
<div class="rounded-2xl border border-slate-200 bg-white p-5">
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Categories</p>
<p class="mt-2 text-3xl font-bold text-slate-900">{{ $stats['categories'] }}</p>
</div>
<div class="rounded-2xl border border-slate-200 bg-white p-5">
<p class="text-xs font-semibold uppercase tracking-wide text-slate-500">New orders</p>
<p class="mt-2 text-3xl font-bold text-slate-900">{{ $stats['orders_new'] }}</p>
@@ -0,0 +1,91 @@
<x-user-layout>
<x-slot name="title">{{ $product->exists ? 'Edit product' : 'New product' }}</x-slot>
<div class="mx-auto max-w-3xl space-y-6">
<div>
<h1 class="text-xl font-semibold text-slate-900">{{ $product->exists ? 'Edit product' : 'New product' }}</h1>
<p class="mt-1 text-sm text-slate-500">Changes sync to WooCommerce when the Ladill plugin is connected.</p>
</div>
<form method="post" action="{{ $product->exists ? route('woo.products.update', $product) : route('woo.products.store') }}" class="space-y-6 rounded-2xl border border-slate-200 bg-white p-6">
@csrf
@if($product->exists) @method('patch') @endif
<div>
<label class="block text-sm font-medium text-slate-700">Store</label>
<select name="woo_store_id" required class="mt-1 w-full rounded-xl border-slate-200 text-sm" @disabled($product->exists)>
@foreach($stores as $store)
<option value="{{ $store->id }}" @selected(old('woo_store_id', $product->woo_store_id) == $store->id)>{{ $store->site_name ?? $store->site_url }}</option>
@endforeach
</select>
</div>
<div>
<label class="block text-sm font-medium text-slate-700">Name</label>
<input type="text" name="name" value="{{ old('name', $product->name) }}" required class="mt-1 w-full rounded-xl border-slate-200 text-sm">
</div>
<div class="grid gap-4 sm:grid-cols-2">
<div>
<label class="block text-sm font-medium text-slate-700">SKU</label>
<input type="text" name="sku" value="{{ old('sku', $product->sku) }}" class="mt-1 w-full rounded-xl border-slate-200 text-sm">
</div>
<div>
<label class="block text-sm font-medium text-slate-700">Status</label>
<select name="status" class="mt-1 w-full rounded-xl border-slate-200 text-sm">
@foreach(\App\Models\WooProduct::STATUSES as $val => $label)
<option value="{{ $val }}" @selected(old('status', $product->status ?: 'draft') === $val)>{{ $label }}</option>
@endforeach
</select>
</div>
</div>
<div class="grid gap-4 sm:grid-cols-2">
<div>
<label class="block text-sm font-medium text-slate-700">Regular price</label>
<input type="number" step="0.01" min="0" name="regular_price" value="{{ old('regular_price', $product->regular_price_minor !== null ? $product->regular_price_minor / 100 : '') }}" class="mt-1 w-full rounded-xl border-slate-200 text-sm">
</div>
<div>
<label class="block text-sm font-medium text-slate-700">Sale price</label>
<input type="number" step="0.01" min="0" name="sale_price" value="{{ old('sale_price', $product->sale_price_minor !== null ? $product->sale_price_minor / 100 : '') }}" class="mt-1 w-full rounded-xl border-slate-200 text-sm">
</div>
</div>
<div class="grid gap-4 sm:grid-cols-2">
<label class="flex items-center gap-2 text-sm text-slate-700">
<input type="checkbox" name="manage_stock" value="1" @checked(old('manage_stock', $product->manage_stock)) class="rounded border-slate-300 text-indigo-600">
Track stock quantity
</label>
<div>
<label class="block text-sm font-medium text-slate-700">Stock quantity</label>
<input type="number" min="0" name="stock_quantity" value="{{ old('stock_quantity', $product->stock_quantity) }}" class="mt-1 w-full rounded-xl border-slate-200 text-sm">
</div>
</div>
@if($categories->isNotEmpty())
<div>
<label class="block text-sm font-medium text-slate-700">Categories</label>
<select name="category_external_ids[]" multiple class="mt-1 w-full rounded-xl border-slate-200 text-sm" size="5">
@foreach($categories as $category)
<option value="{{ $category->external_id }}" @selected(collect(old('category_external_ids', $product->category_external_ids ?? []))->contains($category->external_id))>{{ $category->name }}</option>
@endforeach
</select>
</div>
@endif
<div>
<label class="block text-sm font-medium text-slate-700">Short description</label>
<textarea name="short_description" rows="3" class="mt-1 w-full rounded-xl border-slate-200 text-sm">{{ old('short_description', $product->short_description) }}</textarea>
</div>
<div>
<label class="block text-sm font-medium text-slate-700">Description</label>
<textarea name="description" rows="6" class="mt-1 w-full rounded-xl border-slate-200 text-sm">{{ old('description', $product->description) }}</textarea>
</div>
<div class="flex items-center justify-end gap-3">
<a href="{{ route('woo.products.index') }}" class="text-sm font-medium text-slate-600 hover:text-slate-900">Cancel</a>
<button type="submit" class="rounded-xl bg-indigo-600 px-4 py-2 text-sm font-semibold text-white hover:bg-indigo-700">Save product</button>
</div>
</form>
</div>
</x-user-layout>
@@ -0,0 +1,91 @@
<x-user-layout>
<x-slot name="title">Products</x-slot>
<div class="space-y-6">
<div class="flex flex-wrap items-start justify-between gap-4">
<div>
<h1 class="text-xl font-semibold text-slate-900">Products</h1>
<p class="mt-1 text-sm text-slate-500">Manage WooCommerce products synced from your connected stores.</p>
</div>
<div class="flex flex-wrap items-center gap-2">
@if($stores->isNotEmpty())
<form method="post" action="{{ route('woo.products.sync') }}">
@csrf
<input type="hidden" name="store" value="{{ $storeFilter ?: $stores->first()->id }}">
<button type="submit" class="rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">Sync from store</button>
</form>
@endif
<a href="{{ route('woo.products.create', ['store' => $storeFilter]) }}" class="rounded-xl bg-indigo-600 px-4 py-2 text-sm font-semibold text-white hover:bg-indigo-700">New product</a>
</div>
</div>
<form method="get" class="flex flex-wrap items-end gap-3">
<div class="min-w-[12rem] flex-1 max-w-md">
<input type="search" name="q" value="{{ $search }}" placeholder="Search name or SKU…"
class="w-full rounded-xl border-slate-200 text-sm focus:border-indigo-500 focus:ring-indigo-500">
</div>
@if($stores->isNotEmpty())
<select name="store" class="rounded-xl border-slate-200 text-sm" onchange="this.form.submit()">
<option value="">All stores</option>
@foreach($stores as $store)
<option value="{{ $store->id }}" @selected((string) $storeFilter === (string) $store->id)>{{ $store->site_name ?? $store->site_url }}</option>
@endforeach
</select>
@endif
<select name="status" class="rounded-xl border-slate-200 text-sm" onchange="this.form.submit()">
<option value="">All statuses</option>
@foreach(\App\Models\WooProduct::STATUSES as $val => $label)
<option value="{{ $val }}" @selected($statusFilter === $val)>{{ $label }}</option>
@endforeach
</select>
</form>
<div class="overflow-hidden rounded-2xl border border-slate-200 bg-white">
@if($products->isEmpty())
<p class="px-6 py-10 text-sm text-slate-500">No products yet. Sync from a connected store or create one here.</p>
@else
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-slate-100 text-sm">
<thead class="bg-slate-50 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">
<tr>
<th class="px-6 py-3">Product</th>
<th class="px-6 py-3">Store</th>
<th class="px-6 py-3">SKU</th>
<th class="px-6 py-3">Price</th>
<th class="px-6 py-3">Stock</th>
<th class="px-6 py-3">Status</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@foreach($products as $product)
<tr>
<td class="px-6 py-4">
<p class="font-medium text-slate-900">{{ $product->name }}</p>
@if($product->categoryNames())
<p class="text-xs text-slate-500">{{ implode(', ', $product->categoryNames()) }}</p>
@endif
</td>
<td class="px-6 py-4 text-slate-600">{{ $product->store?->site_name ?? parse_url($product->store?->site_url ?? '', PHP_URL_HOST) }}</td>
<td class="px-6 py-4 text-slate-600">{{ $product->sku ?: '—' }}</td>
<td class="px-6 py-4 text-slate-900">{{ $product->priceFormatted() }}</td>
<td class="px-6 py-4 text-slate-600">
@if($product->manage_stock)
{{ $product->stock_quantity ?? 0 }}
@else
@endif
</td>
<td class="px-6 py-4 text-slate-600">{{ $product->statusLabel() }}</td>
<td class="px-6 py-4 text-right">
<a href="{{ route('woo.products.edit', $product) }}" class="font-medium text-indigo-600 hover:text-indigo-800">Edit</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@if($products->hasPages())<div class="border-t border-slate-100 px-6 py-4">{{ $products->links() }}</div>@endif
@endif
</div>
</div>
</x-user-layout>
+15
View File
@@ -4,9 +4,11 @@ use App\Http\Controllers\Api\StoreActivationController;
use App\Http\Controllers\Auth\SsoLoginController;
use App\Http\Controllers\NotificationController;
use App\Http\Controllers\WalletBalanceController;
use App\Http\Controllers\Woo\CategoryController;
use App\Http\Controllers\Woo\ConnectWordPressController;
use App\Http\Controllers\Woo\DashboardController;
use App\Http\Controllers\Woo\OrderController;
use App\Http\Controllers\Woo\ProductController;
use App\Http\Controllers\Woo\StoreController;
use App\Http\Controllers\WooWebhookController;
use Illuminate\Support\Facades\Route;
@@ -39,6 +41,19 @@ Route::middleware(['auth', 'platform.session'])->group(function () {
Route::get('/dashboard', [DashboardController::class, 'index'])->name('woo.dashboard');
Route::get('/orders', [OrderController::class, 'index'])->name('woo.orders.index');
Route::patch('/orders/{order}/status', [OrderController::class, 'updateStatus'])->name('woo.orders.update-status');
Route::get('/products', [ProductController::class, 'index'])->name('woo.products.index');
Route::get('/products/create', [ProductController::class, 'create'])->name('woo.products.create');
Route::post('/products', [ProductController::class, 'store'])->name('woo.products.store');
Route::get('/products/{product}/edit', [ProductController::class, 'edit'])->name('woo.products.edit');
Route::patch('/products/{product}', [ProductController::class, 'update'])->name('woo.products.update');
Route::post('/products/sync', [ProductController::class, 'sync'])->name('woo.products.sync');
Route::get('/categories', [CategoryController::class, 'index'])->name('woo.categories.index');
Route::get('/categories/create', [CategoryController::class, 'create'])->name('woo.categories.create');
Route::post('/categories', [CategoryController::class, 'store'])->name('woo.categories.store');
Route::get('/categories/{category}/edit', [CategoryController::class, 'edit'])->name('woo.categories.edit');
Route::patch('/categories/{category}', [CategoryController::class, 'update'])->name('woo.categories.update');
Route::delete('/categories/{category}', [CategoryController::class, 'destroy'])->name('woo.categories.destroy');
Route::post('/categories/sync', [CategoryController::class, 'sync'])->name('woo.categories.sync');
Route::get('/stores', [StoreController::class, 'index'])->name('woo.stores.index');
Route::delete('/stores/{store}', [StoreController::class, 'destroy'])->name('woo.stores.destroy');
+110
View File
@@ -131,4 +131,114 @@ class WooWebTest extends TestCase
$this->assertSame(WooOrder::FULFILLMENT_PREPARING, $order->fresh()->fulfillment_status);
}
public function test_product_webhook_ingests_product(): void
{
$user = User::factory()->create();
$store = WooStore::create([
'user_id' => $user->id,
'site_url' => 'https://shop.example.com',
'status' => WooStore::STATUS_ACTIVE,
'connected_at' => now(),
]);
$payload = [
'id' => 101,
'name' => 'Hoodie',
'slug' => 'hoodie',
'sku' => 'HD-1',
'status' => 'publish',
'regular_price' => '150.00',
'categories' => [['id' => 12, 'name' => 'Apparel']],
];
$body = json_encode($payload, JSON_THROW_ON_ERROR);
$signature = base64_encode(hash_hmac('sha256', $body, (string) $store->webhook_secret, true));
$this->call(
'POST',
route('woo.webhooks.woocommerce', $store->public_id),
[],
[],
[],
[
'CONTENT_TYPE' => 'application/json',
'HTTP_X_WC_WEBHOOK_SIGNATURE' => $signature,
'HTTP_X_WC_WEBHOOK_TOPIC' => 'product.updated',
],
$body,
)->assertOk();
$this->assertDatabaseHas('woo_products', [
'woo_store_id' => $store->id,
'external_id' => 101,
'name' => 'Hoodie',
'sku' => 'HD-1',
]);
}
public function test_category_webhook_ingests_category(): void
{
$user = User::factory()->create();
$store = WooStore::create([
'user_id' => $user->id,
'site_url' => 'https://shop.example.com',
'status' => WooStore::STATUS_ACTIVE,
'connected_at' => now(),
]);
$payload = [
'id' => 12,
'name' => 'Apparel',
'slug' => 'apparel',
'parent' => 0,
'count' => 4,
];
$body = json_encode($payload, JSON_THROW_ON_ERROR);
$signature = base64_encode(hash_hmac('sha256', $body, (string) $store->webhook_secret, true));
$this->call(
'POST',
route('woo.webhooks.woocommerce', $store->public_id),
[],
[],
[],
[
'CONTENT_TYPE' => 'application/json',
'HTTP_X_WC_WEBHOOK_SIGNATURE' => $signature,
'HTTP_X_WC_WEBHOOK_TOPIC' => 'product_category.created',
],
$body,
)->assertOk();
$this->assertDatabaseHas('woo_categories', [
'woo_store_id' => $store->id,
'external_id' => 12,
'name' => 'Apparel',
]);
}
public function test_merchant_can_view_products_page(): void
{
$user = User::factory()->create();
$store = WooStore::create([
'user_id' => $user->id,
'site_url' => 'https://shop.example.com',
'status' => WooStore::STATUS_ACTIVE,
]);
\App\Models\WooProduct::create([
'woo_store_id' => $store->id,
'external_id' => 1,
'name' => 'Sample Tee',
'slug' => 'sample-tee',
'status' => 'publish',
]);
$this->actingAs($user)
->get(route('woo.products.index'))
->assertOk()
->assertSee('Sample Tee');
}
}