🔧 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>
175 lines
9.3 KiB
PHP
175 lines
9.3 KiB
PHP
<?php
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; }
|
|
global $wpdb;
|
|
|
|
if(isset($_POST['miravia_action_nonce'])) {
|
|
if(wp_verify_nonce(sanitize_text_field($_POST['miravia_action_nonce']), 'save_miravia_conf')) {
|
|
update_option('miravia_delay_time', sanitize_text_field($_POST['secondsNotify']));
|
|
update_option('miravia_default_status', sanitize_text_field($_POST['miravia_order_defuault_status']));
|
|
update_option('_miravia_default_stock', sanitize_text_field($_POST['_miravia_default_stock']));
|
|
update_option('miravia_transport_mode', sanitize_text_field($_POST['miravia_transport_mode']));
|
|
update_option('miravia_ean_key', sanitize_text_field($_POST['miravia_ean_key']));
|
|
update_option('miravia_default_brand', sanitize_text_field($_POST['miravia_default_brand']));
|
|
update_option('miravia_default_unit', sanitize_text_field($_POST['miravia_default_unit']));
|
|
update_option('miravia_default_unit_value', sanitize_text_field($_POST['miravia_default_unit_value']));
|
|
if(isset($_POST['miraviaDebugMode']) and sanitize_text_field($_POST['miraviaDebugMode']) == '1') {
|
|
update_option('miravia_debug_mode', '1');
|
|
}else{
|
|
update_option('miravia_debug_mode', '0');
|
|
}
|
|
if(isset($_POST['miravia_only_stock']) and sanitize_text_field($_POST['miravia_only_stock']) == '1') {
|
|
update_option('miravia_only_stock', '1');
|
|
}else{
|
|
update_option('miravia_only_stock', '0');
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
$defaultUnit = get_option('miravia_default_unit', 'units');
|
|
$defaultUnitValue = get_option('miravia_default_unit_value', '1');
|
|
$timeDelay = get_option('miravia_delay_time', 300);
|
|
$debugMode = get_option('miravia_debug_mode', '0');
|
|
$transportMode = get_option('miravia_transport_mode', 'dbm');
|
|
$defaultBrand = get_option('miravia_default_brand', 'No Brand');
|
|
$statuses = wc_get_order_statuses();
|
|
$statusDefaultSelected = get_option('miravia_default_status', 'wc-processing');
|
|
|
|
$categories = get_terms( ['taxonomy' => 'product_cat', 'hide_empty' => false] );
|
|
// MiraviaCore::debug($categories);
|
|
// $notifies = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}options WHERE option_name LIKE '%miravia_notify%'", ARRAY_A );
|
|
// // delete_option('miravia_notify_update_stock_in');
|
|
// LOG::add("Get notifies");
|
|
// LOG::add($notifies);
|
|
?>
|
|
<div class="wrap">
|
|
<h2>Configuration</h2>
|
|
<form method="post">
|
|
<?php wp_nonce_field( 'save_miravia_conf', 'miravia_action_nonce' ); ?>
|
|
<table class="form-table">
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('Time Delay', 'miraviawoo')?>
|
|
|
|
</th>
|
|
<td>
|
|
<select name="secondsNotify">
|
|
<option value="30" <?php echo selected($timeDelay, 30,false)?>>30 secs</option>
|
|
<option value="60" <?php echo selected($timeDelay, 60,false)?>>1 min</option>
|
|
<option value="120" <?php echo selected($timeDelay, 120,false)?>>2 min</option>
|
|
<option value="240" <?php echo selected($timeDelay, 240,false)?>>4 min</option>
|
|
<option value="300" <?php echo selected($timeDelay, 300,false)?>>5 min</option>
|
|
<option value="300" <?php echo selected($timeDelay, 600,false)?>>10 min</option>
|
|
<option value="300" <?php echo selected($timeDelay, 3600,false)?>>1 h</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('Debug Mode', 'miraviawoo')?>
|
|
<p class="description"><?php echo __('This active debug mode, developer support','miraviawoo')?></p>
|
|
</th>
|
|
<td>
|
|
<input type="checkbox" value="1" name="miraviaDebugMode" <?php echo checked($debugMode, '1', false)?> />
|
|
</td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('Default Status Orders', 'miraviawoo')?>
|
|
<p class="description"><?php echo __('Set default status for Miravia Orders','miraviawoo')?></p>
|
|
</th>
|
|
<td>
|
|
<select name="miravia_order_defuault_status">
|
|
<?php
|
|
foreach($statuses as $key => $status) {
|
|
if($key == 'wc-completed' || $key == 'wc-refunded' || $key == 'wc-failed' || $key == 'wc-cancelled') { continue; }
|
|
$selected = selected($key, $statusDefaultSelected, false);
|
|
echo '<option value="'.$key.'" '.$selected.'>'.$status.'</option>';
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('Transport Mode', 'miraviawoo')?>
|
|
<p class="description"><?php echo __('Select DBM or DBS','miraviawoo')?></p>
|
|
</th>
|
|
<td>
|
|
<select name="miravia_transport_mode">
|
|
<option value="dbm" <?php selected($transportMode, 'dbm') ?>>DBM</option>
|
|
<option value="dbs" <?php selected($transportMode, 'dbs') ?>>DBS</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('Stock Default', 'miraviawoo')?>
|
|
<p class="description"><?php echo __('When products have "In Stock" without quantity, set stock to send Miravia','miraviawoo')?></p>
|
|
</th>
|
|
<td>
|
|
<input type="number" value="<?php echo get_option('_miravia_default_stock', 100)?>" name="_miravia_default_stock" />
|
|
</td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('EAN Key', 'miraviawoo')?>
|
|
<p class="description"><?php echo __('This use for extract EAN code from products, enter the meta key for your EAN code','miraviawoo')?></p>
|
|
</th>
|
|
<td>
|
|
<input type="text" name="miravia_ean_key" value="<?php echo get_option('miravia_ean_key', '')?>" />
|
|
</td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('Default Brand', 'miraviawoo')?>
|
|
<p class="description"><?php echo __('Set default Brand for your products','miraviawoo')?></p>
|
|
</th>
|
|
<td>
|
|
<select name="miravia_default_brand" class="search-select-miravia-brand">
|
|
<option value="<?php echo $defaultBrand ?>" <?php selected($defaultBrand, $defaultBrand) ?>><?php echo $defaultBrand ?></option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('Default Unit', 'miraviawoo')?>
|
|
<p class="description"><?php echo __('Set default unit for all products','miraviawoo')?></p>
|
|
</th>
|
|
<td>
|
|
<select name="miravia_default_unit">
|
|
<option <?php echo selected('Units',$defaultUnit)?>value="Units">Units</option>
|
|
<option <?php echo selected('Liters',$defaultUnit)?>value="Liters">Liters</option>
|
|
<option <?php echo selected('Kilograms',$defaultUnit)?>value="Kilograms">Kilograms</option>
|
|
<option <?php echo selected('Grams',$defaultUnit)?>value="Grams">Grams</option>
|
|
<option <?php echo selected('Milliliters',$defaultUnit)?>value="Milliliters">Milliliters</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('Default Unit Value', 'miraviawoo')?>
|
|
<p class="description"><?php echo __('Set default unit value for all products','miraviawoo')?></p>
|
|
</th>
|
|
<td>
|
|
<input type="text" name="miravia_default_unit_value" value="<?php echo $defaultUnitValue ?>" />
|
|
</td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('Default Category', 'miraviawoo')?>
|
|
<p class="description"><?php echo __('Set default unit value for all products','miraviawoo')?></p>
|
|
</th>
|
|
<td>
|
|
<select name="miravia_default_unit">
|
|
<?php
|
|
foreach($categories as $cat) {
|
|
echo "<option value='{$cat->term_id}'>{$cat->name}</option>";
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><?php echo __('Only Stock', 'miraviawoo')?>
|
|
<p class="description"><?php echo __('Check this if you want sync only stock','miraviawoo')?></p>
|
|
</th>
|
|
<td>
|
|
<input type="checkbox" value="1" name="miravia_only_stock" <?php echo checked(get_option('miravia_only_stock', '0'), '1', false)?>" />
|
|
</td>
|
|
</tr>
|
|
|
|
</table>
|
|
<input type="submit" class="button" value="<?php echo __('Save')?>" />
|
|
</form>
|
|
</div>
|