diff --git a/controllers/ArticleController.php b/controllers/ArticleController.php index 11f63d7..6e8e56e 100755 --- a/controllers/ArticleController.php +++ b/controllers/ArticleController.php @@ -88,11 +88,39 @@ $model = new Article(); $model->generateLangs(); + if (class_exists('\artbox\catalog\models\Product')) { + $model->productIds = ArrayHelper::map( + $model->relatedProducts, + 'id', + 'lang.title' + ); + } + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) { $categories = Category::find() ->where([ 'id' => \Yii::$app->request->post('categoryIds') ]) ->all(); + + if (class_exists('\artbox\catalog\models\Product')) { + /** + * @var \yii\db\ActiveQuery $query + */ + $query = call_user_func( + [ + '\artbox\catalog\models\Product', + 'find', + ] + ); + /** + * @var \artbox\catalog\models\Product[] $products + */ + $products = $query->where([ 'id' => \Yii::$app->request->post('productIds') ]) + ->all(); + + $model->linkMany('relatedProducts', $products); + } + $model->linkMany('categories', $categories); -- libgit2 0.21.4