Commit b44453def4a64a45719185117760eaf8d26ff14e
1 parent
b9348bde
16.05.16 ann fotorama gallery
Showing
4 changed files
with
43 additions
and
45 deletions
Show diff stats
common/models/Customers.php
| @@ -37,7 +37,6 @@ class Customers extends User | @@ -37,7 +37,6 @@ class Customers extends User | ||
| 37 | public function rules() | 37 | public function rules() |
| 38 | { | 38 | { |
| 39 | return [ | 39 | return [ |
| 40 | - [['username', 'auth_key', 'password_hash', 'email', 'phone'], 'required'], | ||
| 41 | [['status', 'created_at', 'updated_at'], 'integer'], | 40 | [['status', 'created_at', 'updated_at'], 'integer'], |
| 42 | [['username', 'password_hash', 'password_reset_token', 'email', 'phone','surname'], 'string', 'max' => 255], | 41 | [['username', 'password_hash', 'password_reset_token', 'email', 'phone','surname'], 'string', 'max' => 255], |
| 43 | [['auth_key'], 'string', 'max' => 32], | 42 | [['auth_key'], 'string', 'max' => 32], |
common/models/Orders.php
| @@ -97,25 +97,31 @@ class Orders extends \yii\db\ActiveRecord | @@ -97,25 +97,31 @@ class Orders extends \yii\db\ActiveRecord | ||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | 99 | ||
| 100 | - public function afterSave($insert, $changedAttributes) | 100 | + public function beforeSave($insert) |
| 101 | { | 101 | { |
| 102 | - parent::afterSave($insert, $changedAttributes); | ||
| 103 | - if($this->isNewRecord){ | ||
| 104 | - $customer = Customers::find()->where(['phone'=> $this->phone])->one(); | ||
| 105 | - if($customer instanceof Customers){ | ||
| 106 | - $this->customer_id = $customer->id; | ||
| 107 | - $this->save(); | ||
| 108 | - } else { | ||
| 109 | - $customer = new Customers(['scenario' => Customers::SCENARIO_ORDER]); | ||
| 110 | - $customer->email = $this->email; | ||
| 111 | - $customer->phone = $this->phone; | ||
| 112 | - $customer->username = $this->name; | ||
| 113 | - $this->customer_id = $customer->id; | ||
| 114 | - $this->save(); | 102 | + if (parent::beforeSave($insert)) { |
| 103 | + if($this->isNewRecord){ | ||
| 104 | + $customer = Customers::find()->where(['phone'=> $this->phone])->one(); | ||
| 105 | + | ||
| 106 | + if($customer instanceof Customers){ | ||
| 107 | + $this->customer_id = $customer->id; | ||
| 108 | + } else { | ||
| 109 | + $customer = new Customers(['scenario' => Customers::SCENARIO_ORDER]); | ||
| 110 | + $customer->email = $this->email; | ||
| 111 | + $customer->phone = $this->phone; | ||
| 112 | + $customer->username = $this->name; | ||
| 113 | + $customer->save(); | ||
| 114 | + $this->customer_id = $customer->id; | ||
| 115 | + } | ||
| 115 | } | 116 | } |
| 117 | + return true; | ||
| 118 | + } else { | ||
| 119 | + return false; | ||
| 116 | } | 120 | } |
| 117 | 121 | ||
| 118 | 122 | ||
| 123 | + | ||
| 124 | + | ||
| 119 | } | 125 | } |
| 120 | 126 | ||
| 121 | /** | 127 | /** |
frontend/controllers/OrdersController.php
| @@ -94,39 +94,32 @@ class OrdersController extends Controller | @@ -94,39 +94,32 @@ class OrdersController extends Controller | ||
| 94 | $remoteItemModel = RemoteOrders::find()->where(['ID'=>$order_id, 'ID_Product'=> $variant[$k]->product_variant_id])->one(); | 94 | $remoteItemModel = RemoteOrders::find()->where(['ID'=>$order_id, 'ID_Product'=> $variant[$k]->product_variant_id])->one(); |
| 95 | 95 | ||
| 96 | 96 | ||
| 97 | - $payment = [ | ||
| 98 | - '1' => 'Оплата наличными', | ||
| 99 | - '2' => 'Оплата по безналичному расчету. Код ЕГРПОУ', | ||
| 100 | - '3' => 'Приват 24', | ||
| 101 | - '4' => 'Согласовать с менеджером', | ||
| 102 | - ]; | ||
| 103 | - | ||
| 104 | - | ||
| 105 | 97 | ||
| 106 | 98 | ||
| 107 | if($remoteItemModel instanceof RemoteOrders){ | 99 | if($remoteItemModel instanceof RemoteOrders){ |
| 108 | - $itemModel->ID = $order_id; | ||
| 109 | - $itemModel->ID_Client = $order_model->customer_id; | ||
| 110 | - $itemModel->ID_Product = $variant[$k]->product_variant_id; | ||
| 111 | - $itemModel->Quantity = $sessionData[$k]['num']; | ||
| 112 | - $itemModel->Price_old = $variant[$k]->price; | ||
| 113 | - $itemModel->Date = date("Y-m-d H:i:s"); | ||
| 114 | -// $itemModel->Rate = ''; | ||
| 115 | - $itemModel->Sum = $variant[$k]->price * $sessionData[$k]['num']; | ||
| 116 | - $itemModel->Payment_type = $payment[$order_model->payment]; | ||
| 117 | - $itemModel->save(); | 100 | + $remoteItemModel->ID = (string)$order_id; |
| 101 | + $remoteItemModel->ID_Client = (string)$order_model->customer_id; | ||
| 102 | + $remoteItemModel->ID_Product = (string)$variant[$k]->product_variant_id; | ||
| 103 | + $remoteItemModel->Quantity = $sessionData[$k]['num']; | ||
| 104 | + $remoteItemModel->Price_old = $variant[$k]->price; | ||
| 105 | + $remoteItemModel->Date = date("Y-m-d H:i:s"); | ||
| 106 | +// $remoteItemModel->Rate = ''; | ||
| 107 | + $remoteItemModel->Sum = $variant[$k]->price * $sessionData[$k]['num']; | ||
| 108 | + $remoteItemModel->Payment_type = $order_model->payment; | ||
| 109 | + $remoteItemModel->save(); | ||
| 118 | } else { | 110 | } else { |
| 119 | - $itemModel = new RemoteOrders(); | ||
| 120 | - $itemModel->ID = $order_id; | ||
| 121 | - $itemModel->ID_Client = $order_model->customer_id; | ||
| 122 | - $itemModel->ID_Product = $variant[$k]->product_variant_id; | ||
| 123 | - $itemModel->Quantity = $sessionData[$k]['num']; | ||
| 124 | - $itemModel->Price_old = $variant[$k]->price; | ||
| 125 | - $itemModel->Date = date("Y-m-d H:i:s"); | ||
| 126 | -// $itemModel->Rate = ''; | ||
| 127 | - $itemModel->Sum = $variant[$k]->price * $sessionData[$k]['num']; | ||
| 128 | - $itemModel->Payment_type = $payment[$order_model->payment]; | ||
| 129 | - $itemModel->save(); | 111 | + $remoteItemModel = new RemoteOrders(); |
| 112 | + $remoteItemModel->ID = (string)$order_id; | ||
| 113 | + $remoteItemModel->ID_Client = (string)$order_model->customer_id; | ||
| 114 | + $remoteItemModel->ID_Product = (string)$variant[$k]->product_variant_id; | ||
| 115 | + $remoteItemModel->Quantity = $sessionData[$k]['num']; | ||
| 116 | + $remoteItemModel->Price_old = $variant[$k]->price; | ||
| 117 | + $remoteItemModel->Date = date("Y-m-d H:i:s"); | ||
| 118 | +// $remoteItemModel->Rate = ''; | ||
| 119 | + $remoteItemModel->Sum = $variant[$k]->price * $sessionData[$k]['num']; | ||
| 120 | + $remoteItemModel->Payment_type = $order_model->payment; | ||
| 121 | + $remoteItemModel->save(); | ||
| 122 | + | ||
| 130 | } | 123 | } |
| 131 | 124 | ||
| 132 | if($itemModel instanceof OrderItems){ | 125 | if($itemModel instanceof OrderItems){ |
frontend/controllers/SiteController.php
| @@ -133,7 +133,7 @@ class SiteController extends Controller | @@ -133,7 +133,7 @@ class SiteController extends Controller | ||
| 133 | if ($model->load(Yii::$app->request->post()) && $model->login()) { | 133 | if ($model->load(Yii::$app->request->post()) && $model->login()) { |
| 134 | return $this->goBack(); | 134 | return $this->goBack(); |
| 135 | } else { | 135 | } else { |
| 136 | - return $this->render('login', [ | 136 | + return $this->render('index', [ |
| 137 | 'model' => $model, | 137 | 'model' => $model, |
| 138 | ]); | 138 | ]); |
| 139 | } | 139 | } |