/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/OrderMallProductController.php (7661B)
render('index',
[
'searchModel' => $searchModel,
'dataProvider' => $searchModel->search(Yii::$app->request->queryParams)
]
);
}
/**
*
* @return string
*
* @Title("Create")
*/
public function actionCreate()
{
$model = new MallProduct();
$modelLang = new MallProductLang();
$modelUploadForm = new MallProductUploadForm();
$modelUploadForm->setScenario($modelUploadForm::SCENARIO_CREATE);
$post = Yii::$app->getRequest()->post();
if ($model->load($post) && $modelLang->load($post) && $model->validate()) {
$uploadedFile = UploadedFile::getInstance($modelUploadForm, 'product_image_path');
$uploadHelper = UploadHelper::getInstance();
$uploadHelper->setPath($uploadHelper::MALL_PRODUCTS);
$uploadHelper->setUploadedFile($uploadedFile);
$path = $uploadHelper->getPath(true);
$uploadedFile->saveAs($path);
$model->save();
$realpath = $uploadHelper->getRealPath($path);
$modelLang->mall_product_id = $model->getPrimaryKey();
$modelLang->language_code = Yii::$app->language;
$modelLang->product_image_path = '/'. $realpath ;
$modelLang->save();
Com::successFlash('Created Successfully');
return $this->redirect(['index']);
}
return $this->render('create', [
'model' => $model,
'modelLang' => $modelLang,
'modelUploadForm' => $modelUploadForm
]);
}
/**
*
* @param type $id
* @return string
*
* @Title("Update")
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$modelLang = MallProductLang::find()
->select([
'mall_product_lang_id',
'product_name',
'product_description',
'product_image_path'
])
->where(['mall_product_id' => $model->getPrimaryKey()])
->one();
$product_image = $modelLang->product_image_path;
$modelUploadForm = new MallProductUploadForm();
$post = Yii::$app->getRequest()->post();
if ($model->load($post) && $model->validate()) {
$modelLang->load($post);
$uploadedFile = UploadedFile::getInstance($modelUploadForm, 'product_image_path');
if (!empty($uploadedFile)) {
$uploadHelper = UploadHelper::getInstance();
$uploadHelper->setPath($uploadHelper::MALL_PRODUCTS);
$uploadHelper->setUploadedFile($uploadedFile);
$path = $uploadHelper->getPath(true);
$model->save();
$uploadedFile->saveAs($path);
$realPath = $uploadHelper->getRealPath($path);
$modelLang->product_image_path = '/'. $realPath ;
} else {
$modelLang->product_image_path = $product_image;
}
if(!$model->save()) {
return $model;
}
$modelLang->mall_product_id = $model->getPrimaryKey();
$modelLang->language_code = Yii::$app->language;
$modelLang->save();
Com::successFlash('Updated Successfully');
return $this->redirect(['index']);
}
return $this->render('update', [
'model' => $model,
'modelLang' => $modelLang,
'modelUploadForm' => $modelUploadForm,
]);
}
/**
*
* @param type $id
* @return $string
*
* @Title("Delete")
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
if ($model === null) {
Com::failureFlash('Unable to find the Mall Product');
return $this->redirect(['index']);
}
$model->product_status = MallProduct::DELETE;
$model->save();
Com::successFlash('Deleted Successfully');
return $this->redirect(['index']);
}
/**
*
* @param type $id
* @return $model
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = MallProduct::findOne(['mall_product_key' => $id])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
* @return Json
* @throws \yii\base\InvalidParamException
* @throws \yii\base\Exception
*
* @Title("Mall Product Order Status")
*/
public function actionChangeStatus()
{
$params = ['id', 'status'];
$post = Yii::$app->getRequest()->post();
$result = ['status' => STATUS_FAIL, 'msg' => ''];
foreach ($params as $param) {
if ( !array_key_exists($param, $post) ) {
$result['msg'] = Yii::t('backend', 'Required param missing');
goto skip;
}
}
$model = OrderMallProduct::findOne(['order_mall_product_key' => $post['id']]);
if ( $model === null ) {
$result['msg'] = Yii::t('backend', 'Unable to find the requested Mall Product Order Detail');
goto skip;
}
$model->order_status = $post['status'];
$model->save(false);
$result['msg'] = 'Mall Product Order status updated successfully';
$result['status'] = STATUS_SUCCESS;
skip:
return $this->asJson($result);
}
/**
* @return Json
* @throws \yii\base\InvalidParamException
*
* @Title("Quick View")
*/
public function actionQuickView()
{
$params = ['id'];
$post = Yii::$app->getRequest()->post();
$result = ['status' => STATUS_FAIL, 'msg' => ''];
foreach ($params as $param) {
if ( !array_key_exists($param, $post) ) {
$result['msg'] = Yii::t('backend', 'Required param missing');
goto skip;
}
}
$OrderDetailsArray = OrderMallProduct::find()->where(['order_mall_product_key' => $post['id']])->one();
$result['status'] = STATUS_SUCCESS;
$result['response'] = json_encode($OrderDetailsArray->toArray());
$result['data'] = $this->renderPartial('quick-view', ['orderDetailsArray' => $OrderDetailsArray->toArray()]);
skip:
return $this->asJson($result);
}
/**
*
* @param type $id
* @return string
*
* @Title("Print")
*/
public function actionPrint($id)
{
$this->layout = 'print';
$model = Order::find()->where(['order_key' => $id])->one();
return $this->render(
'quick-view',
['resposeArray' => $model->toArray()]
);
}
}