File: //home/bk/__backup/exchanger/oasiscatalog_product.php
<?php
/**
 * Created by el.
 * @autor: el
 * @pakage: el
 * @version: 0.1 08.09.18 15:14
 * Date: 08.09.18
 */
 
$time_start = microtime(true);
require_once('config.php');
$mgc = new Mgc();
error_reporting(E_ALL);
ini_set("display_errors", 1);
define("SUPPLIER_ID",18);
$products = array();
$variants = array();
$importSupplier = new importSupplier(SUPPLIER_ID/*"Oasis"*/);
$cats = file_get_contents(SOURCE_DIR ."oasiscatalog".DIRECTORY_SEPARATOR ."oasiscatalog_categories.json");
$cats = json_decode($cats);
$level = 0;
$categories = array();
$CATS = array();
foreach ($cats as $k => $v) {
    $categories[(int)$v->id] = (string)$v->name;
    $level = max($level,$v->level);
    $cdata = array(
 			    'supplier_id'=>SUPPLIER_ID,
                'title'=>(string)$v->name,
                "parent_id"=>(string)$v->parent_id,
                "sup_id"=>(string)$v->id
                // id 	supplier_id 	title 	sup_id 	parent_id 	cat_id
             );
 $cat_id = $importSupplier->import_inner_category($cdata);
    $CATS[(int)$v->id] = (int)$cat_id;
}
unset($cats);
$p=1;
//die(SOURCE_DIR ."oasiscatalog".DIRECTORY_SEPARATOR . "oasiscatalog_products*.json");
foreach(glob(SOURCE_DIR ."oasiscatalog".DIRECTORY_SEPARATOR . "oasiscatalog_products*.json") as $file){
 //   echo $file;
    $json = json_decode(file_get_contents($file));
    if($json){
        foreach ($json as $group => $items) {
            foreach ($items as $item) {
         //   var_dump($item);
                $import = new stdClass;
           $import->category = "Неразобранное"; // по умолчанию
           $import->supplier_cat_ids = array(); // категории поставщика
                $import->category_ids = array(); // если уже разобранные в системе
foreach ($item->categories as $ca){
    $import->supplier_cat_ids[] = (int)$ca;
    if(isset($CATS[(int)$ca]) && intval($CATS[(int)$ca])){
        $import->category_ids[] =  intval($CATS[(int)$ca]);
      }
}
if(sizeof(  $import->category_ids)){
    $import->category_id = reset(  $import->category_ids);
}
     
     
     
                $import->vendor_ID = (string)$item->id;
         $import->sku = (string)$item->article;
if($import->sku[sizeof($import->sku)-1]=="p")continue;
if($import->sku[sizeof($import->sku)-1]=="P")continue;
     $fullname = '';
             //   $import->catalog = "Oasis";
                $fullname =  isset($item->full_name) && mb_strlen($item->full_name)<=127 ? (string)$item->full_name : (string)$item->name;
//                 }
//                 if(mb_strlen($fullname)>127){
                $fullname = mb_substr($fullname,0,127);
//                 }
                $item->full_name = (string)$item->full_name;
       $str = (string)$item->article." | ".(string)$item->full_name." | ".$fullname."\n";
        $str1 = (string)$item->article." | ".$fullname."\n";
             /*    if(mb_strlen($item->full_name)>127){  }*/
                 $import->sku = (string)$item->article;
                 $import->name = $fullname;
                 $import->variant = $fullname;
                $import->variant_vendor_ID = (string)$item->id;;
                 $import->description = ( isset($item->full_name) && mb_strlen($item->full_name)>127 ? (string)$item->full_name.".<br />" :"" ) .(string)$item->description;
                $import->brand = (string)$item->brand;
                $import->price = (string)str_replace(",", ".", $item->price);
                //	$import->weight   = floatval(str_replace(",",".",$item->tov_vesed));
                $import->material = implode(",", (array)$item->materials);
                //$import->size     = $item->tov_razm;
                //$import->color    = $item->tov_color;
                $import->id = null;
                $import->images = [];
                $import->weight = 0;
                $import->size = '';
                $import->color = '';
	//	$import->id = (string)$item->id;
if((string)$item->article=="3808033XS"){
    var_dump($item);
    exit;
};
                foreach ($item->attributes as $attr) {
                    if ((string)$attr->name == "Вес") $import->weight = floatval(str_replace(",", ".", $attr->value))/1000;
                    elseif ((string)$attr->name == "Размер товара") $import->size = (string)$attr->value;
                    elseif ((string)$attr->name == "Размер") $import->size = (string)$attr->value;
                    elseif ((string)$attr->name == "Цвет") $import->color = (string)$attr->value;
elseif ((string)$attr->name == "Цвет товара") $import->color = (string)$attr->value;
             }
                foreach ($item->images as $image) {
                    $import->images[] =  $image->big;
                }
                $data = $importSupplier->import_item($import);
          /*      if($import->sku=="1953194"){
                    var_dump($item);
                    exit;
                }*/
                echo "import OK ".$import->name."[".$import->sku."]".PHP_EOL;
/*exit;*/
            }
        }
    }
    echo "page: ". $p.PHP_EOL;
   ///**/ $xml = validationXML($file);
$p++;
}
$importSupplier->setInactive();
//var_dump($categories);
// Отладочная информация
print "<!--\r\n";
$time_end = microtime(true);
$exec_time = $time_end-$time_start;
if(function_exists('memory_get_peak_usage')) {
    print "memory peak usage: ".memory_get_peak_usage()." bytes\r\n";
}
print "page generation time: ".$exec_time." seconds\r\n";
print "-->";