'https://dropship.ecomzone.eu/api', 'ECOMZONE_API_TOKEN' => 'klRyAdrXaxL0s6PEUp7LDlH6T8aPSCtBY8NiEHsHiWpc6646K2TZPi5KMxUg' // Replace with your actual API token ]; return isset($config[$key]) ? $config[$key] : $default; } public static function updateValue($key, $value) { return true; } } } // Mock PrestaShop classes if (!class_exists('Context')) { class Context { public $shop; public static $instance; public function __construct() { $this->shop = new stdClass(); $this->shop->id = 1; } public static function getContext() { if (!self::$instance) { self::$instance = new Context(); } return self::$instance; } } } if (!class_exists('PrestaShopLogger')) { class PrestaShopLogger { public static function addLog($message, $severity = 1, $error_code = null, $object_type = null, $object_id = null, $allow_duplicate = false, $id_employee = null) { return true; } } } // Create log directory if it doesn't exist $logDir = __DIR__ . '/log'; if (!file_exists($logDir)) { mkdir($logDir, 0755, true); } try { // Get API settings $apiUrl = Configuration::get('ECOMZONE_API_URL'); $apiToken = Configuration::get('ECOMZONE_API_TOKEN'); echo "API URL: " . $apiUrl . "\n"; echo "API Token: " . (empty($apiToken) || $apiToken === 'YOUR_API_TOKEN' ? "Not set - Please edit api_test.php and replace YOUR_API_TOKEN with your actual token" : "Set (length: " . strlen($apiToken) . " chars)") . "\n\n"; if (empty($apiToken) || $apiToken === 'YOUR_API_TOKEN') { throw new Exception("API token is not configured. Please edit api_test.php and replace YOUR_API_TOKEN with your actual token."); } echo "Testing API connection...\n\n"; // Create API client $client = new EcomZoneClient(); // Test API connectivity with catalog endpoint echo "Requesting catalog data (page 1, limit 1)...\n"; $result = $client->getCatalog(1, 1); if (isset($result['data']) && is_array($result['data'])) { echo "Success! Received " . count($result['data']) . " product(s)\n"; echo "Total products available: " . ($result['total'] ?? 'unknown') . "\n\n"; if (!empty($result['data'])) { $sku = $result['data'][0]['sku'] ?? null; if ($sku) { echo "Testing product detail retrieval...\n"; echo "Requesting product with SKU: " . $sku . "\n"; $productDetail = $client->getProduct($sku); if (isset($productDetail['data']) && !empty($productDetail['data'])) { echo "Success! Retrieved product details\n"; echo "Product name: " . ($productDetail['data']['product_name'] ?? 'unknown') . "\n"; } else { echo "Error: Failed to retrieve product details\n"; echo "Response: " . print_r($productDetail, true) . "\n"; } } } } else { echo "Error: Invalid catalog response\n"; echo "Response: " . print_r($result, true) . "\n"; } echo "\nAPI test completed successfully!\n"; } catch (Exception $e) { echo "ERROR: " . $e->getMessage() . "\n"; if ($e instanceof EcomZoneException) { echo "Error Code: " . $e->getCode() . "\n"; } echo "\nStack Trace:\n" . $e->getTraceAsString() . "\n"; }