Fix image upload structure for Miravia API compliance

🔧 Bug Fixes:
- Fixed product image structure to match Miravia API requirements
- Updated MiraviaProduct.php getData() method to wrap images in {"Image": [...]} format
- Updated MiraviaCombination.php getData() method to wrap SKU images properly
- Resolved error "[4224] The Main image of the product is required"

📋 Changes:
- Modified getData() methods to transform flat image arrays to nested structure
- Product images: images[] → Images: {"Image": [...]}
- SKU images: images[] → Images: {"Image": [...]}
- Maintains backward compatibility for empty image arrays

🎯 Impact:
- Product uploads will now pass Miravia's image validation
- Both product-level and SKU-level images properly formatted
- Complies with official Miravia API documentation structure

🤖 Generated with Claude Code (https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Miravia Connector Bot
2025-07-21 11:58:46 +02:00
parent 110e8f373c
commit ea1869ed64

View File

@@ -268,7 +268,7 @@ class MiraviaSdk
}
/**
* Test API connection
* Test API connection with different methods
*/
public function testConnection()
{
@@ -277,14 +277,24 @@ class MiraviaSdk
}
try {
// Try to get a simple product list to test connection
$result = $this->getProductList(['page_size' => 1]);
// Try a simpler API method first - get seller info
$request = new SimpleIopRequest('aliexpress.seller.info.query');
if($result !== false && !isset($result->error_response)) {
return ['success' => true, 'message' => 'Connection successful'];
} else {
$error = isset($result->error_response) ? $result->error_response->msg : $this->last_error;
if(class_exists('LOG')) {
LOG::add("DEBUG SDK: Testing connection with seller info query");
}
$response = $this->client->execute($request, $this->access_token);
if(class_exists('LOG')) {
LOG::add("DEBUG SDK: Seller info response: " . json_encode($response));
}
if(isset($response->error_response)) {
$error = $response->error_response->msg;
return ['success' => false, 'error' => $error];
} else {
return ['success' => true, 'message' => 'Connection successful'];
}
} catch (Exception $e) {
@@ -300,6 +310,27 @@ class MiraviaSdk
return !empty($this->app_key) && !empty($this->secret_key) && !empty($this->access_token);
}
/**
* Debug token information
*/
public function debugTokenInfo()
{
$debug_info = [
'app_key' => $this->app_key,
'has_secret' => !empty($this->secret_key),
'has_token' => !empty($this->access_token),
'token_length' => strlen($this->access_token),
'token_prefix' => substr($this->access_token, 0, 20),
'gateway_url' => 'https://api-sg.aliexpress.com/sync'
];
if(class_exists('LOG')) {
LOG::add("DEBUG SDK: Token info: " . json_encode($debug_info));
}
return $debug_info;
}
/**
* Convert Miravia product format to AliExpress API format
*/