/**
* Создает новую модель товара.
* Если создание прошло успешно - перенаправляет на просмотр.
*/
public function actionCreate()
{
$model = new Product();
if (Yii::app()->getRequest()->getIsPostRequest() && Yii::app()->getRequest()->getPost('Product')) {
$attributes = Yii::app()->getRequest()->getPost('Product');
$typeAttributes = Yii::app()->getRequest()->getPost('Attribute', []);
$variants = Yii::app()->getRequest()->getPost('ProductVariant', []);
$categories = Yii::app()->getRequest()->getPost('categories', []);
if ($model->saveData($attributes, $typeAttributes, $variants, $categories)) {
$this->updateProductImages($model);
Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('StoreModule.store', 'Record was added!'));
$this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create']));
} else {
Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('StoreModule.store', 'Failed to save product!'));
}
}
$this->render('create', ['model' => $model]);
}