Files
MiraviaConnector/connector-miravia/classes/shared/MiraviaCombination.php
Miravia Connector Bot a7d7dbb164 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>
2025-07-17 08:11:23 +02:00

59 lines
1.4 KiB
PHP

<?php
class MiraviaCombination
{
public $sku = '';
public $ean_code = '';
public $price = 0;
public $special_price = 0;
public $quantity = 0;
public $images = [];
public $width = 0;
public $height = 0;
public $length = 0;
public $weight = 0;
public $variation = [];
public function addVariation($name, $value)
{
$this->variation[$name] = $value;
}
public function getData()
{
$combination = [];
$this->weight = round((float)$this->weight, 2);
foreach ($this as $key => $value){
if($key=='ean_code' && empty($value)){
continue;
}
if($key === 'images' && is_array($value) && !empty($value)){
$combination['Images'] = ['Image' => $value];
} else if($key !== 'images') {
$combination[$key] = $value;
}
}
return $combination;
}
public function getStockData()
{
$combination = [
'sku' => $this->sku,
'price' => $this->price,
'special_price' => $this->special_price,
'quantity' => $this->quantity >= 0 ? $this->quantity : 0
];
return $combination;
}
public function getOnlyStockData()
{
$combination = [
'sku' => $this->sku,
'quantity' => $this->quantity >= 0 ? $this->quantity : 0
];
return $combination;
}
}