Commit c8963ce0e10f55579eb7271f56f74b39106d1a15

Authored by Yarik
1 parent d7bd5725

Social auth + view history

Showing 1 changed file with 28 additions and 0 deletions   Show diff stats
controllers/ArticleController.php
... ... @@ -88,11 +88,39 @@
88 88 $model = new Article();
89 89 $model->generateLangs();
90 90  
  91 + if (class_exists('\artbox\catalog\models\Product')) {
  92 + $model->productIds = ArrayHelper::map(
  93 + $model->relatedProducts,
  94 + 'id',
  95 + 'lang.title'
  96 + );
  97 + }
  98 +
91 99 if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
92 100  
93 101 $categories = Category::find()
94 102 ->where([ 'id' => \Yii::$app->request->post('categoryIds') ])
95 103 ->all();
  104 +
  105 + if (class_exists('\artbox\catalog\models\Product')) {
  106 + /**
  107 + * @var \yii\db\ActiveQuery $query
  108 + */
  109 + $query = call_user_func(
  110 + [
  111 + '\artbox\catalog\models\Product',
  112 + 'find',
  113 + ]
  114 + );
  115 + /**
  116 + * @var \artbox\catalog\models\Product[] $products
  117 + */
  118 + $products = $query->where([ 'id' => \Yii::$app->request->post('productIds') ])
  119 + ->all();
  120 +
  121 + $model->linkMany('relatedProducts', $products);
  122 + }
  123 +
96 124  
97 125 $model->linkMany('categories', $categories);
98 126  
... ...