Commit 7cfb6c633843b6b473759719e904867fc4c88d26

Authored by Alexey Boroda
2 parents 44747138 9e6e9086

Merge remote-tracking branch 'origin/master'

Showing 2 changed files with 46 additions and 17 deletions   Show diff stats
controllers/OrderController.php
... ... @@ -176,6 +176,7 @@
176 176  
177 177 if (!empty( $model )) {
178 178 $model->count += $count;
  179 + $model->removed = false;
179 180 } else {
180 181 $model = new OrderProduct();
181 182  
... ... @@ -186,6 +187,7 @@
186 187 $model->sku = $productVariant->sku;
187 188 $model->price = $productVariant->price;
188 189 $model->count = $count;
  190 + $model->removed = false;
189 191 }
190 192 \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
191 193  
... ... @@ -320,9 +322,9 @@
320 322  
321 323 return $out;
322 324 }
323   -
  325 +
324 326 $model = $this->findModel($id);
325   -
  327 +
326 328 /**
327 329 * @var User $user
328 330 */
... ... @@ -332,7 +334,7 @@
332 334 throw new ForbiddenHttpException();
333 335 }
334 336 }
335   -
  337 +
336 338 $dataProvider = new ActiveDataProvider(
337 339 [
338 340 'query' => $model->getProducts()
... ... @@ -345,11 +347,32 @@
345 347 if (empty( $model->manager_id )) {
346 348 $model->manager_id = \Yii::$app->user->id;
347 349 }
348   -
  350 +
349 351 $headers = \Yii::$app->response->headers;
350 352 $headers->set('Access-Control-Allow-Origin', '*');
351 353  
352 354 if ($model->load(Yii::$app->request->post()) && $model->save()) {
  355 +
  356 + if ($model->published != true) {
  357 + $model->published = true;
  358 + $model->save();
  359 + /**
  360 + * @var SmsSender $sender
  361 + */
  362 +
  363 + $sender = \Yii::$app->sender;
  364 + $sender->send(
  365 + $model->phone,
  366 + $this->renderPartial(
  367 + '@common/mail/smsorder',
  368 + [
  369 + 'order_id' => $model->id,
  370 + ]
  371 + )
  372 + );
  373 + }
  374 +
  375 +
353 376 $this->unblockOrder($model->id);
354 377 return $this->render(
355 378 'update',
... ... @@ -416,6 +439,7 @@
416 439 {
417 440 $model = OrderProduct::findOne($id);
418 441 $model->removed = true;
  442 + $model->count = 0;
419 443 $model->save();
420 444 $order = Order::findOne($order_id);
421 445 $order->totalRecount();
... ... @@ -445,7 +469,7 @@
445 469 if ($model->edit_id == \Yii::$app->user->id) {
446 470 $this->unblockOrder(\Yii::$app->request->post('id'));
447 471 }
448   -
  472 +
449 473 if (!$model->published) {
450 474 $model->deleteUnpublished();
451 475 }
... ... @@ -508,7 +532,7 @@
508 532 $model->save();
509 533 }
510 534  
511   - public function actionPublishOrder($id)
  535 + public function actionPublishOrder($id,$phone)
512 536 {
513 537 $model = Order::findOne($id);
514 538 if ($model->published == true) {
... ... @@ -520,14 +544,17 @@
520 544 * @var SmsSender $sender
521 545 */
522 546 $sender = \Yii::$app->sender;
523   - $sender->send(
524   - $model->phone,
525   - $this->renderPartial(
526   - '@common/mail/smsorder',
527   - [
528   - 'order_id' => $model->id,
529   - ]
530   - )
531   - );
  547 + if(!empty($phone)){
  548 + $sender->send(
  549 + $phone,
  550 + $this->renderPartial(
  551 + '@common/mail/smsorder',
  552 + [
  553 + 'order_id' => $model->id,
  554 + ]
  555 + )
  556 + );
  557 + }
  558 +
532 559 }
533 560 }
... ...
views/order/_form.php
... ... @@ -122,14 +122,16 @@ JS;
122 122  
123 123 $js = <<< JS
124 124 $(document).on('click', '#page-submit', function() {
  125 + var phone = $('#order-phone').val();
125 126 $.ajax({
126 127 url: "/admin/ecommerce/order/publish-order",
127 128 type: "GET",
128 129 data: {
129   - id: {$model->id}
  130 + id: {$model->id},
  131 + phone: phone
130 132 },
131 133 success: function (data) {
132   -
  134 +
133 135 },
134 136 error: function () {
135 137 }
... ...