🔧 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>
208 lines
8.9 KiB
PHP
208 lines
8.9 KiB
PHP
<?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>
|