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:
@@ -39,6 +39,41 @@ class SimpleIopClient
|
||||
}
|
||||
|
||||
public function execute($request, $accessToken = null)
|
||||
{
|
||||
$apiName = $request->getApiName();
|
||||
|
||||
// Check if this is a Miravia API endpoint (starts with /)
|
||||
if (strpos($apiName, '/') === 0) {
|
||||
return $this->executeMiraviaAPI($request, $accessToken);
|
||||
} else {
|
||||
return $this->executeAliExpressAPI($request, $accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
private function executeMiraviaAPI($request, $accessToken = null)
|
||||
{
|
||||
$apiPath = $request->getApiName();
|
||||
$apiParams = $request->getApiParams();
|
||||
|
||||
// For Miravia API, we use direct HTTP calls with token authentication
|
||||
$requestUrl = $this->gatewayUrl . $apiPath;
|
||||
|
||||
if(class_exists('LOG')) {
|
||||
LOG::add("DEBUG SimpleSDK: Making Miravia API request to: " . $requestUrl);
|
||||
LOG::add("DEBUG SimpleSDK: Params: " . json_encode($apiParams));
|
||||
}
|
||||
|
||||
// Use direct POST with JSON for Miravia API
|
||||
$response = $this->curlMiravia($requestUrl, $apiParams, $accessToken);
|
||||
|
||||
if(class_exists('LOG')) {
|
||||
LOG::add("DEBUG SimpleSDK: Miravia Response: " . $response);
|
||||
}
|
||||
|
||||
return json_decode($response);
|
||||
}
|
||||
|
||||
private function executeAliExpressAPI($request, $accessToken = null)
|
||||
{
|
||||
$sysParams = [
|
||||
"app_key" => $this->appKey,
|
||||
@@ -51,7 +86,6 @@ class SimpleIopClient
|
||||
];
|
||||
|
||||
if ($accessToken) {
|
||||
// Personal tokens use access_token parameter instead of session
|
||||
$sysParams["access_token"] = $accessToken;
|
||||
}
|
||||
|
||||
@@ -63,7 +97,7 @@ class SimpleIopClient
|
||||
$requestUrl = $this->gatewayUrl;
|
||||
|
||||
if(class_exists('LOG')) {
|
||||
LOG::add("DEBUG SimpleSDK: Making request to: " . $requestUrl);
|
||||
LOG::add("DEBUG SimpleSDK: Making AliExpress API request to: " . $requestUrl);
|
||||
LOG::add("DEBUG SimpleSDK: Method: " . $request->getApiName());
|
||||
LOG::add("DEBUG SimpleSDK: Params: " . json_encode($totalParams));
|
||||
}
|
||||
@@ -71,7 +105,7 @@ class SimpleIopClient
|
||||
$response = $this->curl($requestUrl, $totalParams);
|
||||
|
||||
if(class_exists('LOG')) {
|
||||
LOG::add("DEBUG SimpleSDK: Response: " . $response);
|
||||
LOG::add("DEBUG SimpleSDK: AliExpress Response: " . $response);
|
||||
}
|
||||
|
||||
return json_decode($response);
|
||||
@@ -109,6 +143,57 @@ class SimpleIopClient
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function curlMiravia($url, $data = null, $accessToken = null)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
|
||||
// Set headers for Miravia API
|
||||
$headers = [
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json'
|
||||
];
|
||||
|
||||
// Add authorization header if token is provided
|
||||
if ($accessToken) {
|
||||
$headers[] = 'Authorization: Bearer ' . $accessToken;
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// Send data as JSON
|
||||
if ($data) {
|
||||
$jsonData = json_encode($data);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
|
||||
|
||||
if(class_exists('LOG')) {
|
||||
LOG::add("DEBUG SimpleSDK: Sending JSON data: " . $jsonData);
|
||||
}
|
||||
}
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
$this->last_error = curl_error($ch);
|
||||
if(class_exists('LOG')) {
|
||||
LOG::add("DEBUG SimpleSDK: CURL Error: " . $this->last_error);
|
||||
}
|
||||
}
|
||||
|
||||
if(class_exists('LOG')) {
|
||||
LOG::add("DEBUG SimpleSDK: HTTP Response Code: " . $httpCode);
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleIopRequest
|
||||
|
||||
Reference in New Issue
Block a user