Commit df25c120b9614cbd20bdf6318e0783c9b2cd506c

Authored by Alexey Boroda
2 parents deaedeb0 7c536875

Merge remote-tracking branch 'origin/master'

Showing 2 changed files with 48 additions and 4 deletions   Show diff stats
controllers/OrderController.php
@@ -237,7 +237,12 @@ @@ -237,7 +237,12 @@
237 $model->published = false; 237 $model->published = false;
238 $model->save(); 238 $model->save();
239 239
240 - return $this->redirect(['update', 'id' => $model->id]); 240 + return $this->redirect(
  241 + [
  242 + 'update',
  243 + 'id' => $model->id,
  244 + ]
  245 + );
241 246
242 $dataProvider = new ActiveDataProvider( 247 $dataProvider = new ActiveDataProvider(
243 [ 248 [
@@ -353,7 +358,7 @@ @@ -353,7 +358,7 @@
353 } 358 }
354 } 359 }
355 360
356 - public function actionFindProduct($q = NULL, $id = NULL) 361 + public function actionFindProduct($q = null, $id = null)
357 { 362 {
358 \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; 363 \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
359 $out = [ 364 $out = [
@@ -409,7 +414,7 @@ @@ -409,7 +414,7 @@
409 414
410 protected function findModel($id) 415 protected function findModel($id)
411 { 416 {
412 - if (( $model = Order::findOne($id) ) !== NULL) { 417 + if (( $model = Order::findOne($id) ) !== null) {
413 return $model; 418 return $model;
414 } else { 419 } else {
415 throw new NotFoundHttpException('The requested page does not exist.'); 420 throw new NotFoundHttpException('The requested page does not exist.');
@@ -472,9 +477,23 @@ @@ -472,9 +477,23 @@
472 $model->save(); 477 $model->save();
473 } 478 }
474 479
475 - public function actionPublishOrder($id) { 480 + public function actionPublishOrder($id)
  481 + {
476 $model = Order::findOne($id); 482 $model = Order::findOne($id);
477 $model->published = true; 483 $model->published = true;
478 $model->save(); 484 $model->save();
  485 + /**
  486 + * @var SmsSender $sender
  487 + */
  488 + $sender = \Yii::$app->sender;
  489 + $sender->send(
  490 + $model->phone,
  491 + $this->renderPartial(
  492 + '@common/mail/smsorder',
  493 + [
  494 + 'order_id' => $model->id,
  495 + ]
  496 + )
  497 + );
479 } 498 }
480 } 499 }
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 namespace artweb\artbox\ecommerce\models; 3 namespace artweb\artbox\ecommerce\models;
4 4
5 use yii\base\Component; 5 use yii\base\Component;
  6 + use yii\helpers\Json;
  7 + use yii\web\Cookie;
6 use yii\web\NotFoundHttpException; 8 use yii\web\NotFoundHttpException;
7 9
8 /** 10 /**
@@ -30,6 +32,16 @@ @@ -30,6 +32,16 @@
30 $this->session = \Yii::$app->session; 32 $this->session = \Yii::$app->session;
31 if (!$this->session->has('basket')) { 33 if (!$this->session->has('basket')) {
32 $this->session->set('basket', []); 34 $this->session->set('basket', []);
  35 + } elseif(!empty($this->session->get('basket'))) {
  36 + $cookies = \Yii::$app->response->cookies;
  37 + $cookies->add(
  38 + new Cookie(
  39 + [
  40 + 'name' => 'basket',
  41 + 'value' => Json::encode($this->session->get('basket')),
  42 + ]
  43 + )
  44 + );
33 } 45 }
34 parent::__construct($config); 46 parent::__construct($config);
35 } 47 }
@@ -131,6 +143,19 @@ @@ -131,6 +143,19 @@
131 public function setData(array $data) 143 public function setData(array $data)
132 { 144 {
133 $this->session->set('basket', $data); 145 $this->session->set('basket', $data);
  146 + $cookies = \Yii::$app->response->cookies;
  147 + if(empty($data)) {
  148 + $cookies->remove('basket');
  149 + } else {
  150 + $cookies->add(
  151 + new Cookie(
  152 + [
  153 + 'name' => 'basket',
  154 + 'value' => Json::encode($data),
  155 + ]
  156 + )
  157 + );
  158 + }
134 } 159 }
135 160
136 /** 161 /**