/** * Updates an existing Service model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $firstService = $this->findService($id); foreach (Yii::$app->params['availableLocales'] as $key => $value) { $currentService = Service::getLocaleInstance($key); $dataService = $currentService::find()->andWhere(['locale_group_id' => $firstService->locale_group_id, 'locale' => $key])->one(); $dataService->categoriesList = $this->getCategoriesListIds($dataService->id); if (!empty($dataService->domain)) { $dataService->domain = explode(',', $dataService->domain); } $services[$key] = $dataService; if (!$services[$key]) { $currentService->attributes = $firstService->attributes; $currentService->attachments = $firstService->attachments; $currentService->thumbnail = $firstService->thumbnail; //TODO: thumbnail copy fix $currentService->categoriesList = $firstService->categoriesList; //$currentService->video = $firstService->video; $currentService->locale_group_id = $firstService->locale_group_id; $currentService->locale = $key; $currentService->title = 'title ' . $key . ' ' . time(); $currentService->descripton = $firstService->description; $currentService->price = $firstService->price; $currentService->slug = ''; $services[$key] = $currentService; } } $service = new MultiModel(['models' => $services]); if ($service->load(Yii::$app->request->post()) && Service::multiSave($service)) { return $this->redirect(['index']); } else { switch ($firstService->on_scenario) { case 'extend': $viewName = 'extend'; break; default: $viewName = 'update'; } return $this->render($viewName, ['model' => $service, 'categories' => ServiceCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]); } }