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:
@@ -123,6 +123,11 @@ $categories = get_terms( ['taxonomy' => 'product_cat', 'hide_empty' => false] );
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="miravia_access_token" value="<?php echo esc_attr($accessToken)?>" style="width: 400px;" placeholder="Enter your Access Token" />
|
||||
<?php if($directApi == '1' && !empty($appKey) && !empty($secretKey) && !empty($accessToken)): ?>
|
||||
<br><br>
|
||||
<button type="button" id="test-api-connection" class="button">Test API Connection</button>
|
||||
<div id="api-test-result" style="margin-top: 10px;"></div>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
@@ -226,4 +231,38 @@ $categories = get_terms( ['taxonomy' => 'product_cat', 'hide_empty' => false] );
|
||||
</table>
|
||||
<input type="submit" class="button" value="<?php echo __('Save')?>" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function($) {
|
||||
$('#test-api-connection').click(function() {
|
||||
var button = $(this);
|
||||
var resultDiv = $('#api-test-result');
|
||||
|
||||
button.prop('disabled', true).text('Testing...');
|
||||
resultDiv.html('<p>Testing API connection...</p>');
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'test_miravia_api_connection',
|
||||
nonce: '<?php echo wp_create_nonce('test_miravia_api'); ?>'
|
||||
},
|
||||
success: function(response) {
|
||||
if(response.success) {
|
||||
resultDiv.html('<div style="color: green; padding: 10px; background: #d4edda; border: 1px solid #c3e6cb; border-radius: 4px;"><strong>✓ Success:</strong> ' + response.data.message + '</div>');
|
||||
} else {
|
||||
resultDiv.html('<div style="color: #721c24; padding: 10px; background: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px;"><strong>✗ Error:</strong> ' + response.data + '</div>');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
resultDiv.html('<div style="color: #721c24; padding: 10px; background: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px;"><strong>✗ Error:</strong> Failed to test connection</div>');
|
||||
},
|
||||
complete: function() {
|
||||
button.prop('disabled', false).text('Test API Connection');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user