/** * Deletes an existing Meal model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param string $id * @return mixed */ public function actionDelete($id) { if ($this->findModel($id)->delete()) { $productImages = MealImage::findOne(['meal_id' => $id]); if (!empty($productImages)) { $image = Yii::$app->params['uploadPath'] . $productImages->image_new_url; if (unlink($image)) { $productImages->delete(); } } $mealItemManage = MealItemsManage::findOne(['meal_id' => $id]); if (!empty($mealItemManage)) { if (MealItemsManage::deleteAll(['meal_id' => $id])) { } } } return $this->redirect(['index']); }
public function actionCheckoutreponse() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $request = Yii::$app->request; $checkOut = []; $id = $request->post('id'); $qty = $request->post('qty'); // $id = 3; // $qty= 3; $getMealItems = MealItemsManage::find()->select(['item_id'])->where(['meal_id' => $id])->asArray()->all(); $query = new Query(); $query->select(['meal.*', 'meal_image.image_new_url', 'meal_image.image_org_url'])->from('meal')->join('LEFT JOIN', 'meal_image', 'meal_image.meal_id = meal.id')->where(['meal.id' => $id]); $command = $query->createCommand(); $checkOut[$id] = $command->queryAll()[0]; $checkOut[$id]['qty'] = $qty; if (!empty($getMealItems)) { $count = 0; foreach ($getMealItems as $key => $value) { $query2 = new Query(); $query2->select(['meal_item.*', 'meal_item_image.image_new_url', 'meal_item_image.image_org_url'])->from('meal_item')->join('LEFT JOIN', 'meal_item_image', 'meal_item_image.itemID = meal_item.id')->where(['meal_item.id' => $value['item_id']]); $command = $query2->createCommand(); $dataMealItem[] = $command->queryAll()[0]; } $checkOut[$id]['items'] = $dataMealItem; } $totalPrice = 0; foreach ($checkOut[$id]['items'] as $key => $value) { $totalPrice += $value['price']; } $totalPrice = $totalPrice * $qty; $checkOut[$id]['totalPrice'] = $totalPrice; // echo '<pre>'; // print_r($totalPrice);die; Yii::$app->session->set('checkOut', $checkOut); return 'success'; // if(!empty($itemInArray)){ // $data[0]['item'] = implode(',', $itemInArray); // } // else{ // $data[0]['item'] = 'not selected item'; // } }