src/ImportCsvContentHandler.php
public function import($number, $row)
    {
        $result = new CsvImportRowResult();

        try
        {
            $isUpdate = false;
            $element = $this->_initElement($number, $row);

            foreach ($this->matching as $number => $fieldName)
            {
                //Выбрано соответствие
                if ($fieldName)
                {
                    $this->_initModelByField($element, $fieldName, $row[$number]);
                }
            }

            if (!$element->isNewRecord)
            {
                $isUpdate = true;
            }

            $element->validate();
            $element->relatedPropertiesModel->validate();

            if (!$element->errors && !$element->relatedPropertiesModel->errors)
            {
                $element->save();

                if (!$element->relatedPropertiesModel->save())
                {
                    throw new Exception('Не сохранены дополнительные данные');
                };

                $imageUrl = $this->getValue('image', $row);
                if ($imageUrl && !$element->image)
                {
                    try
                    {
                        $file = \Yii::$app->storage->upload($imageUrl, [
                            'name' => $element->name
                        ]);

                        $element->link('image', $file);

                    } catch (\Exception $e)
                    {
                        //\Yii::error('Not upload image to: ' . $cmsContentElement->id . " ({$realUrl})", 'import');
                    }
                }


                $result->message        =   $isUpdate === true ? "Элемент обновлен" : 'Элемент создан' ;

                $element->relatedPropertiesModel->initAllProperties();
                $rp = Json::encode($element->relatedPropertiesModel->toArray());
                $rp = '';
                $result->html           =   <<<HTML
Элемент: <a href="{$element->url}" data-pjax="0" target="_blank">{$element->id}</a> $rp
HTML;

            } else
            {
                $result->success        =   false;
                $result->message        =   'Ошибка';
                $result->html           =   Json::encode($element->errors) . "<br />" . Json::encode($element->relatedPropertiesModel->errors);
            }

            $result->data           =   $this->matching;

            unset($element->relatedPropertiesModel);
            unset($element);

        } catch (\Exception $e)
        {
            $result->success        =   false;
            $result->message        =   $e->getMessage();
        }






        return $result;
    }
public function import($number, $row)
    {
        $result = new CsvImportRowResult();

        try
        {
            $isUpdate = false;
            $element = $this->_initElement($number, $row);

            foreach ($this->matching as $number => $fieldName)
            {
                //Выбрано соответствие
                if ($fieldName)
                {
                    $this->_initModelByField($element, $fieldName, $row[$number]);
                }
            }

            if (!$element->isNewRecord)
            {
                $isUpdate = true;
            }

            $element->validate();
            $element->relatedPropertiesModel->validate();

            if (!$element->errors && !$element->relatedPropertiesModel->errors)
            {
                $element->save();

                if (!$element->relatedPropertiesModel->save())
                {
                    throw new Exception('Не сохранены дополнительные данные');
                };

                $imageUrl = $this->getValue('image', $row);
                if ($imageUrl && !$element->image)
                {
                    try
                    {
                        $file = \Yii::$app->storage->upload($imageUrl, [
                            'name' => $element->name
                        ]);

                        $element->link('image', $file);

                    } catch (\Exception $e)
                    {
                        //\Yii::error('Not upload image to: ' . $cmsContentElement->id . " ({$realUrl})", 'import');
                    }
                }


                $result->message        =   $isUpdate === true ? "Элемент обновлен" : 'Элемент создан' ;

                $element->relatedPropertiesModel->initAllProperties();
                $rp = Json::encode($element->relatedPropertiesModel->toArray());
                $rp = '';
                $result->html           =   <<<HTML
Элемент: <a href="{$element->url}" data-pjax="0" target="_blank">{$element->id}</a> $rp
HTML;

            } else
            {
                $result->success        =   false;
                $result->message        =   'Ошибка';
                $result->html           =   Json::encode($element->errors) . "<br />" . Json::encode($element->relatedPropertiesModel->errors);
            }

            $result->data           =   $this->matching;

            unset($element->relatedPropertiesModel);
            unset($element);

        } catch (\Exception $e)
        {
            $result->success        =   false;
            $result->message        =   $e->getMessage();
        }






        return $result;
    }
@param $number
@param $row

@return CsvImportRowResult