🔧 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>
120 lines
3.7 KiB
PHP
120 lines
3.7 KiB
PHP
<?php
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; }
|
|
|
|
if( !class_exists('MIRAVIABase') ) {
|
|
class MIRAVIABase {
|
|
|
|
private $url = "https://api.miravia.es/rest";
|
|
private $token = "50000701b37tSEfdXdiuAq0yiimwLWEyVIf3lsRgyp2yLqwX61b895957sebFoS";
|
|
private $appSecret = "8nxjS2TDTevc0AwmXh7AbKQL4XnuaE7t";
|
|
private $appKey = "500406";
|
|
private $client = false;
|
|
function __construct(){
|
|
if(!$this->client) {
|
|
$this->client = new IopClient($this->url,$this->appKey,$this->appSecret);
|
|
}
|
|
}
|
|
|
|
function secure(){
|
|
if(!$this->client) {
|
|
die(json_encode(array('error' => true, 'message' => 'No se ha establecido la conexión')));
|
|
}
|
|
}
|
|
|
|
function get($endpoint = '', $params = array()) {
|
|
$this->secure();
|
|
$request = new IopRequest($endpoint,'GET');
|
|
|
|
if($params) {
|
|
foreach($params as $k => $v) {
|
|
$request->addApiParam($k,$v);
|
|
}
|
|
}
|
|
|
|
try{
|
|
$result = $this->client->execute($request,$this->token);
|
|
}catch(Exception $e) {
|
|
return $this->error_control($e);
|
|
}
|
|
|
|
$resp = json_decode($result, true);
|
|
return $this->response($resp);
|
|
}
|
|
|
|
function post($endpoint = '', $data = array()) {
|
|
$this->secure();
|
|
$request = new IopRequest($endpoint);
|
|
|
|
if($data) {
|
|
foreach($data as $k => $v) {
|
|
$request->addApiParam($k,$v);
|
|
}
|
|
}
|
|
try{
|
|
$result = $this->client->execute($request, $this->token);
|
|
}catch(Exception $e) {
|
|
return $this->error_control($e);
|
|
}
|
|
|
|
$resp = json_decode($result, true);
|
|
return $this->response($resp);
|
|
}
|
|
|
|
function response($result) {
|
|
if(isset($result['data'])) {
|
|
return $result['data'];
|
|
}else{
|
|
//Control de errores
|
|
return $this->error_control($result);
|
|
}
|
|
}
|
|
|
|
function error_control($resp) {
|
|
// die('<pre>'.print_r($resp, true).'</pre>');
|
|
if($resp->code != '0') {
|
|
if(isset($resp->detail)) {
|
|
$errors = $resp->detail;
|
|
}else{
|
|
$errors = [$resp->message];
|
|
}
|
|
return array(
|
|
'code' => $resp->code,
|
|
'errors' => $errors
|
|
);
|
|
}else{
|
|
return array(
|
|
'code' => '-1',
|
|
'errors' => array($resp)
|
|
);
|
|
}
|
|
}
|
|
|
|
function get_images_batch($batch_id) {
|
|
return $this->get('/image/response/get', array('batch_id' => $batch_id));
|
|
}
|
|
|
|
function get_brands($page) {
|
|
|
|
$to = $page * 20;
|
|
$from = $to - 20;
|
|
return $this->get('/category/brands/query', array('start_row' => $from, "page_size" => $to));
|
|
}
|
|
|
|
|
|
function get_orders($args = array()) {
|
|
return $this->get('/orders/get', $args);
|
|
}
|
|
|
|
function get_order($args = array()) {
|
|
return $this->get('/order/get', $args);
|
|
}
|
|
|
|
function get_orders_items($args = array()) {
|
|
return $this->get('/order/items/get', $args);
|
|
}
|
|
|
|
function get_products($args = array()) {
|
|
return $this->get('/products/get', $args);
|
|
}
|
|
}
|
|
} |