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:
parent
752600f337
commit
8eff705548
@ -39,7 +39,9 @@ class MiraviaSdk
|
||||
|
||||
try {
|
||||
$request = new SimpleIopRequest('aliexpress.offer.product.post');
|
||||
$request->addApiParam('aeop_a_e_product', json_encode($productData));
|
||||
// Convert Miravia product format to AliExpress format
|
||||
$aliexpressProduct = $this->convertToAliExpressFormat($productData);
|
||||
$request->addApiParam('aeop_a_e_product', json_encode($aliexpressProduct));
|
||||
|
||||
if(class_exists('LOG')) {
|
||||
LOG::add("DEBUG SDK: Creating product with AliExpress API");
|
||||
@ -291,4 +293,50 @@ class MiraviaSdk
|
||||
{
|
||||
return !empty($this->app_key) && !empty($this->secret_key) && !empty($this->access_token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Miravia product format to AliExpress API format
|
||||
*/
|
||||
private function convertToAliExpressFormat($miraviaProduct)
|
||||
{
|
||||
$aliexpressProduct = [
|
||||
'subject' => $miraviaProduct['name'] ?? '',
|
||||
'category_id' => $miraviaProduct['id_category'] ?? '',
|
||||
'language' => 'en',
|
||||
'currency_code' => 'EUR',
|
||||
'package_type' => true,
|
||||
'product_price' => $miraviaProduct['price'] ?? '0',
|
||||
'product_unit' => 100,
|
||||
'package_length' => $miraviaProduct['length'] ?? 1,
|
||||
'package_width' => $miraviaProduct['width'] ?? 1,
|
||||
'package_height' => $miraviaProduct['height'] ?? 1,
|
||||
'gross_weight' => $miraviaProduct['weight'] ?? '0.1',
|
||||
'detail' => $miraviaProduct['description'] ?? '',
|
||||
'image_u_r_ls' => implode(';', $miraviaProduct['Images']['Image'] ?? []),
|
||||
'package_quantity' => 1,
|
||||
'ws_display' => 'N',
|
||||
'ws_offline_date' => '',
|
||||
'freight_template_id' => 0,
|
||||
'product_status_type' => 'onSelling'
|
||||
];
|
||||
|
||||
// Add SKU information
|
||||
if (!empty($miraviaProduct['sku'])) {
|
||||
$aliexpressProduct['aeop_ae_product_s_k_us'] = [
|
||||
[
|
||||
'sku_code' => $miraviaProduct['sku'],
|
||||
'sku_price' => $miraviaProduct['price'] ?? '0',
|
||||
'sku_stock' => $miraviaProduct['quantity'] ?? '0',
|
||||
'currency_code' => 'EUR',
|
||||
'id' => ''
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
if(class_exists('LOG')) {
|
||||
LOG::add("DEBUG SDK: Converted product format: " . json_encode($aliexpressProduct));
|
||||
}
|
||||
|
||||
return $aliexpressProduct;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user