diff --git a/controllers/ManageController.php b/controllers/ManageController.php index cfe7b6c..9dcc8d3 100755 --- a/controllers/ManageController.php +++ b/controllers/ManageController.php @@ -11,6 +11,7 @@ use artweb\artbox\ecommerce\models\Product; use artweb\artbox\ecommerce\models\ProductSearch; use yii\db\ActiveQuery; + use yii\helpers\Html; use yii\helpers\VarDumper; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -220,13 +221,27 @@ */ public function actionIsTop($id) { - $model = $this->findModel($id); - - $model->is_top = intval(empty( $model->is_top )); - - $model->save(false, [ 'is_top' ]); - - return $this->redirect([ 'index' ]); + \Yii::$app->response->format = Response::FORMAT_JSON; + $product = Product::findOne($id); + $product->is_top = !$product->is_top; + if ($product->save()) { + if ($product->is_top) { + $tag = Html::tag('span', '', [ + 'class' => 'glyphicon glyphicon-star', + ]); + } else { + $tag = Html::tag('span', '', [ + 'class' => 'glyphicon glyphicon-star-empty', + ]); + } + return [ + 'success' => true, + 'tag' => $tag, + 'message' => 'Статус ТОП успешно изменен', + ]; + } else { + return []; + } } /** @@ -238,13 +253,27 @@ */ public function actionIsNew($id) { - $model = $this->findModel($id); - - $model->is_new = intval(empty( $model->is_new )); - - $model->save(false, [ 'is_new' ]); - - return $this->redirect([ 'index' ]); + \Yii::$app->response->format = Response::FORMAT_JSON; + $product = Product::findOne($id); + $product->is_new = !$product->is_new; + if ($product->save()) { + if ($product->is_new) { + $tag = Html::tag('span', '', [ + 'class' => 'glyphicon glyphicon-heart', + ]); + } else { + $tag = Html::tag('span', '', [ + 'class' => 'glyphicon glyphicon-heart-empty', + ]); + } + return [ + 'success' => true, + 'tag' => $tag, + 'message' => 'Статус НОВЫЙ успешно изменен', + ]; + } else { + return []; + } } /** @@ -256,13 +285,27 @@ */ public function actionIsDiscount($id) { - $model = $this->findModel($id); - - $model->is_discount = intval(empty( $model->is_discount )); - - $model->save(false, [ 'is_discount' ]); - - return $this->redirect([ 'index' ]); + \Yii::$app->response->format = Response::FORMAT_JSON; + $product = Product::findOne($id); + $product->is_discount = !$product->is_discount; + if ($product->save()) { + if ($product->is_discount) { + $tag = Html::tag('span', '', [ + 'class' => 'glyphicon glyphicon-tags', + ]); + } else { + $tag = Html::tag('span', '', [ + 'class' => 'glyphicon glyphicon-tag', + ]); + } + return [ + 'success' => true, + 'tag' => $tag, + 'message' => 'Статус АКЦИОННЫЙ успешно изменен', + ]; + } else { + return []; + } } /** diff --git a/views/manage/index.php b/views/manage/index.php index 4dfbc66..32a3f35 100755 --- a/views/manage/index.php +++ b/views/manage/index.php @@ -120,7 +120,7 @@ ], [ 'class' => 'yii\grid\ActionColumn', - 'template' => '{items} {view} |{is_top} {is_new} {is_discount} | {update} {delete}', + 'template' => '{items} {view} | {is_top} {is_new} {is_discount} | {update} {delete}', 'buttons' => [ 'is_top' => function ($url, $model) { return Html::a( @@ -128,6 +128,7 @@ $url, [ 'title' => Yii::t('product', ( $model->is_top ? 'Set not is top' : 'Set is top' )), + 'class' => 'toggle-status', ] ); }, @@ -137,6 +138,7 @@ $url, [ 'title' => Yii::t('product', ( $model->is_new ? 'Set not is new' : 'Set is new' )), + 'class' => 'toggle-status', ] ); }, @@ -149,6 +151,7 @@ 'product', ( $model->is_discount ? 'Set not is promotion' : 'Set is promotion' ) ), + 'class' => 'toggle-status', ] ); }, @@ -179,7 +182,7 @@ case 'is_top': return \yii\helpers\Url::to( [ - 'manage/is_top', + 'manage/is-top', 'id' => $model->id, ] ); @@ -187,7 +190,7 @@ case 'is_new': return \yii\helpers\Url::to( [ - 'manage/is_new', + 'manage/is-new', 'id' => $model->id, ] ); -- libgit2 0.21.4