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>
71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?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;
|
|
}
|
|
}
|