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

81 lines
3.2 KiB
PHP

<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
$profiles = MiraviaCore::get_accounts();
if($profiles) {
$category = new MiraviaCategory($profiles[0]['token']);
$tree = $category->getCategories();
}
//Save data
if(isset($_POST['action']) and sanitize_text_field($_POST['action']) == 'save_profile') {
$categories_recibed = implode(",", array_map('sanitize_text_field', $_POST['tax_input']['product_cat']));
$acounts_recibed = implode(",", array_map('sanitize_text_field', $_POST['profile']));
// die(var_dump($categories_recibed));
if($_POST['description'] == '') {
echo "<p>Profile need description</p>";
}else{
$saveProfile = MiraviaCore::add_profile(array(
'name' => sanitize_text_field($_POST['description']),
'accounts_id' => $acounts_recibed,
'categories' => $categories_recibed,
'miravia_category' => sanitize_text_field($_POST['miravia_category'])
));
if($saveProfile) {
wp_safe_redirect(admin_url("admin.php?page=miravia_settings&subpage=edit_profile&action=edit&id={$saveProfile}"));
}
}
}
?>
<div class="wrap miravia-pane">
<h1 class="wp-heading-inline">Create new profile</h1>
<hr class="wp-header-end">
<form method="post">
<input type="hidden" name="action" value="save_profile" />
<table class="form-table">
<tr valign="top">
<th scope="row"><?php echo __('Description Profile', 'miraviawoo')?></th>
<td>
<input required type="text" name="description" value="" />
</td>
</tr>
<tr>
<td>Categories
<span class="description">Select the categories with this profile</span>
</td>
<td>
<ul class="miravia_categories_select" style="height: 400px; overflow: auto;">
<?php wp_terms_checklist(0, array(
'taxonomy' => 'product_cat'
));?>
</ul>
</td>
</tr>
<tr>
<td>Miravia Category</td>
<td>
<select name="miravia_category" class="search-select-miravia">
<?php
foreach($tree as $cat) {
echo "<option value='{$cat['id']}'>{$cat['name']}</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Seller Accounts</td>
<td>
<?php
foreach($profiles as $profile) {
echo "<p><input type='checkbox' name='profile[]' value='{$profile['id']}' /> {$profile['name']}</p>";
}
?>
</td>
</tr>
</table>
<input type="submit" name="submit" class="button" value="Save profile" />
</form>
</div>