🔧 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>
110 lines
5.0 KiB
PHP
110 lines
5.0 KiB
PHP
<?php
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; }
|
|
$categories_end = array();
|
|
$categories = get_terms(array('taxonomy' => 'product_cat'));
|
|
foreach($categories as $cat) {
|
|
$categories_end[] = (object) array('lk_option' => $cat->name, 'lk_value' => $cat->term_id);
|
|
}
|
|
$profiles = MiraviaCore::get_profiles();
|
|
$accounts = MiraviaCore::get_accounts();
|
|
if(isset($_POST['action']) and sanitize_text_field($_POST['action']) == 'save_rule') {
|
|
if(sanitize_text_field($_POST['name_rule']) != "") {
|
|
$account = sanitize_text_field($_POST['apply_accounts']);
|
|
$profiles = sanitize_text_field($_POST['apply_profile']);
|
|
$filterDecoded = urldecode($_POST['filter_data']);
|
|
$actionsDecoded = urldecode($_POST['action_detail_data']);
|
|
$saveProfile = MiraviaCore::add_rule(array(
|
|
'name_rule' => sanitize_text_field($_POST['name_rule']),
|
|
'accounts' => $account,
|
|
'profile_id' => $profiles,
|
|
'rules_json' => $filterDecoded,
|
|
'action_json' => $actionsDecoded
|
|
));
|
|
if($saveProfile) {
|
|
wp_safe_redirect('?page=miravia_settings&subpage=rules');
|
|
}
|
|
}else{
|
|
echo "Error: Rule need Name";
|
|
}
|
|
}
|
|
?>
|
|
<script>
|
|
const filter = [];
|
|
const categories = <?php echo json_encode($categories_end)?>;
|
|
</script>
|
|
<div class="wrap miravia-pane">
|
|
<h1 class="wp-heading-inline">Add 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..." />
|
|
</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
|
|
foreach($accounts as $acc) {
|
|
echo " <option value='{$acc['id']}'>{$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">Select one profile</option>
|
|
<?php
|
|
foreach($profiles as $pro) {
|
|
echo "<option value='{$pro['id']}'>{$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" style="margin-bottom:10px">
|
|
<option value="remove">Do not send these products</option>
|
|
<option value="only" >Only send these products</option>
|
|
<option value="price_stock">Change price or stock</option>
|
|
<option value="name">Name</option>
|
|
</select>
|
|
<div id="action_detail"></div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
</table>
|
|
<input type="submit" name="submit" class="button" value="Save Rule" />
|
|
</form>
|
|
</div>
|