public function confirmUpdate() { $transaction = Yii::$app->db->beginTransaction(); $product = Products::findOne($this->id); $characteristic = Characteristics::findOne($product->characteristics_id); if (!($product && $characteristic)) { throw new NotFoundHttpException('Product Not Found'); } try { $product->clk_name = $this->name; $product->clk_description = $this->description; $product->price = $this->price; if (!$product->save()) { throw new \Exception('Product not update, transaction rollback'); } $characteristic->display_type = $this->displayType; $characteristic->mechanism_type = $this->mechanismType; $characteristic->starp_type = $this->starpType; $characteristic->sex = $this->sex; if (!$characteristic->save()) { throw new \Exception('Characteristic not update, transaction rollback'); } $transaction->commit(); Yii::$app->session->addFlash('success', 'Product successfully updated'); } catch (\Exception $e) { $transaction->rollBack(); throw $e; } }