Files
MiraviaConnector/connector-miravia/views/pages/orders.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

64 lines
2.5 KiB
PHP

<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
if(isset($_GET['account'])) {
$link = new MiraviaLink(sanitize_text_field($_GET['token']));
$orders = $link->getOrders('2022-09-01');
$miraviaTable = new MiraviaTable();
// die('<pre>'.print_r($orders,true).'</pre>');
$data = array();
$miraviaTable->custom_actions = array(
'download' => sprintf('<a href="javascript:void(0);" class="download_order" data-account="'.sanitize_text_field($_GET['account_id']).'" data-token="'.sanitize_text_field($_GET['token']).'" data-id="[id]">Download</a>', sanitize_text_field($_REQUEST['page']), sanitize_text_field($_REQUEST['subpage']), 'download', ),
);
$miraviaTable->columns = [
'id' => "Order Number",
'name' => 'Customer Name',
'price' => "Price",
'statuses' => "Status",
'created_at' => 'Created',
'updated_at' => 'Updated',
];
foreach($orders['data']['orders'] as $k => $p) {
$data[] = array(
'id' => $p['order_number'],
'name' => $p['customer_first_name'],
'price' => number_format($p['price'], 2) . '€',
'statuses' => $p['statuses'][0],
'created_at' => date('d-m-Y H:i', strtotime($p['created_at'])),
'updated_at' => date('d-m-Y H:i', strtotime($p['updated_at'])),
);
}
// die('<pre>' . print_r($data, true) . '</pre>');
$miraviaTable->data_table = $data;
$miraviaTable->total_elements = $orders['data']['count'];
$miraviaTable->prepare_items();
}else{
$accounts = MiraviaCore::get_accounts();
$html_accounts = "";
if(count($accounts) == 1) {
wp_safe_redirect( "?page=miravia_settings&subpage=orders&account={$accounts[0]['name']}&token={$accounts[0]['token']}&account_id={$accounts[0]['id']}", 301);
die();
}
foreach($accounts as $a) {
$html_accounts .= "<a href='?page=miravia_settings&subpage=orders&account={$a['name']}&token={$a['token']}&account_id={$a['id']}'>{$a['name']} ({$a['email']})</a>";
}
}
?>
<div class="wrap">
<h2>Miravia Orders</h2>
<?php if(!isset($_GET['account'])) {
echo wp_kses('<p>'.__('Select an account', 'miravia').'</p>', array('p' => array()));
echo wp_kses($html_accounts, array('a' => array()));
}else{
echo wp_kses('<p>'.__('Orders by account', 'miravia').' '.sanitize_text_field($_GET['account']).'</p>', array('p' => array()));
$miraviaTable->display();
} ?>
</div>