Files
ladill-woo-manager/app/Services/Woo/OrderSyncService.php
T
isaacclad e709de6593
Deploy Ladill Woo Manager / deploy (push) Successful in 35s
Use WooCommerce store currency for product and order money.
Sync currency from the plugin, format product prices and totals with it, and show the store currency on product price fields instead of hard-coding GHS.
2026-07-24 15:38:07 +00:00

52 lines
1.3 KiB
PHP

<?php
namespace App\Services\Woo;
use App\Models\WooStore;
class OrderSyncService
{
public function __construct(
private PluginClient $client,
private OrderIngestService $orders,
private CatalogSyncService $catalog,
) {}
public function syncOrders(WooStore $store): int
{
$response = $this->client->get($store, 'orders', ['per_page' => 100]);
if (! is_array($response)) {
return 0;
}
if (isset($response['currency']) || isset($response['currency_symbol'])) {
$this->catalog->applyStoreMeta($store, $response);
}
$items = $response['data'] ?? $response;
if (! is_array($items)) {
return 0;
}
if (array_is_list($items) === false && isset($response['data']) === false) {
$items = array_values(array_filter($items, fn ($item) => is_array($item) && (isset($item['id']) || isset($item['number']))));
}
$count = 0;
foreach ($items as $item) {
if (! is_array($item)) {
continue;
}
try {
$this->orders->ingest($store, $item);
$count++;
} catch (\Throwable) {
continue;
}
}
return $count;
}
}