diff --git a/common/models/Customers.php b/common/models/Customers.php index 558ce2a..956ab66 100755 --- a/common/models/Customers.php +++ b/common/models/Customers.php @@ -37,7 +37,6 @@ class Customers extends User public function rules() { return [ - [['username', 'auth_key', 'password_hash', 'email', 'phone'], 'required'], [['status', 'created_at', 'updated_at'], 'integer'], [['username', 'password_hash', 'password_reset_token', 'email', 'phone','surname'], 'string', 'max' => 255], [['auth_key'], 'string', 'max' => 32], diff --git a/common/models/Orders.php b/common/models/Orders.php index 59764fa..0972b77 100755 --- a/common/models/Orders.php +++ b/common/models/Orders.php @@ -97,25 +97,31 @@ class Orders extends \yii\db\ActiveRecord } - public function afterSave($insert, $changedAttributes) + public function beforeSave($insert) { - parent::afterSave($insert, $changedAttributes); - if($this->isNewRecord){ - $customer = Customers::find()->where(['phone'=> $this->phone])->one(); - if($customer instanceof Customers){ - $this->customer_id = $customer->id; - $this->save(); - } else { - $customer = new Customers(['scenario' => Customers::SCENARIO_ORDER]); - $customer->email = $this->email; - $customer->phone = $this->phone; - $customer->username = $this->name; - $this->customer_id = $customer->id; - $this->save(); + if (parent::beforeSave($insert)) { + if($this->isNewRecord){ + $customer = Customers::find()->where(['phone'=> $this->phone])->one(); + + if($customer instanceof Customers){ + $this->customer_id = $customer->id; + } else { + $customer = new Customers(['scenario' => Customers::SCENARIO_ORDER]); + $customer->email = $this->email; + $customer->phone = $this->phone; + $customer->username = $this->name; + $customer->save(); + $this->customer_id = $customer->id; + } } + return true; + } else { + return false; } + + } /** diff --git a/frontend/controllers/OrdersController.php b/frontend/controllers/OrdersController.php index 420e60d..006b746 100755 --- a/frontend/controllers/OrdersController.php +++ b/frontend/controllers/OrdersController.php @@ -94,39 +94,32 @@ class OrdersController extends Controller $remoteItemModel = RemoteOrders::find()->where(['ID'=>$order_id, 'ID_Product'=> $variant[$k]->product_variant_id])->one(); - $payment = [ - '1' => 'Оплата наличными', - '2' => 'Оплата по безналичному расчету. Код ЕГРПОУ', - '3' => 'Приват 24', - '4' => 'Согласовать с менеджером', - ]; - - if($remoteItemModel instanceof RemoteOrders){ - $itemModel->ID = $order_id; - $itemModel->ID_Client = $order_model->customer_id; - $itemModel->ID_Product = $variant[$k]->product_variant_id; - $itemModel->Quantity = $sessionData[$k]['num']; - $itemModel->Price_old = $variant[$k]->price; - $itemModel->Date = date("Y-m-d H:i:s"); -// $itemModel->Rate = ''; - $itemModel->Sum = $variant[$k]->price * $sessionData[$k]['num']; - $itemModel->Payment_type = $payment[$order_model->payment]; - $itemModel->save(); + $remoteItemModel->ID = (string)$order_id; + $remoteItemModel->ID_Client = (string)$order_model->customer_id; + $remoteItemModel->ID_Product = (string)$variant[$k]->product_variant_id; + $remoteItemModel->Quantity = $sessionData[$k]['num']; + $remoteItemModel->Price_old = $variant[$k]->price; + $remoteItemModel->Date = date("Y-m-d H:i:s"); +// $remoteItemModel->Rate = ''; + $remoteItemModel->Sum = $variant[$k]->price * $sessionData[$k]['num']; + $remoteItemModel->Payment_type = $order_model->payment; + $remoteItemModel->save(); } else { - $itemModel = new RemoteOrders(); - $itemModel->ID = $order_id; - $itemModel->ID_Client = $order_model->customer_id; - $itemModel->ID_Product = $variant[$k]->product_variant_id; - $itemModel->Quantity = $sessionData[$k]['num']; - $itemModel->Price_old = $variant[$k]->price; - $itemModel->Date = date("Y-m-d H:i:s"); -// $itemModel->Rate = ''; - $itemModel->Sum = $variant[$k]->price * $sessionData[$k]['num']; - $itemModel->Payment_type = $payment[$order_model->payment]; - $itemModel->save(); + $remoteItemModel = new RemoteOrders(); + $remoteItemModel->ID = (string)$order_id; + $remoteItemModel->ID_Client = (string)$order_model->customer_id; + $remoteItemModel->ID_Product = (string)$variant[$k]->product_variant_id; + $remoteItemModel->Quantity = $sessionData[$k]['num']; + $remoteItemModel->Price_old = $variant[$k]->price; + $remoteItemModel->Date = date("Y-m-d H:i:s"); +// $remoteItemModel->Rate = ''; + $remoteItemModel->Sum = $variant[$k]->price * $sessionData[$k]['num']; + $remoteItemModel->Payment_type = $order_model->payment; + $remoteItemModel->save(); + } if($itemModel instanceof OrderItems){ diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 513418c..1eaf1e9 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -133,7 +133,7 @@ class SiteController extends Controller if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { - return $this->render('login', [ + return $this->render('index', [ 'model' => $model, ]); } -- libgit2 0.21.4