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:
@@ -21,7 +21,12 @@ if( !class_exists('APIMIRAVIA') ) {
|
||||
'miravia_connect_product',
|
||||
'disconnect_product_miravia',
|
||||
'test_miravia_api_connection',
|
||||
'debug_miravia_credentials'
|
||||
'debug_miravia_credentials',
|
||||
'miravia_submit_single_product_feed',
|
||||
'miravia_submit_bulk_products_feed',
|
||||
'miravia_update_job_status',
|
||||
'miravia_get_feed_jobs',
|
||||
'miravia_resubmit_job'
|
||||
);
|
||||
foreach( $actionsPrivate as $action ){
|
||||
add_action( 'wp_ajax_'.$action, array( $this, $action ) );
|
||||
@@ -627,6 +632,118 @@ if( !class_exists('APIMIRAVIA') ) {
|
||||
wp_send_json($result);
|
||||
wp_die();
|
||||
}
|
||||
|
||||
// NEW FEED API METHODS
|
||||
|
||||
function miravia_submit_single_product_feed() {
|
||||
if (!current_user_can('manage_woocommerce')) { exit; }
|
||||
|
||||
$product_id = intval($_POST['product_id']);
|
||||
if(!$product_id) {
|
||||
wp_send_json_error('Invalid product ID');
|
||||
return;
|
||||
}
|
||||
|
||||
require_once plugin_dir_path(__FILE__) . 'class.feed-manager.php';
|
||||
$feedManager = new MiraviaFeedManager();
|
||||
|
||||
$result = $feedManager->submitSingleProduct($product_id);
|
||||
|
||||
if($result['success']) {
|
||||
wp_send_json_success($result);
|
||||
} else {
|
||||
wp_send_json_error($result['error']);
|
||||
}
|
||||
}
|
||||
|
||||
function miravia_submit_bulk_products_feed() {
|
||||
if (!current_user_can('manage_woocommerce')) { exit; }
|
||||
|
||||
$product_ids = $_POST['product_ids'] ?? [];
|
||||
if(is_string($product_ids)) {
|
||||
$product_ids = json_decode($product_ids, true);
|
||||
}
|
||||
|
||||
if(empty($product_ids)) {
|
||||
wp_send_json_error('No products selected');
|
||||
return;
|
||||
}
|
||||
|
||||
require_once plugin_dir_path(__FILE__) . 'class.feed-manager.php';
|
||||
$feedManager = new MiraviaFeedManager();
|
||||
|
||||
$result = $feedManager->submitProducts(array_map('intval', $product_ids));
|
||||
|
||||
if($result['success']) {
|
||||
wp_send_json_success($result);
|
||||
} else {
|
||||
wp_send_json_error($result['error']);
|
||||
}
|
||||
}
|
||||
|
||||
function miravia_update_job_status() {
|
||||
if (!current_user_can('manage_woocommerce')) { exit; }
|
||||
|
||||
$job_id = intval($_POST['job_id']);
|
||||
if(!$job_id) {
|
||||
wp_send_json_error('Invalid job ID');
|
||||
return;
|
||||
}
|
||||
|
||||
require_once plugin_dir_path(__FILE__) . 'class.feed-manager.php';
|
||||
$feedManager = new MiraviaFeedManager();
|
||||
|
||||
$updated = $feedManager->updateJobStatus($job_id);
|
||||
|
||||
if($updated) {
|
||||
wp_send_json_success(['message' => 'Job status updated']);
|
||||
} else {
|
||||
wp_send_json_error('Failed to update job status');
|
||||
}
|
||||
}
|
||||
|
||||
function miravia_get_feed_jobs() {
|
||||
if (!current_user_can('manage_woocommerce')) { exit; }
|
||||
|
||||
$page = max(1, intval($_GET['page'] ?? 1));
|
||||
$limit = 20;
|
||||
$offset = ($page - 1) * $limit;
|
||||
$status = sanitize_text_field($_GET['status'] ?? '');
|
||||
|
||||
require_once plugin_dir_path(__FILE__) . 'class.feed-manager.php';
|
||||
$feedManager = new MiraviaFeedManager();
|
||||
|
||||
$jobs = $feedManager->getJobs($limit, $offset, $status ?: null);
|
||||
$total = $feedManager->getJobCount($status ?: null);
|
||||
|
||||
wp_send_json_success([
|
||||
'jobs' => $jobs,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'pages' => ceil($total / $limit)
|
||||
]);
|
||||
}
|
||||
|
||||
function miravia_resubmit_job() {
|
||||
if (!current_user_can('manage_woocommerce')) { exit; }
|
||||
|
||||
$job_id = intval($_POST['job_id']);
|
||||
if(!$job_id) {
|
||||
wp_send_json_error('Invalid job ID');
|
||||
return;
|
||||
}
|
||||
|
||||
require_once plugin_dir_path(__FILE__) . 'class.feed-manager.php';
|
||||
$feedManager = new MiraviaFeedManager();
|
||||
|
||||
$result = $feedManager->resubmitJob($job_id);
|
||||
|
||||
if($result['success']) {
|
||||
wp_send_json_success($result);
|
||||
} else {
|
||||
wp_send_json_error($result['error']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$APIMIRAVIA = new APIMIRAVIA();
|
||||
|
||||
Reference in New Issue
Block a user