public function afterSave($insert, $changedAttributes) { if ($this->isNewRecord === false) { OrderProducts::deleteAll(["order_id" => $this->id]); } foreach ($this->rendeles["termek"] as $key => $row) { $toppings = []; if (isset($this->rendeles["feltet"][$key]) && $this->rendeles["feltet"][$key]) { $toppings = $this->rendeles["feltet"][$key]; } $toppings = Json::encode($toppings); $model = new OrderProducts(); $model->order_id = $this->id; $model->product_id = $row; $model->toppings = $toppings; $model->count = $this->rendeles["count"][$key]; $model->save(); } parent::afterSave($insert, $changedAttributes); }
/** * Deletes an existing Orders model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { return $this->redirect("/admin/orders/index"); exit; OrderProducts::deleteAll(["order_id" => $id]); $this->findModel($id)->delete(); return $this->redirect(['index']); }