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>
This commit is contained in:
Miravia Connector Bot
2025-07-17 08:11:23 +02:00
commit a7d7dbb164
61 changed files with 8501 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
list($order, $items) = MiraviaCore::get_order_woocommerce($post->ID);
?>
<div id="miravia_order_gestion">
<?php
$package_data = get_post_meta($post->ID, '_miravia_packed_result', true);
if(isset($package_data['data']['pack_order_list'])){
$packages = [];
foreach ($package_data['data']['pack_order_list'] as $item){
if(isset($item['order_item_list'])){
foreach($item['order_item_list'] as $package){
$packages[$package['package_id']] = true;
}
}
}
foreach($packages as $p => $v) {
if($v) {
echo wp_kses('<a href="javascript:void(0)" class="miraviaprintLabel" data-id="'.$post->ID.'" data-package="'.$p.'"><i class="fa fa-print"></i> Print Shipping Label ['.$p.']</a>', wp_kses_allowed_html());
}
}
}else{
echo wp_kses(' <p>'.__('Ready to ship?','miraviawoo').'</p>
<button type="button" id="packOrderButton" data-id="'.$post->ID.'">Pack Order</button>', wp_kses_allowed_html());
}
?>
</div>

View File

@@ -0,0 +1,43 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $post;
$defaultBrand = get_option('miravia_default_brand', 'No Brand');
$productBrand = get_post_meta($post->ID, '_miravia_brand_product', true);
$productUnit = get_post_meta($post->ID, '_miravia_unit', true);
$productUnitValue = get_post_meta($post->ID, '_miravia_unit_value', true);
$defaultUnit = get_option('miravia_default_unit', 'units');
$defaultUnitValue = get_option('miravia_default_unit_value', '1');
if($productBrand) {
$defaultBrand = $productBrand;
}
?>
<div class="options_group show_if_simple show_if_external show_if_variable" style="">
<p class=" form-field miravia_brand_product_field">
<label for="miravia_brand_product"><?php echo __('Product Brand', 'miraviawoo') ?></label>
<select id="miravia_brand_product" name="miravia_brand_product" class="search-select-miravia-brand">
<option value="<?php echo $defaultBrand ?>" <?php selected($defaultBrand, $defaultBrand) ?>><?php echo $defaultBrand ?></option>
</select>
</p>
<p class=" form-field miravia_unit_type_field">
<label for="miravia_unit_type"><?php echo __('Unit Type', 'miraviawoo') ?></label>
<select id="miravia_unit_type" name="miravia_unit_type">
<option value="">Default: <?php echo $defaultUnit ?></option>
<option <?php echo selected('Units',$productUnit)?> value="Units">Units</option>
<option <?php echo selected('Liters',$productUnit)?> value="Liters">Liters</option>
<option <?php echo selected('Kilograms',$productUnit)?> value="Kilograms">Kilograms</option>
<option <?php echo selected('Grams',$productUnit)?> value="Grams">Grams</option>
<option <?php echo selected('Milliliters',$productUnit)?> value="Milliliters">Milliliters</option>
</select>
</p>
<p class=" form-field miravia_brand_product_field">
<label for="miravia_brand_product"><?php echo __('Unit Value', 'miraviawoo') ?></label>
<input type="text" name="miravia_unit_value" value="<?php echo $productUnitValue ?>" placeholder="Default: <?php echo $defaultUnitValue?>" />
</p>
</div>

View File

@@ -0,0 +1,38 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
if(isset($_GET['action']) and $_GET['action'] == 'delete') {
if(current_user_can( 'manage_options' )){
MiraviaCore::delete_account(sanitize_text_field( $_GET['id'] ));
wp_safe_redirect(admin_url("admin.php?page=miravia_settings&subpage=accounts"));
}
}
$miraviaTable = new MiraviaTable();
$miraviaTable->custom_actions = array(
'delete' => sprintf('<a href="admin.php?page=%s&subpage=%s&action=%s&id=[id]">Delete</a>', sanitize_text_field($_REQUEST['page']), sanitize_text_field($_REQUEST['subpage']), 'delete'),
);
$miraviaTable->columns = [
'name' => 'Name',
'lang' => 'Language',
'userid' => 'User ID',
'created' => 'Created',
'updated' => 'Updated'
];
$miraviaTable->data_table = $accounts = MiraviaCore::get_accounts();
$miraviaTable->total_elements = count($accounts);
$miraviaTable->prepare_items();
?>
<div class="wrap">
<form method="post" action="<?php echo admin_url('admin-ajax.php?action=miravia_authorize')?>">
<h1 class="wp-heading-inline">Miravia Seller Accounts</h1>
<input type="submit" name="authorize" class="page-title-action" value="Add Account" />
</form>
<hr class="wp-header-end">
<?php
$miraviaTable->display();
?>
</div>

View File

@@ -0,0 +1,109 @@
<?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>

View File

@@ -0,0 +1,65 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
$category = get_term(sanitize_text_field($_GET['cat_id']));
if(isset($_POST['action']) and sanitize_text_field($_POST['action']) == 'save_miravia_attr_default') {
update_term_meta($category->term_id, "_miravia_attr", sanitize_text_field($_POST['attr']));
}
$miravia_category = get_term_meta($category->term_id, '_miravia_category', true);
$token = MiraviaCore::get_miravia_account_default();
if($token) {
$token = $token['token'];
}else{
die('Error: Account is not ready');
}
$link = new MiraviaCategory($token);
$attributes = $link->getAttributes($miravia_category);
$default_attributes = get_term_meta($category->term_id, "_miravia_attr", true);
$attributes_woocommerce = wp_list_pluck( wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name' );
?>
<h1>MIRAVIA - Attributes <?php echo $category->name ?> Configuration</h1>
<form method="post">
<table width="100%">
<?php
if($attributes_woocommerce) {
foreach($attributes_woocommerce as $slug => $attr) {
// if(isset($default_attributes[$attr['name']])) {
// $value = $default_attributes[$attr['name']];
// }else{
// $value = '';
// }
// $obligatorio = '';
// if($attr['is_mandatory'] == '1') {
// $obligatorio = '*';
// }
$options = '';
if (!empty ($attributes ) ) {
foreach ( $attributes as $key => $v ) {
if($v['is_sale_prop'] == 0) {
continue;
}
$selected = '';
if($default_attributes != '' and $v['name'] == $default_attributes[$slug]) {
$selected = 'selected="selected"';
}
$options .= "<option value='{$v['name']}' {$selected}>{$v['label']}</option>";
}
}
echo wp_kses("<tr>
<td style='text-transform: capitalize;'>{$attr}</td>
<td><select class='attribute' name='attr[{$slug}]'>
<option disabled value='0'> - Select - </option>{$options}</select></td>
</tr>", wp_kses_allowed_html());
}
echo wp_kses("<button type='submit' name='action' value='save_miravia_attr_default'>Guardar Atributos</button>",wp_kses_allowed_html());
}else{
echo esc_html('No hay atributos en el id ' . $category->term_id);
}
?>
</table>
</form>

View File

@@ -0,0 +1,10 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
// $brands = $MIRAVIAWOO->client->get_brands(1);
// die('<pre>'.print_r($brands, true).'</pre>');
?>
<div class="wrap">
<h2>Brands</h2>
</div>

View File

@@ -0,0 +1,45 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
?>
<h1>MIRAVIA - Category Configuration</h1>
<?php
$token = MiraviaCore::get_miravia_account_default();
if($token) {
$token = $token['token'];
}else{
die('Error: Account is not ready');
}
$link = new MiraviaCategory($token);
$miravia_categories = $link->getCategories(true);
if(isset($_POST['action']) and sanitize_text_field($_POST['action']) == 'save_miravia_categories') {
if(is_array($_POST['miravia_category'])) {
foreach($_POST['miravia_category'] as $woocommerce_cat_id => $miravia_cat) {
update_term_meta(sanitize_text_field($woocommerce_cat_id), "_miravia_category", sanitize_text_field($miravia_cat));
}
}
}
$woocommerce_categories = get_terms('product_cat');
?>
<form method="post">
<table width="100%">
<thead>
<td>WooCommerce Category</td>
<td>MIRAVIA Category</td>
<td>Opciones</td>
</thead>
<?php
foreach($woocommerce_categories as $category) {
$selected = get_term_meta($category->term_id, "_miravia_category", true);
echo wp_kses("<tr>
<td>{$category->name}</td>
<td>".MiraviaCore::select_category($miravia_categories, array('select' => $selected, 'name' => 'miravia_category['.$category->term_id.']'))."</td>
<td>
<a href='?page=miravia_settings&subpage=attributes&cat_id={$category->term_id}'>Atributos por defecto</a>
</td>
</tr>", wp_kses_allowed_html());
}
?>
<button type="submit" name="action" value="save_miravia_categories">Guardar Categorias</button>
</table>
</form>

View File

@@ -0,0 +1,175 @@
<?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>

View File

@@ -0,0 +1,81 @@
<?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>

View File

@@ -0,0 +1,29 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
?>
<div class="wrap">
<div class="region_config_dashboard">
<img style="width:300px" src="<?php echo plugins_url('assets/img/miravia-logo-new.svg', MIRAVIA_ASSETS_PATH)?>" />
<h2>Dashboard</h2>
<p>Welcome to Miravia Dashboard for WooCommerce, manage your products on Miravia Store and download orders on your WooCommerce site.</p>
<a href="admin.php?page=miravia_settings&subpage=orders" class="btn_config">
<h4><i class="fa fa-file"></i> Orders</h4>
<p>Manage orders from Miravia, download and change status from your WooCommerce</p>
</a>
<a href="admin.php?page=miravia_settings&subpage=profiles" class="btn_config">
<h4><i class="fa-solid fa-tree"></i> Profiles</h4>
<p>Create o Edit your profiles to send products to Miravia</p>
</a>
<a href="admin.php?page=miravia_settings&subpage=products" class="btn_config">
<h4><i class="fa-solid fa-store"></i> Products</h4>
<p>View Miravia products, status, stock and connect with your WooCommerce products</p>
</a>
<a href="admin.php?page=miravia_settings&subpage=configuration" class="btn_config">
<h4><i class="fa-solid fa-gear"></i> Configuration</h4>
<p>Change plugin configuration for attributes, default values, etc.</p>
</a>
<div class="clear"></div>
<p>Connector version <?php echo MIRAVIA_WOO_VERSION ?> (Build <?php echo MIRAVIA_BUILD_VERSION ?>)</p>
</div>
</div>

View File

@@ -0,0 +1,49 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
$id = sanitize_text_field($_GET['id']);
$jobs = MiraviaCore::get_job_detail($id);
$miraviaTable = new MiraviaTable();
$data = array();
// MiraviaCore::debug($jobs);
if($jobs) {
$token = $jobs[0];
$miraviaTable->custom_actions = array(
'download' => sprintf('<a href="/wp-admin/post.php?post=[id_woocommerce]&action=edit" target="_blank">Edit</a>' ),
'view' => '<a href="https://www.miravia.es/p/i[id_miravia].html" target="_blank">View on Miravia</a>',
);
$miraviaTable->columns = [
'name' => 'SKU',
'id_miravia' => 'ID Miravia',
'id_woocommerce' => 'ID WooCommerce',
'lastError' => 'Last Error',
'created' => 'Created',
'updated' => 'Updated',
'status_text' => 'Status'
];
foreach($jobs as $k => $p) {
$data[] = array(
'name' => $p['sku'],
'id_miravia' => $p['id_miravia'],
'id_woocommerce' => $p['id_woocommerce'],
'lastError' => $p['lastError'],
'created' => date('d-m-Y H:i:s', strtotime($p['created'])),
'updated' => date('d-m-Y H:i:s', strtotime($p['updated'])),
'status_text' => $p['status_text']
);
}
}
// die('<pre>' . print_r($data, true) . '</pre>');
$miraviaTable->data_table = $data;
$miraviaTable->total_elements = count($data);
$miraviaTable->prepare_items();
?>
<div class="wrap">
<h2>Job Detail</h2>
<?php echo $miraviaTable->display(); ?>
</div>

View File

@@ -0,0 +1,208 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
if($_GET['id']) {
$id = sanitize_text_field($_GET['id']);
$prof =MiraviaCore::get_profiles($id);
}else{
exit('Validation error');
}
$token = MiraviaCore::get_miravia_account_default();
if($token) {
$token = $token['token'];
}else{
die('Error: Account is not ready');
}
$link = new MiraviaCategory($token);
$profiles = MiraviaCore::get_accounts();
if($profiles) {
$category = new MiraviaCategory($token);
$tree = $category->getCategories();
}
$attributes = $link->getAttributes($prof['miravia_category']);
// var_dump($prof['config']);
try {
$default_attributes = $prof['config'] ? json_decode($prof['config'], true) : [];
}catch(Exception $e) {
$default_attributes = [];
}
// MiraviaCore::debug($default_attributes);
$attributes_woocommerce = wp_list_pluck( wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name' );
if(isset($_POST['action']) and sanitize_text_field($_POST['action']) == 'save_miravia_attr_default') {
$default_attributes = sanitize_text_field($_POST['attr']);
$args = array('config' => json_encode(array('attr' => sanitize_text_field($_POST['attr']))));
LOG::add($args);
if(MiraviaCore::update_profile($args, array('id' => $id))) {
echo esc_html('Attributes profile saved');
}
}
//Save data
if(isset($_POST['action']) and sanitize_text_field($_POST['action']) == 'update_profile') {
if($_POST['description'] == '') {
echo "<p>Profile need description</p>";
}elseif ($_POST['tax_input']['product_cat'] == null) {
echo "<p>Profile need categories</p>";
}else{
$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));
$saveProfile = MiraviaCore::update_profile(array(
'name' => sanitize_text_field($_POST['description']),
'accounts_id' => $acounts_recibed,
'categories' => $categories_recibed,
'miravia_category' => sanitize_text_field($_POST['miravia_category'])
), array('id' => $id));
if($saveProfile) {
wp_safe_redirect('?page=miravia_settings&subpage=profiles');
}
}
}
//Rules
$miraviaTable = new MiraviaTable([
'sccren' => 'miravia_rules'
]);
$miraviaTable->custom_actions = array(
'edit' => sprintf('<a href="?page=%s&subpage=%s&action=%s&id=[id]">Editar</a>', sanitize_text_field($_REQUEST['page']), 'edit_rule', 'edit', ),
'delete' => sprintf('<a href="?page=%s&subpage=%s&action=%s&id=[id]">Eliminar</a>', sanitize_text_field($_REQUEST['page']), sanitize_text_field($_REQUEST['subpage']), 'delete'),
);
$miraviaTable->columns = [
'id' => "ID",
'name' => "Name",
'created' => 'Created',
'updated' => 'Updated'
];
$miraviaTable->default_column_name = 'name_rule';
$rules = MiraviaCore::get_rules(false, "profile_id = {$id} or profile_id = '0'");
$miraviaTable->data_table = $rules;
$miraviaTable->total_elements = count($rules);
$miraviaTable->prepare_items();
?>
<div class="wrap miravia-pane">
<h1 class="wp-heading-inline">Edit Profile</h1>
<hr class="wp-header-end">
<div class="text-sm font-medium text-center text-gray-500">
<ul style="display:flex" class="mv-tab-nav">
<li>
<a href="javascript:void(0);" data-tab="profile" class="mv-bt-tab active" style="margin-right:10px">Profile</a>
</li>
<li>
<a href="javascript:void(0);" data-tab="attributes" class="mv-bt-tab" style="margin-right:10px">Attributes</a>
</li>
<li>
<a href="javascript:void(0);" data-tab="rules" class="mv-bt-tab" style="margin-right:10px">Rules</a>
</li>
</ul>
</div>
<div class="mv-tabs">
<div class="mv-tab mv-tab-active" data-tab="profile">
<form method="post">
<input type="hidden" name="action" value="update_profile" />
<table class="form-table">
<tr valign="top">
<td scope="row"><?php echo __('Description Profile', 'miraviawoo')?>
<span class="description"><?php echo __('Describe your Profile, this use on admin site only') ?></span>
</td>
<td>
<input type="text" name="description" value="<?php echo $prof['name']?>" />
</td>
</tr>
<tr>
<td>Categories
<span class="description">Select the categories with this profile</span>
</td>
<td>
<ul class="miravia_categories_select" style="height: 350px; overflow: auto; border:1px solid #ccc; padding: 15px;">
<?php wp_terms_checklist(0, array(
'taxonomy' => 'product_cat',
'selected_cats' => explode(",", $prof['categories'])
));?>
</ul>
</td>
</tr>
<tr>
<td>Miravia Category</td>
<td>
<select name="miravia_category" class="search-select-miravia">
<?php
foreach($tree as $cat) {
$selected = "";
if($cat['id'] == $prof['miravia_category']) {
$selected = 'selected="selected"';
}
echo "<option value='{$cat['id']}' {$selected}>{$cat['name']}</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Seller Accounts</td>
<td>
<?php
$profiles_array = explode(',', $prof['accounts_id']);
foreach($profiles as $profile) {
$selected = '';
if(in_array($profile['id'], $profiles_array)) {
$selected = 'checked="checked"';
}
echo "<p><input type='checkbox' name='profile[]' {$selected} value='{$profile['id']}' /> {$profile['name']}</p>";
}
?>
</td>
</tr>
</table>
<input type="submit" name="submit" class="button" value="Update profile" />
<button type="button" class="button sendProductsMiravia" data-profile="<?php echo $id?>">Send Products</button>
</form>
</div>
<div class="mv-tab" data-tab="attributes">
<form method="post">
<input type="hidden" name="action" value="save_miravia_attr_default" />
<table width="100%">
<?php
if($attributes_woocommerce) {
foreach($attributes_woocommerce as $slug => $attr) {
$options = '';
if (!empty ($attributes ) ) {
foreach ( $attributes as $key => $v ) {
if($v['is_sale_prop'] == 0) {
continue;
}
$selected = '';
if($default_attributes != '' and isset($default_attributes[$slug]) and $v['name'] == $default_attributes[$slug]) {
$selected = 'selected="selected"';
}
$options .= "<option value='{$v['name']}' {$selected}>{$v['label']}</option>";
}
}
echo "<tr>
<td style='text-transform: capitalize;'>{$attr}</td>
<td><select class='attribute' name='attr[{$slug}]'>
<option value='0'> - Select - </option>{$options}</select></td>
</tr>";
}
}
?>
</table>
<input type="submit" name="submit" class="button" value="Save Attributes" />
</form>
</div>
<div class="mv-tab" data-tab="rules">
<?php
$miraviaTable->display();
?>
</div>
</div>
</div>

View File

@@ -0,0 +1,129 @@
<?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>

View File

@@ -0,0 +1,45 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
$jobs = MiraviaCore::get_jobs();
$miraviaTable = new MiraviaTable();
$data = array();
if($jobs) {
$token = $jobs[0];
$miraviaTable->custom_actions = array(
'detail' => sprintf('<a href="?page=%s&subpage=%s&id=[name]">Detail</a>', sanitize_text_field($_REQUEST['page']), 'detail-job' ),
'download' => sprintf('<a href="javascript:void(0);" class="checkJob" data-token="[token]" data-id="[name]">Check Status</a>', sanitize_text_field($_REQUEST['page']), sanitize_text_field($_REQUEST['subpage']), 'download', ),
'cancel' => sprintf('<a href="javascript:void(0);" class="cancelJob" data-token="[token]" data-id="[name]">Cancel Job</a>', sanitize_text_field($_REQUEST['page']), sanitize_text_field($_REQUEST['subpage']), 'download', ),
);
$miraviaTable->columns = [
'name' => 'Job',
'status' => 'Status',
'total' => 'Total Products',
'updated' => 'Updated',
];
foreach($jobs as $k => $p) {
$data[] = array(
'name' => $p['job_id'],
'status' => '<span class="status_result">...</span>',
'token' => $p['token'],
'total' => $p['total'],
'updated' => date('d-m-Y H:i:s', strtotime($p['updated'])),
);
}
}
// die('<pre>' . print_r($data, true) . '</pre>');
$miraviaTable->data_table = $data;
$miraviaTable->total_elements = count($data);
$miraviaTable->prepare_items();
?>
<div class="wrap">
<h2>Miravia Jobs</h2>
<?php echo $miraviaTable->display(); ?>
</div>

View File

@@ -0,0 +1,63 @@
<?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>

View File

@@ -0,0 +1,7 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
$result = MiraviaCore::get_profile_by_product('LO52027');
MiraviaCore::debug($result);

View File

@@ -0,0 +1,72 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
$page = isset($_GET['paged']) ? intval($_GET['paged']) - 1 : 1;
$pagesize = 10;
$token = MiraviaCore::get_miravia_account_default();
if($token) {
$token = $token['token'];
}else{
die('Error: Account is not ready');
}
if(isset($_GET['action']) and $_GET['action'] == 'disconect') {
if(current_user_can( 'manage_options' )){
MiraviaCore::disconnect_product(sanitize_text_field( $_GET['id'] ));
wp_safe_redirect(admin_url("admin.php?page=miravia_settings&subpage=products"));
}
}
$link = new MiraviaLink($token);
$products = MiraviaCore::get_local_products($page, $pagesize);
// MiraviaCore::debug([$page, $pagesize, $products], false);
$miraviaTable = new MiraviaTable();
$miraviaTable->custom_actions = array(
'woocommerce' => '<a href="admin.php?page=miravia_settings&subpage=products&action=disconect&id=[id_woocommerce]">Disconect</a>',
//'upload' => '<a href="javascript:void(0)" data-profile="[ID]" class="sendProductsMiravia">Upload products</a>'
);
$data = array();
$miraviaTable->columns = [
'sku' => "SKU",
'name' => "Title",
'variationsTotal' => 'Total Variations',
'price' => "Price",
'lastError' => "Last Error",
'status_text' => "Status",
'created' => 'Created',
'updated' => 'Updated',
'actions' => 'Actions',
];
foreach($products as $k => $p) {
try {
$_product = new WC_Product($p['id_woocommerce']);
$data[] = array(
'id_woocommerce' => $p['id_woocommerce'],
'sku' => $p['sku'],
'name' => $p['name'],
'variationsTotal' => $p['variationsTotal'],
'price' => $_product->get_price_html(),
'lastError' =>$p['lastError'],
'status_text' => $p['status_text'],
'created' => $p['created'],
'updated' => $p['updated'],
'actions' => $p['id_miravia'] != 0 ? "<a target='_blank' href='https://www.miravia.es/p/i{$p['id_miravia']}.html' class='button'>View on Miravia</a>" : 'Not on Miravia',
);
}catch(Exception $e){
continue;
}
}
$miraviaTable->data_table = $data;
$miraviaTable->total_elements = count($data);
$miraviaTable->prepare_items();
?>
<div class="wrap">
<h2>Products</h2>
<p><?php echo __('Your products for Miravia', 'miravia')?></p>
<?php $miraviaTable->display(); ?>
</div>

View File

@@ -0,0 +1,58 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
$page = isset($_GET['paged']) ? intval($_GET['paged']) - 1 : '0';
$pagesize = 10;
$token = MiraviaCore::get_miravia_account_default();
if($token) {
$token = $token['token'];
}else{
die('Error: Account is not ready');
}
$link = new MiraviaLink($token);
$products = $link->getProductList($page);
// MiraviaCore::debug($products['data'], false);
$miraviaTable = new MiraviaTable();
$data = array();
$miraviaTable->custom_actions = array(
'view' => '<a href="https://www.miravia.es/p/i[id].html">View</a>',
//'upload' => '<a href="javascript:void(0)" data-profile="[ID]" class="sendProductsMiravia">Upload products</a>'
);
$miraviaTable->columns = [
'id' => "ID",
'image' => "Image",
'name' => "Name",
'price' => "Price",
'status' => "Status",
'created' => 'Created',
'updated' => 'Updated',
'connect' => 'Connect'
];
foreach($products['data']['products'] as $k => $p) {
$image = count($p['images']) > 0 ? $p['images'][0] : false;
$sku = $p['skus'][0]['SellerSku'];
$id_remote = $p['item_id'];
$data[] = array(
'id' => $id_remote,
'image' => $image ? "<img width='50px' src='{$image}' />" : '',
'name' => $p['attributes']['name'],
'price' => number_format($p['skus'][0]['price'], 2) . '€',
'status' => $p['status'],
'created' => date('d-m-Y H:i', intval($p['created_time'])),
'updated' => date('d-m-Y H:i', intval($p['updated_time'])),
'connect' => "<a href='javascript:void(0);' class='button connectProductRemote' data-sku='{$sku}' data-id='{$id_remote}'>Connect</a>"
);
}
// die('<pre>' . print_r($data, true) . '</pre>');
$miraviaTable->data_table = $data;
$miraviaTable->total_elements = $products['data']['total_products'];
$miraviaTable->prepare_items();
?>
<div class="wrap">
<h2>Miravia Products</h2>
<p><?php echo __('Your remote products created in Miravia account', 'miravia')?></p>
<?php $miraviaTable->display(); ?>
</div>

View File

@@ -0,0 +1,39 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
if(isset($_GET['action']) and $_GET['action'] == 'delete') {
if(current_user_can( 'manage_options' )){
MiraviaCore::delete_profile(sanitize_text_field( $_GET['id'] ));
wp_safe_redirect(admin_url("admin.php?page=miravia_settings&subpage=profiles"));
}
}
$miraviaTable = new MiraviaTable([
'sccren' => 'miravia_profiles'
]);
$miraviaTable->custom_actions = array(
'edit' => sprintf('<a href="?page=%s&subpage=%s&action=%s&id=[id]">Editar</a>', sanitize_text_field($_REQUEST['page']), 'edit_profile', 'edit', ),
'delete' => sprintf('<a href="?page=%s&subpage=%s&action=%s&id=[id]">Eliminar</a>', sanitize_text_field($_REQUEST['page']), sanitize_text_field($_REQUEST['subpage']), 'delete'),
'upload' => '<a href="javascript:void(0)" data-profile="[id]" class="sendProductsMiravia">Upload products</a>'
);
$miraviaTable->columns = [
'id' => "ID",
'name' => "Name",
'created' => 'Created',
'updated' => 'Updated',
'sync' => 'Status Sync'
];
$profiles = MiraviaCore::get_profiles();
$miraviaTable->data_table = $profiles;
$miraviaTable->total_elements = count($profiles);
$miraviaTable->prepare_items();
?>
<div class="wrap">
<h1 class="wp-heading-inline">Mapping Profiles</h1>
<a href="<?php echo admin_url('admin.php?page=miravia_settings&subpage=create_profile')?>" class="page-title-action">Create Profile</a>
<hr class="wp-header-end">
<?php
$miraviaTable->display();
?>
</div>

View File

@@ -0,0 +1,37 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
$miraviaTable = new MiraviaTable([
'sccren' => 'miravia_rules'
]);
if(isset($_GET['action']) and $_GET['action'] == 'delete') {
if(current_user_can( 'manage_options' )){
MiraviaCore::delete_rule(sanitize_text_field( $_GET['id'] ));
wp_safe_redirect(admin_url("admin.php?page=miravia_settings&subpage=rules"));
}
}
$miraviaTable->custom_actions = array(
'edit' => sprintf('<a href="?page=%s&subpage=%s&action=%s&id=[id]">Editar</a>', sanitize_text_field($_REQUEST['page']), 'edit_rule', 'edit', ),
'delete' => sprintf('<a href="?page=%s&subpage=%s&action=%s&id=[id]">Eliminar</a>', sanitize_text_field($_REQUEST['page']), sanitize_text_field($_REQUEST['subpage']), 'delete'),
);
$miraviaTable->columns = [
'id' => "ID",
'name' => "Name",
'created' => 'Created',
'updated' => 'Updated'
];
$miraviaTable->default_column_name = 'name_rule';
$rules = MiraviaCore::get_rules();
$miraviaTable->data_table = $rules;
$miraviaTable->total_elements = count($rules);
$miraviaTable->prepare_items();
?>
<div class="wrap">
<h1 class="wp-heading-inline">Rules</h1>
<a href="<?php echo admin_url('admin.php?page=miravia_settings&subpage=add-rule')?>" class="page-title-action">Create Rule</a>
<hr class="wp-header-end">
<?php
$miraviaTable->display();
?>
</div>

View File

@@ -0,0 +1,11 @@
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
global $MIRAVIAWOO;
if(!isset($_GET['subpage'])) {
$page = 'dashboard';
}else{
$page = sanitize_text_field($_GET['subpage']);
}
require_once(MIRAVIA_VIEWS_PATH . 'pages/' . $page . '.php');