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:
@@ -19,7 +19,8 @@ if( !class_exists('APIMIRAVIA') ) {
|
||||
'miravia_print_label',
|
||||
'miravia_get_brands',
|
||||
'miravia_connect_product',
|
||||
'disconnect_product_miravia'
|
||||
'disconnect_product_miravia',
|
||||
'test_miravia_api_connection'
|
||||
);
|
||||
foreach( $actionsPrivate as $action ){
|
||||
add_action( 'wp_ajax_'.$action, array( $this, $action ) );
|
||||
@@ -547,6 +548,44 @@ if( !class_exists('APIMIRAVIA') ) {
|
||||
wp_die();
|
||||
}
|
||||
|
||||
function test_miravia_api_connection() {
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_die('Unauthorized');
|
||||
}
|
||||
|
||||
if (!wp_verify_nonce($_POST['nonce'], 'test_miravia_api')) {
|
||||
wp_send_json_error('Invalid nonce');
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if direct API is enabled
|
||||
if (get_option('miravia_direct_api', '0') !== '1') {
|
||||
wp_send_json_error('Direct API access is not enabled');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
require_once plugin_dir_path(__FILE__) . 'shared/MiraviaSdk.php';
|
||||
$sdk = new MiraviaSdk();
|
||||
|
||||
if (!$sdk->isConfigured()) {
|
||||
wp_send_json_error('SDK not configured. Please check your API credentials.');
|
||||
return;
|
||||
}
|
||||
|
||||
$test_result = $sdk->testConnection();
|
||||
|
||||
if ($test_result['success']) {
|
||||
wp_send_json_success(['message' => $test_result['message']]);
|
||||
} else {
|
||||
wp_send_json_error($test_result['error']);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
wp_send_json_error('Connection test failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function miravia_update_product() {
|
||||
if ( !current_user_can( 'manage_woocommerce' ) ) { exit; }
|
||||
$result = array(
|
||||
|
||||
Reference in New Issue
Block a user