up untill fetch 10 products
This commit is contained in:
1 parent
9c2c174a43
commit
2eef682859
4 files changed
+148
-28
No files matched your search
@@ -44,7 +44,8 @@ class EcomZone extends Module
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Configuration::updateValue('ECOMZONE_API_KEY', '') ||
|
||||
// Set default API key from your working configuration
|
||||
if (!Configuration::updateValue('ECOMZONE_API_KEY', 'klRyAdrXaxL0s6PEUp7LDlH6T8aPSCtBY8NiEHsHiWpc6646K2TZPi5KMxUg') ||
|
||||
!Configuration::updateValue('ECOMZONE_API_URL', 'https://dropship.ecomzone.eu/api')) {
|
||||
$this->errors[] = $this->l('Could not set default configuration');
|
||||
return false;
|
||||
@@ -56,18 +57,54 @@ class EcomZone extends Module
|
||||
public function getContent()
|
||||
{
|
||||
$output = '';
|
||||
$debugOutput = '';
|
||||
|
||||
if (Tools::isSubmit('submitEcomZone')) {
|
||||
$apiKey = Tools::getValue('ECOMZONE_API_KEY');
|
||||
$apiKey = trim(Tools::getValue('ECOMZONE_API_KEY'));
|
||||
|
||||
if (!$apiKey) {
|
||||
$output .= $this->displayError($this->l('API Key is required'));
|
||||
} else {
|
||||
Configuration::updateValue('ECOMZONE_API_KEY', $apiKey);
|
||||
$debugOutput .= "API Key saved: " . substr($apiKey, 0, 10) . "...\n";
|
||||
$output .= $this->displayConfirmation($this->l('Settings updated'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Handle manual fetch
|
||||
if (Tools::isSubmit('fetchProducts')) {
|
||||
try {
|
||||
$debugOutput .= "Starting product fetch...\n";
|
||||
|
||||
// Get first 10 products for testing
|
||||
$catalog = $this->api->getCatalog(10);
|
||||
|
||||
if (isset($catalog['data']) && is_array($catalog['data'])) {
|
||||
foreach ($catalog['data'] as $product) {
|
||||
$debugOutput .= sprintf(
|
||||
"Found product: %s - %s (Price: %s EUR, Stock: %s)\n",
|
||||
$product['sku'],
|
||||
$product['product_name'],
|
||||
$product['product_price'],
|
||||
$product['stock']
|
||||
);
|
||||
}
|
||||
$debugOutput .= sprintf("\nTotal products fetched: %d\n", count($catalog['data']));
|
||||
} else {
|
||||
$debugOutput .= "No products found or invalid response format\n";
|
||||
}
|
||||
|
||||
$output .= $this->displayConfirmation($this->l('Products fetched successfully'));
|
||||
|
||||
} catch (Exception $e) {
|
||||
$debugOutput .= "Error: " . $e->getMessage() . "\n";
|
||||
$output .= $this->displayError($this->l('Error fetching products'));
|
||||
}
|
||||
}
|
||||
|
||||
// Store debug output in smarty variable
|
||||
$this->context->smarty->assign('debug_output', $debugOutput);
|
||||
|
||||
return $output . $this->displayForm();
|
||||
}
|
||||
|
||||
@@ -86,6 +123,15 @@ class EcomZone extends Module
|
||||
'size' => 50
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
[
|
||||
'type' => 'submit',
|
||||
'title' => $this->l('Fetch Products'),
|
||||
'icon' => 'process-icon-download',
|
||||
'name' => 'fetchProducts',
|
||||
'class' => 'btn btn-primary pull-left'
|
||||
]
|
||||
],
|
||||
'submit' => [
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-default pull-right'
|
||||
@@ -99,8 +145,21 @@ class EcomZone extends Module
|
||||
$helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
|
||||
$helper->default_form_language = Configuration::get('PS_LANG_DEFAULT');
|
||||
$helper->fields_value['ECOMZONE_API_KEY'] = Configuration::get('ECOMZONE_API_KEY');
|
||||
|
||||
return $helper->generateForm($fields_form);
|
||||
|
||||
// Add debug console after form
|
||||
$form = $helper->generateForm($fields_form);
|
||||
$debug_console = '<div class="panel">
|
||||
<div class="panel-heading">
|
||||
<i class="icon-list"></i> ' . $this->l('Debug Console') . '
|
||||
</div>
|
||||
<div class="panel-content">
|
||||
<pre id="debug-console" style="max-height: 300px; overflow-y: auto; background: #f5f5f5; padding: 10px;">
|
||||
' . $this->context->smarty->getTemplateVars('debug_output') . '
|
||||
</pre>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
return $form . $debug_console;
|
||||
}
|
||||
|
||||
public function getErrors()
|
||||
|
||||
Reference in new issue
Block a user