Fix Woo sync: exempt webhooks from CSRF and backfill on connect.
Deploy Ladill Woo Manager / deploy (push) Successful in 39s
Deploy Ladill Woo Manager / deploy (push) Successful in 39s
Auto-import catalog and orders after store activation, add manual order sync, and allow WooCommerce webhooks without CSRF tokens. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Woo;
|
||||
|
||||
use App\Models\WooStore;
|
||||
|
||||
class OrderSyncService
|
||||
{
|
||||
public function __construct(
|
||||
private PluginClient $client,
|
||||
private OrderIngestService $orders,
|
||||
) {}
|
||||
|
||||
public function syncOrders(WooStore $store): int
|
||||
{
|
||||
$response = $this->client->get($store, 'orders', ['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;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->orders->ingest($store, $item);
|
||||
$count++;
|
||||
} catch (\Throwable) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Woo;
|
||||
|
||||
use App\Models\WooStore;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class StoreSyncService
|
||||
{
|
||||
public function __construct(
|
||||
private CatalogSyncService $catalog,
|
||||
private OrderSyncService $orders,
|
||||
) {}
|
||||
|
||||
/** @return array{categories: int, products: int, orders: int} */
|
||||
public function syncAll(WooStore $store): array
|
||||
{
|
||||
$counts = [
|
||||
'categories' => 0,
|
||||
'products' => 0,
|
||||
'orders' => 0,
|
||||
];
|
||||
|
||||
try {
|
||||
$catalogCounts = $this->catalog->syncAll($store);
|
||||
$counts['categories'] = $catalogCounts['categories'];
|
||||
$counts['products'] = $catalogCounts['products'];
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Woo catalog sync failed', [
|
||||
'store_id' => $store->id,
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$counts['orders'] = $this->orders->syncOrders($store);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Woo order sync failed', [
|
||||
'store_id' => $store->id,
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $counts;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user