🔧 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>
91 lines
2.5 KiB
PHP
91 lines
2.5 KiB
PHP
<?php
|
|
|
|
require_once dirname(__FILE__) . '/MiraviaLink.php';
|
|
|
|
class MiraviaCategory extends MiraviaLink
|
|
{
|
|
|
|
public function getCategories($treeFormat = false)
|
|
{
|
|
$url = $this->api_url . '/category/tree';
|
|
$ret = $this->CallAPI($url);
|
|
if($ret === false){
|
|
return false;
|
|
}
|
|
$resp = json_decode($ret, true);
|
|
if(!isset($resp['success']) || !$resp['success']){
|
|
$this->last_error = $resp['error'];
|
|
return false;
|
|
}
|
|
if(isset($resp['data'])){
|
|
if($treeFormat) {
|
|
return $resp['data'];
|
|
}else{
|
|
return $this->treeToList($resp['data']);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getBrands()
|
|
{
|
|
$url = $this->api_url . '/category/brands';
|
|
$ret = $this->CallAPI($url);
|
|
if($ret === false){
|
|
return false;
|
|
}
|
|
$resp = json_decode($ret, true);
|
|
if(!isset($resp['success']) || !$resp['success']){
|
|
$this->last_error = $resp['error'];
|
|
return false;
|
|
}
|
|
if(isset($resp['data'])){
|
|
return $resp['data'];
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getAttributes($id)
|
|
{
|
|
$url = $this->api_url . '/category/' . $id . '/attributes';
|
|
$ret = $this->CallAPI($url);
|
|
if($ret === false){
|
|
return false;
|
|
}
|
|
$resp = json_decode($ret, true);
|
|
if(!isset($resp['success']) || !$resp['success']){
|
|
$this->last_error = isset($resp['error']) ? $resp['error'] : $ret;
|
|
return false;
|
|
}
|
|
if(isset($resp['data'])){
|
|
return $resp['data'];
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private function treeToList($tree = [], $prefix = '')
|
|
{
|
|
$ret = [];
|
|
$separator = $prefix=='' ? '' : ' / ';
|
|
foreach ($tree as $item) {
|
|
$name = $item['name'];
|
|
if(isset($item['children'])) {
|
|
$children = $this->treeToList($item['children'], $prefix . $separator . $name);
|
|
foreach($children as $key => $child){
|
|
$ret[] = [
|
|
'id' => $child['id'],
|
|
'name' => $child['name']
|
|
];
|
|
}
|
|
}else{
|
|
$ret[] = [
|
|
'id' => $item['category_id'],
|
|
'name' => $prefix . $separator . $name
|
|
];
|
|
}
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
}
|