workingCopy/ecomzone/get_token.php
2025-06-24 21:46:54 +02:00

53 lines
1.7 KiB
PHP

<?php
// Simple script to get the API token from the PrestaShop configuration
// Check if we're running from command line
$cli = php_sapi_name() === 'cli';
// Set content type for browser
if (!$cli) {
header('Content-Type: text/plain');
}
// Try to load PrestaShop configuration
$configFile = __DIR__ . '/../../config/config.inc.php';
if (file_exists($configFile)) {
include_once($configFile);
// If Configuration class exists, try to get token
if (class_exists('Configuration')) {
$token = Configuration::get('ECOMZONE_API_TOKEN');
echo "API Token from configuration: " . ($token ? $token : "Not set") . "\n";
exit;
}
}
// If PrestaShop config doesn't work, try direct DB connection using default credentials
$dbConfig = [
'host' => 'localhost',
'username' => 'prestashop',
'password' => 'prestashop',
'database' => 'prestashop',
'prefix' => 'ps_'
];
echo "Attempting direct database connection...\n";
try {
$db = new PDO("mysql:host={$dbConfig['host']};dbname={$dbConfig['database']}", $dbConfig['username'], $dbConfig['password']);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("SELECT value FROM {$dbConfig['prefix']}configuration WHERE name = 'ECOMZONE_API_TOKEN'");
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result && isset($result['value'])) {
echo "API Token found in database: " . $result['value'] . "\n";
} else {
echo "API Token not found in database.\n";
}
} catch (PDOException $e) {
echo "Database connection failed: " . $e->getMessage() . "\n";
echo "You'll need to manually update the api_test.php file with your API token.\n";
}