> * } */ public function forStore(?WooStore $store): array { $catalog = config('woo_integrations', []); if (! $store) { return [ 'store' => null, 'reachable' => false, 'integrations' => $this->catalogOnly($catalog), ]; } $remote = $this->client->get($store, 'integrations/status'); $reachable = is_array($remote); if (! $reachable) { Log::info('Woo integration status unavailable', ['store_id' => $store->id]); } $remoteItems = is_array($remote['integrations'] ?? null) ? $remote['integrations'] : []; $integrations = []; foreach ($catalog as $key => $meta) { $remoteStatus = is_array($remoteItems[$key] ?? null) ? $remoteItems[$key] : []; $integrations[] = $this->mergeIntegration($key, $meta, $remoteStatus, $store, $reachable); } return [ 'store' => $store, 'reachable' => $reachable, 'integrations' => $integrations, ]; } /** * @param array $meta * @param array $remoteStatus * @return array */ private function mergeIntegration(string $key, array $meta, array $remoteStatus, WooStore $store, bool $reachable): array { $state = $reachable ? (string) ($remoteStatus['state'] ?? 'unknown') : 'unavailable'; $manageUrl = $remoteStatus['manage_url'] ?? null; if (is_string($manageUrl) && $manageUrl !== '' && ! str_starts_with($manageUrl, 'http')) { $manageUrl = rtrim((string) $store->site_url, '/').'/'.ltrim($manageUrl, '/'); } return [ 'key' => $key, 'name' => (string) ($meta['name'] ?? $key), 'description' => (string) ($meta['description'] ?? ''), 'category' => (string) ($meta['category'] ?? 'Integration'), 'install_url' => $meta['install_url'] ?? null, 'docs_url' => $meta['docs_url'] ?? null, 'state' => $state, 'installed' => (bool) ($remoteStatus['installed'] ?? false), 'connected' => (bool) ($remoteStatus['connected'] ?? false), 'summary' => $reachable ? (string) ($remoteStatus['summary'] ?? '') : 'Could not reach your store. Check that the Ladill plugin is active.', 'manage_url' => is_string($manageUrl) && $manageUrl !== '' ? $manageUrl : null, 'details' => is_array($remoteStatus['details'] ?? null) ? $remoteStatus['details'] : [], ]; } /** * @param array> $catalog * @return list> */ private function catalogOnly(array $catalog): array { $integrations = []; foreach ($catalog as $key => $meta) { $integrations[] = [ 'key' => $key, 'name' => (string) ($meta['name'] ?? $key), 'description' => (string) ($meta['description'] ?? ''), 'category' => (string) ($meta['category'] ?? 'Integration'), 'install_url' => $meta['install_url'] ?? null, 'docs_url' => $meta['docs_url'] ?? null, 'state' => 'no_store', 'installed' => false, 'connected' => false, 'summary' => 'Connect a WooCommerce store to see status.', 'manage_url' => null, 'details' => [], ]; } return $integrations; } }