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:34:59 +02:00
parent dc50508c1c
commit 752600f337
79 changed files with 7970 additions and 36 deletions

View File

@@ -0,0 +1,26 @@
<?php
/**
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 18:06
*/
namespace Sweeper\PlatformMiddleware\Test\Services\Aliexpress\OpenApi;
use Sweeper\PlatformMiddleware\Services\Aliexpress\OpenApi\Order;
use PHPUnit\Framework\TestCase;
class OrderTest extends TestCase
{
public function testGetOrderList()
{
$accountInfo = [];
$response = Order::instance()->getOrderList($accountInfo, ['current_page' => 1, 'page_size' => 50]);
dump($response);
static::assertIsArray($response);
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:49
*/
namespace Sweeper\PlatformMiddleware\Test\Services\Mirakl;
use PHPUnit\Framework\TestCase;
use Sweeper\PlatformMiddleware\Services\Mirakl\Order;
use Sweeper\PlatformMiddleware\Services\Mirakl\Request;
class OrderTest extends TestCase
{
public function testGetOrders(): void
{
$response = Order::instance([
'api_url' => Request::OPEN_API_URL,
'api_key' => $appInfo['apiKey'] ?? $appInfo['api_key'] ?? $appInfo['secretFieldValue'] ?? '59ac39c9-6d1b-4ff1-a57f-26bb835048e6',
'shop_id' => $appInfo['shopId'] ?? $appInfo['shop_id'] ?? $appInfo['clientFieldValue'] ?? '',
])->setSuccessCode(-1)->getOrders();
dump($response);
$this->assertTrue($response->isSuccess());
}
public function testGetOrderDocuments(): void
{
$response = Order::instance([
'api_url' => Request::OPEN_API_URL,
'api_key' => $appInfo['apiKey'] ?? $appInfo['api_key'] ?? $appInfo['secretFieldValue'] ?? '59ac39c9-6d1b-4ff1-a57f-26bb835048e6',
'shop_id' => $appInfo['shopId'] ?? $appInfo['shop_id'] ?? $appInfo['clientFieldValue'] ?? '',
])->setSuccessCode(-1)->getOrderDocuments(['C59675662-A', 'C59652563-A']);
dump($response);
$this->assertTrue($response->isSuccess());
}
public function testDownloadOrdersDocuments(): void
{
$response = Order::instance([
'api_url' => Request::OPEN_API_URL,
'api_key' => $appInfo['apiKey'] ?? $appInfo['api_key'] ?? $appInfo['secretFieldValue'] ?? '59ac39c9-6d1b-4ff1-a57f-26bb835048e6',
'shop_id' => $appInfo['shopId'] ?? $appInfo['shop_id'] ?? $appInfo['clientFieldValue'] ?? '',
])->downloadOrdersDocuments(['C59675662-A', 'C59652563-A'], false);
dump($response);
$this->assertTrue($response->isSuccess());
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/2/26 13:50
*/
namespace Sweeper\PlatformMiddleware\Test\Services\Mirakl;
use PHPUnit\Framework\TestCase;
use Sweeper\PlatformMiddleware\Services\Mirakl\PlatformSetting;
use Sweeper\PlatformMiddleware\Services\Mirakl\Request;
class PlatformSettingTest extends TestCase
{
public function testCarriers(): void
{
$response = PlatformSetting::instance([
'api_url' => Request::OPEN_API_URL,
'api_key' => $appInfo['apiKey'] ?? $appInfo['api_key'] ?? $appInfo['secretFieldValue'] ?? '59ac39c9-6d1b-4ff1-a57f-26bb835048e6',
'shop_id' => $appInfo['shopId'] ?? $appInfo['shop_id'] ?? $appInfo['clientFieldValue'] ?? '',
])->setSuccessCode(-1)->carriers();
dump($response);
$this->assertTrue($response->isSuccess());
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/19 17:39
*/
namespace Sweeper\PlatformMiddleware\Test\Services\Miravia;
use Sweeper\PlatformMiddleware\Services\Miravia\Order;
use PHPUnit\Framework\TestCase;
class OrderTest extends TestCase
{
public function testGetOrderList(): void
{
$accountInfo = [];
$response = Order::instance()->getOrderList($accountInfo, ['current_page' => 1, 'open_channel' => '', 'channel_seller_id' => '']);
dump($response);
static::assertIsArray($response);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Created by Sweeper PhpStorm.
* Author: Sweeper <wili.lixiang@gmail.com>
* DateTime: 2024/3/15 15:33
*/
namespace Sweeper\PlatformMiddleware\Test;
use PHPUnit\Framework\TestCase;
use function Sweeper\PlatformMiddleware\package_path;
use function Sweeper\PlatformMiddleware\vendor_path;
class TestPath extends TestCase
{
public function testRootPath(): void
{
$expected = dirname(__DIR__);
$actual = dirname(vendor_path());
dump('===== testRootPath =====', $expected, $actual);
$this->assertEquals($expected, $actual);
}
public function testVendorPath(): void
{
$expected = dirname(__DIR__) . '/vendor';
$actual = vendor_path();
dump('===== testVendorPath =====', $expected, $actual);
$this->assertEquals($expected, $actual);
}
public function testPackagePath(): void
{
$package = 'sweeper/platform-middleware';
$expected = dirname(__DIR__);
$actual = package_path($package);
dump('===== testPackagePath =====', $expected, $actual);
$this->assertEquals($expected, $actual);
}
}