🔧 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>
65 lines
2.8 KiB
PHP
65 lines
2.8 KiB
PHP
<?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>
|