public function actionImport($params = null)
 {
     try {
         $params = Json::decode($params);
     } catch (InvalidParamException $e) {
         echo 'Wrong input parameters.';
         return 1;
     }
     if (empty($params['files'])) {
         return 1;
     }
     $ts = microtime(true);
     $files = [];
     foreach ($params['files'] as $file) {
         $xmlReader = new XmlFileReader($file);
         if (XmlFileReader::FILETYPE_IMPORT === $xmlReader->fileType()) {
             array_unshift($files, $file);
         } else {
             $files[] = $file;
         }
         unset($xmlReader);
     }
     foreach ($files as $file) {
         $xmlReader = new XmlFileReader($file);
         $xmlReader->parse();
         unset($xmlReader);
         unlink($file);
     }
     echo sprintf('Task working time: %s', microtime(true) - $ts);
     return 0;
 }
 public function actionConfigure()
 {
     if (\Yii::$app->request->isPost) {
         foreach (\Yii::$app->request->post('guidSelect', []) as $key => $value) {
             $item = CommercemlGuid::findOne(['id' => $key, 'type' => 'PROPERTY']);
             if (!empty($item)) {
                 $item->model_id = $value;
                 $item->save();
             }
         }
         if (null !== ($file = UploadedFile::getInstanceByName('cmlFile'))) {
             $xmlReader = new XmlFileReader($file->tempName);
             foreach ($xmlReader->getProperties() as $item) {
                 $model = CommercemlGuid::findOne(['guid' => $item[XmlFileReader::ELEMENT_ID]]);
                 if (empty($model)) {
                     $guid = new CommercemlGuid();
                     $guid->type = 'PROPERTY';
                     $guid->guid = $item[XmlFileReader::ELEMENT_ID];
                     $guid->name = $item[XmlFileReader::ELEMENT_NAIMENOVANIE];
                     $guid->model_id = 0;
                     $guid->save();
                 }
             }
         }
         return $this->redirect('', 301);
     }
     $properties = array_reduce(CommercemlGuid::find()->where(['type' => 'PROPERTY'])->asArray()->all(), function ($result, $item) {
         $result[$item['guid']] = $item;
         return $result;
     }, []);
     $propertiesGroups = array_reduce(PropertyGroup::findAll(['object_id' => 3]), function ($result, $item) {
         return array_reduce($item->properties, function ($result, $item) {
             if ($item->is_eav || $item->has_static_values) {
                 $result[] = ['id' => $item->id, 'name' => $item->name];
             }
             return $result;
         }, $result);
     }, [['id' => 0, 'name' => '']]);
     return $this->render('configure', ['props' => $properties, 'propsGroups' => $propertiesGroups]);
 }