public function actionEdit() { // [ 'Группа 1'=>['photo1', 'photo2', 'photo3'], 'Группа 2'=>['photo1', 'photo2', 'photo3'], 'Группа 3'=>['photo1', 'photo2', 'photo3'] ] if (Yii::$app->user->isGuest) { $this->redirect(Url::toRoute(['photobooks/index'])); return; } $this->layout = 'editor'; $ref = Yii::$app->request->get('ref'); $id = Yii::$app->request->get('id'); $selected_style_id = Yii::$app->request->get('style_id', 0); if (!empty($ref) && !empty($id)) { $user_id = AlphaId::id($ref, true); $pb_id = AlphaId::id($id, true); if ($user_id != Yii::$app->user->identity->getId()) { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Страница не найдена')); $this->redirect(Url::toRoute(['photobooks/index'])); return; } $model = new PhotobookForm(); if (!$model->loadById($pb_id)) { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Фотокнига не найдена')); $this->redirect(Url::toRoute(['photobooks/index'])); return; } if (empty($model->data['pages'])) { $this->redirect(Url::toRoute(['photobooks/upload-photos', 'ref' => $ref, 'id' => $id])); return; } $style_id = $model->style_id; $style = new StyleForm(); if (!$style->loadById($style_id)) { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Стиль для данной фотокниги не найден.')); $this->redirect(Url::toRoute(['photobooks/index'])); return; } $selected_cover = new CoverForm(); if (!$selected_cover->loadById($model->cover_id)) { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Обложка для данной фотокниги не найден.')); $this->redirect(Url::toRoute(['photobooks/index'])); return; } $covers = Cover::find()->where(['status' => 1])->all(); $new_covers = []; foreach ($covers as $key => $cover) { $new_covers[$cover->material_type][] = $cover; } $pages = $model->data['pages']; $base_price = (count($pages) - 2) * $style->price_spread; $cover_price_sign = $selected_cover->price_sign; $selected_cover->price; $total_price = $base_price; if ($cover_price_sign == "=") { $total_price = $selected_cover->price; } else { if ($cover_price_sign == "+") { $total_price += $selected_cover->price; } else { if ($cover_price_sign == "-") { $total_price -= $selected_cover->price; } } } $user = User::findOne(['id' => $user_id]); $total_price = CurrencyConvertor::conv($total_price, $user->default_currency); $curse = CurrencyConvertor::getCurse($user->default_currency); $product_info = $model->getProductInfo(); $total_price = $product_info['response']['price'] * $curse; $settingForm = new SettingForm(); $photobook_thumb_as_object = $settingForm->getValue('photobook_thumb_as_object', false); return $this->render('edit', ['model' => $model, 'ref' => $ref, 'id' => $id, 'pb_id' => $pb_id, 'user_id' => $user_id, 'pages' => $pages, 'style' => $style, 'selected_cover' => $selected_cover, 'covers' => $new_covers, 'total_price' => $total_price, 'default_currency' => $user->default_currency, 'cover_price_sign' => $cover_price_sign, 'cover_price' => $selected_cover->price, 'price_spread' => $style->price_spread, 'curse' => $curse, 'photobook_thumb_as_object' => $photobook_thumb_as_object]); } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Страница не найдена')); $this->redirect(Url::toRoute(['photobooks/index'])); } }