Commit 551235233ce73c71f45295424e0aa5429374af57
1 parent
85958295
-Status switcher
Showing
2 changed files
with
70 additions
and
24 deletions
Show diff stats
controllers/ManageController.php
| ... | ... | @@ -11,6 +11,7 @@ |
| 11 | 11 | use artweb\artbox\ecommerce\models\Product; |
| 12 | 12 | use artweb\artbox\ecommerce\models\ProductSearch; |
| 13 | 13 | use yii\db\ActiveQuery; |
| 14 | + use yii\helpers\Html; | |
| 14 | 15 | use yii\helpers\VarDumper; |
| 15 | 16 | use yii\web\Controller; |
| 16 | 17 | use yii\web\NotFoundHttpException; |
| ... | ... | @@ -220,13 +221,27 @@ |
| 220 | 221 | */ |
| 221 | 222 | public function actionIsTop($id) |
| 222 | 223 | { |
| 223 | - $model = $this->findModel($id); | |
| 224 | - | |
| 225 | - $model->is_top = intval(empty( $model->is_top )); | |
| 226 | - | |
| 227 | - $model->save(false, [ 'is_top' ]); | |
| 228 | - | |
| 229 | - return $this->redirect([ 'index' ]); | |
| 224 | + \Yii::$app->response->format = Response::FORMAT_JSON; | |
| 225 | + $product = Product::findOne($id); | |
| 226 | + $product->is_top = !$product->is_top; | |
| 227 | + if ($product->save()) { | |
| 228 | + if ($product->is_top) { | |
| 229 | + $tag = Html::tag('span', '', [ | |
| 230 | + 'class' => 'glyphicon glyphicon-star', | |
| 231 | + ]); | |
| 232 | + } else { | |
| 233 | + $tag = Html::tag('span', '', [ | |
| 234 | + 'class' => 'glyphicon glyphicon-star-empty', | |
| 235 | + ]); | |
| 236 | + } | |
| 237 | + return [ | |
| 238 | + 'success' => true, | |
| 239 | + 'tag' => $tag, | |
| 240 | + 'message' => 'Статус ТОП успешно изменен', | |
| 241 | + ]; | |
| 242 | + } else { | |
| 243 | + return []; | |
| 244 | + } | |
| 230 | 245 | } |
| 231 | 246 | |
| 232 | 247 | /** |
| ... | ... | @@ -238,13 +253,27 @@ |
| 238 | 253 | */ |
| 239 | 254 | public function actionIsNew($id) |
| 240 | 255 | { |
| 241 | - $model = $this->findModel($id); | |
| 242 | - | |
| 243 | - $model->is_new = intval(empty( $model->is_new )); | |
| 244 | - | |
| 245 | - $model->save(false, [ 'is_new' ]); | |
| 246 | - | |
| 247 | - return $this->redirect([ 'index' ]); | |
| 256 | + \Yii::$app->response->format = Response::FORMAT_JSON; | |
| 257 | + $product = Product::findOne($id); | |
| 258 | + $product->is_new = !$product->is_new; | |
| 259 | + if ($product->save()) { | |
| 260 | + if ($product->is_new) { | |
| 261 | + $tag = Html::tag('span', '', [ | |
| 262 | + 'class' => 'glyphicon glyphicon-heart', | |
| 263 | + ]); | |
| 264 | + } else { | |
| 265 | + $tag = Html::tag('span', '', [ | |
| 266 | + 'class' => 'glyphicon glyphicon-heart-empty', | |
| 267 | + ]); | |
| 268 | + } | |
| 269 | + return [ | |
| 270 | + 'success' => true, | |
| 271 | + 'tag' => $tag, | |
| 272 | + 'message' => 'Статус НОВЫЙ успешно изменен', | |
| 273 | + ]; | |
| 274 | + } else { | |
| 275 | + return []; | |
| 276 | + } | |
| 248 | 277 | } |
| 249 | 278 | |
| 250 | 279 | /** |
| ... | ... | @@ -256,13 +285,27 @@ |
| 256 | 285 | */ |
| 257 | 286 | public function actionIsDiscount($id) |
| 258 | 287 | { |
| 259 | - $model = $this->findModel($id); | |
| 260 | - | |
| 261 | - $model->is_discount = intval(empty( $model->is_discount )); | |
| 262 | - | |
| 263 | - $model->save(false, [ 'is_discount' ]); | |
| 264 | - | |
| 265 | - return $this->redirect([ 'index' ]); | |
| 288 | + \Yii::$app->response->format = Response::FORMAT_JSON; | |
| 289 | + $product = Product::findOne($id); | |
| 290 | + $product->is_discount = !$product->is_discount; | |
| 291 | + if ($product->save()) { | |
| 292 | + if ($product->is_discount) { | |
| 293 | + $tag = Html::tag('span', '', [ | |
| 294 | + 'class' => 'glyphicon glyphicon-tags', | |
| 295 | + ]); | |
| 296 | + } else { | |
| 297 | + $tag = Html::tag('span', '', [ | |
| 298 | + 'class' => 'glyphicon glyphicon-tag', | |
| 299 | + ]); | |
| 300 | + } | |
| 301 | + return [ | |
| 302 | + 'success' => true, | |
| 303 | + 'tag' => $tag, | |
| 304 | + 'message' => 'Статус АКЦИОННЫЙ успешно изменен', | |
| 305 | + ]; | |
| 306 | + } else { | |
| 307 | + return []; | |
| 308 | + } | |
| 266 | 309 | } |
| 267 | 310 | |
| 268 | 311 | /** | ... | ... |
views/manage/index.php
| ... | ... | @@ -120,7 +120,7 @@ |
| 120 | 120 | ], |
| 121 | 121 | [ |
| 122 | 122 | 'class' => 'yii\grid\ActionColumn', |
| 123 | - 'template' => '{items} {view} |{is_top} {is_new} {is_discount} | {update} {delete}', | |
| 123 | + 'template' => '{items} {view} | {is_top} {is_new} {is_discount} | {update} {delete}', | |
| 124 | 124 | 'buttons' => [ |
| 125 | 125 | 'is_top' => function ($url, $model) { |
| 126 | 126 | return Html::a( |
| ... | ... | @@ -128,6 +128,7 @@ |
| 128 | 128 | $url, |
| 129 | 129 | [ |
| 130 | 130 | 'title' => Yii::t('product', ( $model->is_top ? 'Set not is top' : 'Set is top' )), |
| 131 | + 'class' => 'toggle-status', | |
| 131 | 132 | ] |
| 132 | 133 | ); |
| 133 | 134 | }, |
| ... | ... | @@ -137,6 +138,7 @@ |
| 137 | 138 | $url, |
| 138 | 139 | [ |
| 139 | 140 | 'title' => Yii::t('product', ( $model->is_new ? 'Set not is new' : 'Set is new' )), |
| 141 | + 'class' => 'toggle-status', | |
| 140 | 142 | ] |
| 141 | 143 | ); |
| 142 | 144 | }, |
| ... | ... | @@ -149,6 +151,7 @@ |
| 149 | 151 | 'product', |
| 150 | 152 | ( $model->is_discount ? 'Set not is promotion' : 'Set is promotion' ) |
| 151 | 153 | ), |
| 154 | + 'class' => 'toggle-status', | |
| 152 | 155 | ] |
| 153 | 156 | ); |
| 154 | 157 | }, |
| ... | ... | @@ -179,7 +182,7 @@ |
| 179 | 182 | case 'is_top': |
| 180 | 183 | return \yii\helpers\Url::to( |
| 181 | 184 | [ |
| 182 | - 'manage/is_top', | |
| 185 | + 'manage/is-top', | |
| 183 | 186 | 'id' => $model->id, |
| 184 | 187 | ] |
| 185 | 188 | ); |
| ... | ... | @@ -187,7 +190,7 @@ |
| 187 | 190 | case 'is_new': |
| 188 | 191 | return \yii\helpers\Url::to( |
| 189 | 192 | [ |
| 190 | - 'manage/is_new', | |
| 193 | + 'manage/is-new', | |
| 191 | 194 | 'id' => $model->id, |
| 192 | 195 | ] |
| 193 | 196 | ); | ... | ... |