/var/www/vhosts/nabawater/backend/controllers
NameSizeModeActions
ActivityLogController.php16500644editdlrm
AddressTypeController.php64660644editdlrm
AdminOrderReportController.php35920644editdlrm
AdminUserController.php125230644editdlrm
AdsController.php97430644editdlrm
AreaController.php70190644editdlrm
BannerController.php71000644editdlrm
BranchController.php339890644editdlrm
BranchReviewController.php22090644editdlrm
CashBackPromotionsController.php120510644editdlrm
CategoryController.php87950644editdlrm
CityController.php55180644editdlrm
CmsController.php60260644editdlrm
ConfigurationController.php105640644editdlrm
CountryController.php52340644editdlrm
CouponController.php152450644editdlrm
CuisineController.php82070644editdlrm
DashboardController.php58050644editdlrm
DeliveryAreaController.php75060644editdlrm
DeliveryboyController.php76620644editdlrm
DeliveryChargeSettingsController.php45560644editdlrm
DriverOrderController.php35850644editdlrm
EnquiryController.php25410644editdlrm
FaqController.php65710644editdlrm
IngredientController.php69540644editdlrm
ItemController.php341500644editdlrm
ItemImportController.php38480644editdlrm
ItemIngredientGroupController.php111050644editdlrm
ItemMappingController.php121600644editdlrm
ItemTypeController.php74450644editdlrm
LanguageController.php38470644editdlrm
LoginController.php16840644editdlrm
LoyalityPointController.php66550644editdlrm
MallProductController.php63980644editdlrm
MetaTagController.php50390644editdlrm
MobileTranslationController.php44510644editdlrm
NewsLetterController.php52070664editdlrm
NewsletterController.php52070644editdlrm
NewsletterSubscriberController.php17470644editdlrm
NotificationController.php83820644editdlrm
OrderController.php937130644editdlrm
OrderMallProductController.php76610644editdlrm
OrderParcelController.php27520644editdlrm
OrderReportController.php39040644editdlrm
ParcelItemTypeController.php43570644editdlrm
PromotionController.php67100644editdlrm
PushNotificationController.php29900644editdlrm
RatingController.php6230644editdlrm
RefundRequestController.php29640644editdlrm
reject-index.php429310644editdlrm
RejectedOrderReportController.php5660644editdlrm
ReportController.php422320644editdlrm
RoleController.php52300644editdlrm
SiteController.php3570644editdlrm
StockController.php20670644editdlrm
TaxController.php45680644editdlrm
TodaySpecialController.php74730644editdlrm
TopOrderItemReportController.php38660644editdlrm
TopupController.php46190644editdlrm
UnitController.php71150644editdlrm
UserController.php135660644editdlrm
UserLevelController.php37870644editdlrm
VendorBankController.php28800644editdlrm
VendorController.php244910644editdlrm
VendorOrderReportController.php51460644editdlrm
VendorPaymentController.php60940644editdlrm
VendorTypeController.php84280644editdlrm
WalletController.php17910644editdlrm
WalletTranscationController.php22820644editdlrm
WebpushNotificationController.php25630644editdlrm
Edit: /var/www/vhosts/nabawater/backend/controllers/ItemController.php (34150B)
render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $searchModel->search(Yii::$app->request->queryParams), 'categoryName' => $categoryName, 'vendorName' => $vendorName, 'cuisineName' => $cuisineName ] ); } /** * * @return string * * @Title("Stock") */ public function actionStock() { $searchModel = new ItemSearch(); $categoryName = Item::getCategoryName(); $vendorName = Item::getVendorName(); $cuisineName = Cuisine::getCuisineData(); return $this->render('_stock', [ 'searchModel' => $searchModel, 'dataProvider' => $searchModel->search(Yii::$app->request->queryParams), 'categoryName' => $categoryName, 'vendorName' => $vendorName, 'cuisineName' => $cuisineName ] ); } /** * * @return string * * @Title("Create") */ public function actionCreate() { $model = new Item(); $modelLang = new ItemLang(); $modelLang->setScenario($modelLang::SCENARIO_CREATE); $modelItemImage = new ItemImage(); $modelItemUploadForm = new ItemUploadForm(); $modelItemUploadForm->setScenario($modelItemUploadForm::SCENARIO_CREATE); $modelVendor = new Vendor(); $modelBranch = new Branch(); $modelItemTypeDetail = new ItemTypeDetails(); $modelItemType = new ItemType(); $modelCategory = new Category(); $cuisineDetails = new Cuisine(); $appLanguages = Language::getAppLanguages(); if(!isset($_POST['Item']['branch_id'])) { // print_r($_POST); die; goto skip; } foreach ($_POST['Item']['branch_id'] as $bkey => $branch) { $model = new Item(); $modelLang = new ItemLang(); $modelLang->setScenario($modelLang::SCENARIO_CREATE); $modelItemImage = new ItemImage(); $modelItemUploadForm = new ItemUploadForm(); $modelItemUploadForm->setScenario($modelItemUploadForm::SCENARIO_CREATE); $modelVendor = new Vendor(); $modelBranch = new Branch(); $modelItemTypeDetail = new ItemTypeDetails(); $modelItemType = new ItemType(); $modelCategory = new Category(); $cuisineDetails = new Cuisine(); $appLanguages = Language::getAppLanguages(); $post = Yii::$app->getRequest()->post(); // if($_POST != []) { // print_r($post); die; // } if($model->load($post)){ if(AdminUser::isVendor() || AdminUser::isBranch()) { $model->item_approved_status = $model::NOT_APPROVED; } $model->branch_id = $branch; $modelLang->branch_id = $branch; if ($modelLang->load($post) && $model->validate() && $modelLang->validate()) { $modelItemTypeDetail->load($post); $modelItemImage->load($post); if(AdminUser::isVendor()){ $model->vendor_id = yii::$app->user->getId(); } $model->save(); foreach($appLanguages as $langCode => $langName) { $modelTranslation = new ItemLang(); $modelTranslation->loadTranslationAttribute($post, $langCode); $modelTranslation->item_id = $model->getPrimaryKey(); $modelTranslation->save(); } $imgpathIds = []; if ($modelItemImage->item_image_path) { foreach ($modelItemImage->item_image_path as $key => $item_image_path) { $modelImage = new ItemImage; $modelImage->item_id = $model->getPrimaryKey(); $modelImage->item_image_path = $modelItemImage->item_image_path[$key]; $modelImage->image_large_path = $modelItemImage->image_large_path[$key]; $modelImage->image_thumb_path = $modelItemImage->image_thumb_path[$key]; // $modelImage->moveToOrginalPath('item_image_path'); // $modelImage->moveToOrginalPath('image_large_path'); // $modelImage->moveToOrginalPath('image_thumb_path'); if (!$modelImage->save()) { $response['error'] = $this->prepareErrors($modelImage); $response['type'] = 'modelImageSA'; //goto skip; } $imgpathIds[] = $modelImage->getPrimaryKey(); } } ItemImage::deleteAll([ 'and', ['in', 'item_id', [$model->getPrimaryKey()]], ['not in', 'item_image_id', $imgpathIds] ]); if(count($_POST['Item']['branch_id']) == $bkey +1) { Com::successFlash(Yii::t('backend','Created Successfully')); $adminUserData = Yii::$app->getUser()->getIdentity(); $adminUserName = $adminUserData->attributes['user_name']; $branchName = ItemLang::find()->where(['item_id' => $model->item_id,'language_code' => Yii::$app->language])->one(); ActivityLog::log($adminUserName.' '. 'create item '.' '. $branchName->item_name); return $this->redirect(['index']); } } } } skip: return $this->render('create', [ 'model' => $model, 'modelLang' => $modelLang, 'modelItemImage' => $modelItemImage, 'modelItemUploadForm' => $modelItemUploadForm, 'modelVendor' => $modelVendor, 'modelBranch' => $modelBranch, 'modelCategory' => $modelCategory, 'modelItemTypeDetail' => $modelItemTypeDetail, 'modelItemType' => $modelItemType, 'cuisineDetails' => $cuisineDetails, 'appLanguages' => $appLanguages ]); } /** * * @param type $id * @return string * * @Title("Update") */ public function actionUpdate($id) { $model = $this->findModel($id); $modelItemImage = new ItemImage(); $modelItemUploadForm = new ItemUploadForm(); $modelLang = new ItemLang(); $modelItemTypeDetailData = ItemTypeDetails::find() ->select('GROUP_CONCAT(item_type_id) AS item_type_id') ->where(['item_id' => $model->getPrimaryKey()]) ->asArray() ->one(); $modelItemTypeDetail = new ItemTypeDetails(); $modelLang->setScenario($modelLang::SCENARIO_UPDATE); $post = Yii::$app->getRequest()->post(); $modelVendor = new Vendor(); $modelBranch = new Branch(); $modelItemType = new ItemType(); $modelCategory = new Category(); $cuisineDetails = new Cuisine(); $modelImg = ItemImage::findAll(['item_id' => $model->getPrimaryKey()]); $appLanguages = Language::getAppLanguages(); ItemLang::updateTranslationAttribute($modelLang, $model->getPrimaryKey()); $appLanguages = Language::getAppLanguages(); // ItemImage::updateTranslationAttribute($modelItemImage, $model->getPrimaryKey()); if($model->load($post)) { $modelLang->branch_id = $post['Item']['branch_id']; if ($model->validate() && $modelLang->load($post) && $modelLang->validate()) { $modelItemTypeDetail->load($post); $modelItemImage->load($post); // print_r($modelItemImage); die; $model->save(); foreach ($appLanguages as $langCode => $langName) { $modelTranslation = ItemLang::findOne([ 'item_id' => $model->getPrimaryKey(), 'language_code' => $langCode ]); if ($modelTranslation === null) { $modelTranslation = new ItemLang(); $modelTranslation->item_id = $model->getPrimaryKey(); } $modelTranslation->loadTranslationAttribute($post, $langCode); $modelTranslation->save(); } $imgpathIds = []; if ($modelItemImage->item_image_id) { foreach ($modelItemImage->item_image_id as $key => $item_image_id) { $modelImage = ItemImage::findOne($item_image_id); if($modelImage == null) { $modelImage = new ItemImage(); } $modelImage->item_id = $model->getPrimaryKey(); $modelImage->item_image_path = $modelItemImage->item_image_path[$key]; $modelImage->image_large_path = $modelItemImage->image_large_path[$key]; $modelImage->image_thumb_path = $modelItemImage->image_thumb_path[$key]; // $modelImage->moveToOrginalPath('item_image_path'); // $modelImage->moveToOrginalPath('image_large_path'); // $modelImage->moveToOrginalPath('image_thumb_path'); if (!$modelImage->save()) { $response['error'] = $this->prepareErrors($modelImage); $response['type'] = 'modelImageSA'; //goto skip; } $imgpathIds[] = $modelImage->getPrimaryKey(); } } ItemImage::deleteAll([ 'and', ['in', 'item_id', [$model->getPrimaryKey()]], ['not in', 'item_image_id', $imgpathIds] ]); // $fileHelper = FileUploadHelper::getInstance()->convertFileArray(); // foreach ($appLanguages as $langCode => $langName) { // $imageModel = ItemImage::findOne([ // 'item_id' => $model->getPrimaryKey(), // 'language_code' => $langCode // ]); // if ($imageModel === null) { // $imageModel = new ItemImage(); // $imageModel->item_id = $model->getPrimaryKey(); // } // $uploadedFile = $fileHelper->getFileInstance($modelItemUploadForm, 'item_image_path', $langCode); // if (!empty($uploadedFile)) { // $uploadHelper = UploadHelper::getInstance(); // $uploadHelper->setPath($uploadHelper::ITEM); // $uploadHelper->setUploadedFile($uploadedFile); // $path = $uploadHelper->getPath(true); // $uploadedFile->saveAs($path); // $realpath = $uploadHelper->getRealPath($path); // $imageModel->loadTranslationAttribute($post, $langCode); // $imageModel->item_id = $model->getPrimaryKey(); // $imageModel->item_image_path = '/'. $realpath ; // $imageModel->save(); // } else { // $imageModel->loadTranslationAttribute($post, $langCode); // $imageModel->item_id = $model->getPrimaryKey(); // $imageModel->save(); // } // } // ItemTypeDetails::deleteAll(['item_id' => $model->getPrimaryKey()]); // foreach ((array)$modelItemTypeDetail->item_type_id as $itemType => $itemTypeId) { // $modelItemTypeDetailModel = new ItemTypeDetails(); // $modelItemTypeDetailModel->item_id = $model->getPrimaryKey(); // $modelItemTypeDetailModel->item_type_id = $itemTypeId; // if (!($modelItemTypeDetailModel->save())) { // $data = $modelItemTypeDetailModel->attributes; // $modelItemTypeDetailModel->setAttributes($data); // return $this->render('update', [ // 'model' => $model, // 'modelLang' => $modelLang, // 'imageModel' => $imageModel, // 'modelBranch' => $modelBranch, // 'modelCategory' => $modelCategory, // 'modelVendor'=> $modelVendor, // 'modelItemTypeDetail' => $modelItemTypeDetail, // 'modelItemTypeDetailData' => $modelItemTypeDetailData, // 'modelItemType' => $modelItemType, // 'cuisineDetails' => $cuisineDetails // ]); // } // } $modelItemTypeDetail->item_id = $model->getPrimaryKey(); $modelItemTypeDetail->save(); Com::successFlash(Yii::t('backend','Updated Successfully')); $adminUserData = Yii::$app->getUser()->getIdentity(); $adminUserName = $adminUserData->attributes['user_name']; $branchName = ItemLang::find()->where(['item_id' => $model->item_id,'language_code' => Yii::$app->language])->one(); ActivityLog::log($adminUserName.' '. 'updated item '.' '. $branchName->item_name); return $this->redirect(['index']); } } return $this->render('update', [ 'model' => $model, 'modelLang' => $modelLang, 'modelItemImage' => $modelItemImage, 'modelItemUploadForm' => $modelItemUploadForm, 'modelBranch' => $modelBranch, 'modelCategory' => $modelCategory, 'modelVendor'=> $modelVendor, 'modelItemTypeDetail' => $modelItemTypeDetail, 'modelItemTypeDetailData' => $modelItemTypeDetailData, 'modelItemType' => $modelItemType, 'cuisineDetails' => $cuisineDetails, 'appLanguages' => $appLanguages, 'modelImg' => $modelImg, ]); } /** * * @param type $id * @return string * * @Title("Delete") */ public function actionDelete($id) { $model = $this->findModel($id); if ($model === null) { Com::failureFlash('Unable to find the Item'); return $this->redirect(['index']); } $model->item_status = Item::DELETE; $model->save(); $adminUserData = Yii::$app->getUser()->getIdentity(); $adminUserName = $adminUserData->attributes['user_name']; $branchName = ItemLang::find()->where(['item_id' => $model->item_id,'language_code' => Yii::$app->language])->one(); ActivityLog::log($adminUserName.' '. 'deleted item '.' '. $branchName->item_name); Com::successFlash(Yii::t('backend','Deleted Successfully')); return $this->redirect(['index']); } /** * * @param type $id * @return $model * @throws NotFoundHttpException */ protected function findModel($id) { if (($model = Item::findOne(['item_key' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /** * * @return Json * * @Title("Item Status") */ public function actionChangeStatus() { $params = ['key', 'status']; $post = Yii::$app->getRequest()->post(); $result = ['status' => STATUS_FAIL, 'msg' => '']; foreach ($params as $param) { if (!array_key_exists($param, $post)) { $result['msg'] = 'Required param missing'; goto skip; } } $model = Item::findOne(['item_key' => $post['key']]); if ($model === null) { $result['msg'] = 'Unable to find the Item'; goto skip; } $model->item_status = $post['status']; $model->save(false); $result['msg'] = Yii::t('backend','Item deactivated successfully'); if ((int)$model->item_status === $model::ACTIVE) { $result['msg'] = Yii::t('backend','Item activated successfully'); $adminUserData = Yii::$app->getUser()->getIdentity(); $adminUserName = $adminUserData->attributes['user_name']; $branchName = ItemLang::find()->where(['item_id' => $model->item_id,'language_code' => Yii::$app->language])->one(); ActivityLog::log($adminUserName.' '. 'activated item '.' '. $branchName->item_name); } else { $adminUserData = Yii::$app->getUser()->getIdentity(); $adminUserName = $adminUserData->attributes['user_name']; $branchName = ItemLang::find()->where(['item_id' => $model->item_id,'language_code' => Yii::$app->language])->one(); ActivityLog::log($adminUserName.' '. 'deactivated item '.' '. $branchName->item_name); } $result['status'] = STATUS_SUCCESS; skip: return $this->asJson($result); } /** * * @param type $id * @return $model * @throws NotFoundHttpException */ protected function findImageModel($id) { $model = ItemImage::find() ->alias('IM') ->select('IM.*') ->leftJoin(['I' => Item::tableName()], 'IM.item_id = I.item_id') ->where(['I.item_key' => $id]) ->one(); if ($model === null) { throw new NotFoundHttpException('The requested page does not exist.'); } return $model; } /** * * @param type $id * @return boolean * @return string */ public function actionGetIngredients($id) { $model = ItemMapping::find() ->alias('IM') ->select([ 'IMG.item_ingredient_group_id', 'IIGL.group_name', 'IIG.ingredient_type', 'IIG.minimum', 'IIG.maximum' ]) ->leftJoin(['IMG' => ItemMappingGroup::tableName()], 'IMG.item_mapping_id = IM.item_mapping_id ') ->leftJoin(['IIGL' => ItemIngredientGroupLang::tableName()], 'IIGL.item_ingredient_group_id = IMG.item_ingredient_group_id') ->leftJoin(['IIG' => ItemIngredientGroup::tableName()],'IIG.item_ingredient_group_id = IMG.item_ingredient_group_id') ->where(['IM.item_id' => $id]) ->asArray() ->all(); if ($model === null || empty($model)) { return false; } else { foreach ($model as $key => $value) { $model[$key]['ingredients']= ''; $model[$key]['ingredients'] = ItemIngredientMapping::find() ->alias('IIM') ->select([ 'IIM.*', 'IL.ingredient_name' ]) ->leftJoin(['IL' => IngredientLang::tableName()], 'IL.ingredient_id = IIM.ingredient_id') ->where(['IIM.item_ingredient_group_id' => $value['item_ingredient_group_id']]) ->asArray() ->all(); } return $this->renderPartial('item-ingredient', ['data' => $model, 'item_id' => $id]); } } /** * @return string * @throws \yii\base\InvalidParamException */ public function actionGetBranchItems() { $post = Yii::$app->getRequest()->post(); $result = ['status' => STATUS_FAIL, 'msg' => '', 'model' => '']; if (!array_key_exists('branch_id', $post)) { $result['msg'] = 'Required Param Missing'; goto skip; } $model = Item::find() ->alias('I') ->select([ 'I.*', 'IL.item_name', 'IMG.item_ingredient_group_id' ]) ->leftJoin(['IL' => ItemLang::tableName()], 'IL.item_id = I.item_id') ->leftJoin(['IM' => ItemMapping::tableName()], 'IM.item_id = I.item_id') ->leftJoin(['IMG' => ItemMappingGroup::tableName()], 'IMG.item_mapping_id = IM.item_mapping_id') ->where(['I.branch_id' => $post]) ->andWhere(['I.item_status' => Item::ACTIVE]) ->asArray() ->all(); if ($model === null || empty($model)) { $result['msg'] = 'Unable to find the items for this vendor'; goto skip; } foreach ($model as $key => $value) { $row = []; $row[] = Html::tag('td', $value['item_name']); if ( $value['item_ingredient_group_id'] !== null ) { $row[] = Html::tag('td', Html::a('', 'javascript:;' , ['class' => 'plus_button', 'id' => $value['item_id'], 'onclick' => 'addItem('.$value['item_id'].', '.$post['branch_id'].')'])); } else { $row[] = Html::tag('td', Html::a('', 'javascript:;' , ['class' => 'plus_button', 'id' => $value['item_id']])); } $tbody[] = Html::tag('tr', implode('', $row)); } $tbody = Html::tag('tbody', implode('', $tbody)); $result['table_body'] = $tbody; $result['status'] = STATUS_SUCCESS; $result['msg'] = 'Data Fetched Successfully'; skip: return $this->asJson($result); } /** * @return string */ public function actionGetItem() { $post = Yii::$app->request->post(); $vendor_id = $post['id']; $items = Item::find() ->alias('I') ->select([ 'IL.item_name', 'I.item_id' ]) ->leftJoin(['IL' => ItemLang::tableName()], 'IL.item_id = I.item_id') ->where(['I.branch_id' => $vendor_id]) ->andWhere(['<>', 'I.item_status', Item::DELETE]) ->all(); $option = Html::tag('option', '', ['value' => '']); foreach ($items as $item) { $option .= Html::tag('option', $item->item_name, ['value' => $item->item_id]); } echo $option; } /** * * @param type $id * @return string * * @Title("View") */ public function actionView($id) { $model = $this->findModel($id); $query = Item::find() ->alias('I') ->select([ 'IL.item_name', 'CL.category_name', 'VL.vendor_name', 'IL.item_description', 'I.item_price', 'I.item_status', 'C.cuisine_name', 'I.item_approved_status' ]) ->leftJoin(['IL' => ItemLang::tableName()], 'IL.item_id = I.item_id') ->leftJoin(['CL' => CategoryLang::tableName()], 'I.category_id = CL.category_id') ->leftJoin(['VL' => VendorLang::tableName()], 'I.vendor_id = VL.vendor_id') ->leftJoin(['C' => CuisineLang::tableName()], 'C.cuisine_id = I.cuisine_id') ->where(['I.item_id' => $model->item_id]) ->andWhere(['IL.language_code' => Yii::$app->language]) ->one(); return $this->render('view', ['model' => $query]); } /** * * @return Json */ public function actionChangeItemStatus() { $data = Yii::$app->request->post(); //print_r($data); die; $result = ['status' => STATUS_FAIL, 'msg' => '']; foreach($data['keylist'] as $key) { $model = $this->findModel($key); if($data['status'] == 'Active') { $model->item_status = Item::ACTIVE; $result['msg'] = Yii::t('backend', 'Items activated successfully'); } else if($data['status'] == 'Deactive') { $model->item_status = Item::INACTIVE; $result['msg'] = Yii::t('backend', 'Items Deactivated successfully'); } else { $model->item_status = 3; //Item::DELETE; $result['msg'] = Yii::t('backend', 'Items deleted successfully'); } $model->save(false); } $result['status'] = STATUS_SUCCESS; skip: return $this->asJson($result); } public function actionImportItem() { $modelItemFileUploadForm = new ItemFileUploadForm(); $post = Yii::$app->getRequest()->post(); if($modelItemFileUploadForm->load($post)) { $uploadedFile = UploadedFile::getInstance($modelItemFileUploadForm, 'item_file'); if (!$uploadedFile == null) { $uploadHelper = UploadHelper::getInstance(); $uploadHelper->setPath($uploadHelper::ITEM_IMPORT_FILE); //$uploadHelper->setUploadedFile($uploadedFile); $name = sprintf('%s%s', time(), Com::generateRandomString(5, true)); $path = sprintf('%s%s%s.%s', $uploadHelper->getPath(), DIRECTORY_SEPARATOR, $name, isset($upload->extension)); $uploadedFile->saveAs($path); $realpath = $uploadHelper->getRealPath($path); $filePath = UploadHelper::getInstance()->getAbsPath($realpath); $chunkSize = 10000; $chunkHelper = ChunkHelper::getInstance(); $reader = IOFactory::createReaderForFile($filePath); $reader->setReadFilter($chunkHelper); $i = 2; $chunkHelper->setRows(1, $chunkSize); $spredSheet = $reader->load($filePath); $rowCount = $spredSheet->setActiveSheetIndex(0)->getHighestRow(); $worksheet = $spredSheet->getActiveSheet(); foreach ($worksheet->getRowIterator() as $key => $row) { $activeSheet = $spredSheet->getActiveSheet(); $iten_name = $activeSheet->getCell('A'.$i)->getValue(); $item_description = $activeSheet->getCell('B'.$i)->getValue(); $vendor_id = $activeSheet->getCell('C'.$i)->getValue(); $branch_id = $activeSheet->getCell('D'.$i)->getValue(); $category_id = $activeSheet->getCell('E'.$i)->getValue(); $item_price = $activeSheet->getCell('F'.$i)->getValue(); $sort_no = $activeSheet->getCell('G'.$i)->getValue(); $package_fee = $activeSheet->getCell('H'.$i)->getValue(); $is_recomm = 0; $item_status = $activeSheet->getCell('J'.$i)->getValue(); $approval_status = $activeSheet->getCell('K'.$i)->getValue(); $cuisine_id = 1; $langauge = Language::getAll(); $itemModel = new Item(); $itemModel->category_id = $category_id; $itemModel->vendor_id = $vendor_id; $itemModel->branch_id = $branch_id; $itemModel->cuisine_id = $cuisine_id; $itemModel->sort_no = $key; $itemModel->item_status = $item_status; $itemModel->item_price = $item_price; $itemModel->package_price = $package_fee; $itemModel->is_recommended = 0; $itemModel->item_approved_status = $approval_status; if(!$itemModel->save(false)) { echo '
'; print_r($itemModel->getErrors()); echo '
';exit; } foreach ((array)$langauge as $key => $languageValue) { $itemLangmodel = new ItemLang(); $itemLangmodel->item_id = $itemModel->getPrimaryKey(); $itemLangmodel->language_code = strtolower($languageValue->language_code); $itemLangmodel->item_name = $iten_name; $itemLangmodel->item_description = $item_description; $itemLangmodel->save(false); } $i++; } Yii::$app->session->setFlash('success', Yii::t('backend', "successfully Uploaded")); return $this->redirect(['import-item']); } } return $this->render('import-item', ['modelItemFileUploadForm' => $modelItemFileUploadForm]); } /** * Upload Pictures * @return Array */ public function actionUpload() { $modelProductUploadFrom = new ProductUploadForm(); // print_r($_FILES); die; $file = UploadedFile::getInstance($modelProductUploadFrom, 'item_image_path'); $msg = 'Unknown method'; if(!$file){ $msg = 'Upload a file'; goto skip; } $modelProductUploadFrom->item_image_path = $file; if (!$modelProductUploadFrom->validate()) { $msg= $modelProductUploadFrom->getFirstError('item_image_path'); goto skip; } $uploadHelper = UploadHelper::getInstance(); $join = $uploadHelper->join([$uploadHelper::TEMP,$uploadHelper::ITEM]); $uploadHelper->setpath($join); $uploadHelper->setUploadedFile($file); $path = $uploadHelper->getPath(true); $realpath = $uploadHelper->getRealPath($path); $file->saveAs($path); $result = ['original_path' => DIRECTORY_SEPARATOR .$realpath]; $result['thumb'] = DIRECTORY_SEPARATOR . $uploadHelper ->generateThumb($uploadHelper->getAbsPath($result['original_path'])); $result['large_path'] = DIRECTORY_SEPARATOR . $uploadHelper ->resize( $uploadHelper->getAbsPath($result['original_path']), Item::LARGE_IMAGE_WIDTH ); return $this->asJson($result); skip: throw new \yii\web\HttpException(400,$msg); } }