Files
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

130 lines
6.2 KiB
PHP

<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
$categories_end = array();
if($_GET['id']) {
$id = sanitize_text_field($_GET['id']);
$rule =MiraviaCore::get_rules($id);
}else{
exit('Validation error');
}
$profiles = MiraviaCore::get_profiles();
$accounts = MiraviaCore::get_accounts();
$actions_json = json_decode($rule['action_json']);
$categories = get_terms(array('taxonomy' => 'product_cat'));
foreach($categories as $cat) {
$categories_end[] = (object) array('lk_option' => $cat->name, 'lk_value' => $cat->term_id);
}
if(isset($_POST['action']) and sanitize_text_field($_POST['action']) == 'save_rule') {
$filterDecoded = urldecode($_POST['filter_data']);
$actionsDecoded = urldecode($_POST['action_detail_data']);
$account = sanitize_text_field($_POST['apply_accounts']);
$profile = sanitize_text_field($_POST['apply_profile']);
$arrayDatosRule = array(
'name_rule' => sanitize_text_field($_POST['name_rule']),
'accounts' => intval($account),
'profile_id' => intval($profile),
'rules_json' => $filterDecoded,
'action_json' => $actionsDecoded,
'action_type' => sanitize_text_field($_POST['action_type'])
);
$saveProfile = MiraviaCore::update_rule($arrayDatosRule, array('id' => $id));
if($saveProfile) {
$rule = $arrayDatosRule;
echo esc_html('Rule saved');
}
}
// var_dump($rule);
?>
<script>
const action_detail = <?php echo $rule['action_json']?>;
const filter = <?php echo $rule['rules_json']?>;
const categories = <?php echo json_encode($categories_end)?>;
</script>
<div class="wrap miravia-pane">
<h1 class="wp-heading-inline">Edit Rule to Miravia</h1>
<hr class="wp-header-end">
<form id="miravia_rules_form" method="post">
<input type="hidden" name="action" value="save_rule" />
<table class="form-table">
<tr valign="top">
<th scope="row"><?php echo __('Name of Rule', 'miraviawoo')?>
<span class="description"><?php echo __('Describe your rule', 'miraviawoo')?></span>
</th>
<td>
<input type="text" name="name_rule" placeholder="Rule Name..." value="<?php echo $rule['name_rule']?>" />
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo __('Accounts', 'miraviawoo')?>
<span class="description"><?php echo __('Select all or one account to apply this rule', 'miraviawoo')?></span>
</th>
<td>
<select name="apply_accounts">
<option value="0">Apply all accounts</option>
<?php
$accounts_array = explode(',', $rule['accounts']);
foreach($accounts as $acc) {
$selected = '';
if(in_array($acc['id'], $accounts_array)) {
$selected = 'selected="selected"';
}
echo "<option value='{$acc['id']}' {$selected}>{$acc['name']}</option>";
}
?>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo __('Profile', 'miraviawoo')?>
<span class="description"><?php echo __('Select all or one profile to apply this rule', 'miraviawoo')?></span>
</th>
<td>
<select name="apply_profile">
<option value="0">Apply all profiles</option>
<?php
foreach($profiles as $pro) {
$selected = '';
if($pro['id'] == $rule['profile_id']) {
$selected = 'selected="selected"';
}
echo " <option value='{$pro['id']}' {$selected}>{$pro['name']}</option>";
}
?>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo __('Rules', 'miraviawoo')?>
<span class="description"><?php echo __('Create a conditionals to apply this rule', 'miraviawoo')?></span>
</th>
<td>
<div id="filter_editor" style="border:1px solid #CCC; padding:10px; background-color:#FFF;border-radius:5px"></div>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo __('Actions', 'miraviawoo')?>
<span class="description"><?php echo __('If conditionals is true, what happens?', 'miraviawoo')?></span>
</th>
<td>
<div style="border:1px solid #CCC; padding:10px; margin-top:20px; background-color:#FFF; border-radius:5px">
<select id="action_type" name="action_type" style="margin-bottom:10px">
<option value="remove" <?php echo $rule['action_type'] == 'remove' ? 'selected="selected"' : ''?>>Do not send these products</option>
<option value="only" <?php echo $rule['action_type'] == 'only' ? 'selected="selected"' : ''?>>Only send these products</option>
<option value="price_stock" <?php echo $rule['action_type'] == 'price_stock' ? 'selected="selected"' : ''?>>Change price or stock</option>
<option value="name" <?php echo $rule['action_type'] == 'name' ? 'selected="selected"' : ''?>>Name</option>
</select>
<div id="action_detail"></div>
</div>
</td>
</tr>
</table>
<input type="submit" name="submit" class="button" value="Save Rule" />
</form>
</div>