diff --git a/controllers/OrderPaymentController.php b/controllers/OrderPaymentController.php new file mode 100644 index 0000000..b18a65f --- /dev/null +++ b/controllers/OrderPaymentController.php @@ -0,0 +1,140 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all OrderPayment models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new OrderPaymentSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single OrderPayment model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new OrderPayment model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new OrderPayment(); + $model->generateLangs(); + if ($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if ($model->save() && $model->transactionStatus) { + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } + + } + + return $this->render('create', [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + ]); + } + + /** + * Updates an existing OrderPayment model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $model->generateLangs(); + if ($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if ($model->save() && $model->transactionStatus) { + + return $this->redirect([ + 'view', + 'id' => $model->id, + ]); + } + } + + return $this->render('update', [ + 'model' => $model, + 'modelLangs' => $model->modelLangs, + ]); + } + + /** + * Deletes an existing OrderPayment model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the OrderPayment model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return OrderPayment the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = OrderPayment::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/models/Order.php b/models/Order.php index 0b93dd4..e1f5778 100755 --- a/models/Order.php +++ b/models/Order.php @@ -42,6 +42,7 @@ * @property double $amount_imposed * @property string $shipping_by * @property string $city + * @property string $deliveryString */ class Order extends ActiveRecord { @@ -126,16 +127,6 @@ 'string', 'max' => 255, ], - [ - [ 'payment' ], - 'in', - 'range' => [ - 1, - 2, - 3, - 4, - ], - ], ]; } @@ -151,19 +142,7 @@ 'deleted_at' => Yii::t('app', 'Дата удаления'), ]; } - - // public function beforeSave($insert) - // { - // $this->user_id = Yii::$app->user->id; - // $this->date_time = new Expression('NOW()'); - // return parent::beforeSave($insert); - // } - // - // public function beforeDelete() - // { - // return parent::beforeDelete(); - // } - + public function addBasket($product_variant_id, $count) { $session = new Session; @@ -232,7 +211,11 @@ } $session[ 'basket' ] = $this->data; } - + + + /** + * @return array + */ public function getBasketMods() { $session = new Session; @@ -287,21 +270,71 @@ return $mod->price; } - + + public function clearBasket() { $session = new Session; $session->open(); $session[ 'basket' ] = NULL; } - + + + /** + * @return \yii\db\ActiveQuery + */ public function getUser() { return $this->hasOne(Customer::className(), [ 'id' => 'user_id' ]); } - + + /** + * @return \yii\db\ActiveQuery + */ public function getProducts() { return $this->hasMany(OrderProduct::className(), [ 'order_id' => 'id' ]); } + + + /** + * @return \yii\db\ActiveQuery + */ + public function getOrderDelivery(){ + return $this->hasOne(Delivery::className(), ['id'=> 'delivery']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getOrderLabel(){ + return $this->hasOne(Label::className(),['id'=> 'status']); + } + + + + /** + * @return \yii\db\ActiveQuery + */ + public function getOrderPayment(){ + return $this->hasOne(OrderPayment::className(),['id'=> 'payment']); + } + + + /** + * @return string + */ + public function getDeliveryString(){ + if(!empty($this->deliveryModel)){ + if(!empty($this->deliveryModel->parent)){ + return $this->deliveryModel->parent->lang->title .': '.$this->deliveryModel->lang->title; + } else { + return $this->deliveryModel->lang->title; + } + } else { + return ''; + } + } + + } \ No newline at end of file diff --git a/models/OrderPayment.php b/models/OrderPayment.php new file mode 100644 index 0000000..a57e13c --- /dev/null +++ b/models/OrderPayment.php @@ -0,0 +1,99 @@ + [ + 'class' => LanguageBehavior::className(), + 'objectLang' => OrderPaymentLang::className(), + 'ownerKey' => 'id', + 'langKey' => 'order_payment_id', + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [['status'], 'integer'], + [ + [ 'status' ], + 'default', + 'value' => 1, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => \Yii::t('app','ID'), + 'status' => \Yii::t('app','Статус'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getOrderPaymentLangs() + { + return $this->hasMany(OrderPaymentLang::className(), ['order_payment_id' => 'id']); + } +} diff --git a/models/OrderPaymentLang.php b/models/OrderPaymentLang.php new file mode 100644 index 0000000..3c31fa5 --- /dev/null +++ b/models/OrderPaymentLang.php @@ -0,0 +1,74 @@ + 255], + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']], + [['order_payment_id'], 'exist', 'skipOnError' => true, 'targetClass' => OrderPayment::className(), 'targetAttribute' => ['order_payment_id' => 'id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'order_payment_id' => 'Order Payment ID', + 'language_id' => 'Language ID', + 'title' => 'Title', + 'text' => 'Text', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLanguage() + { + return $this->hasOne(Language::className(), ['id' => 'language_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getOrderPayment() + { + return $this->hasOne(OrderPayment::className(), ['id' => 'order_payment_id']); + } +} diff --git a/models/OrderPaymentSearch.php b/models/OrderPaymentSearch.php new file mode 100644 index 0000000..da73a4c --- /dev/null +++ b/models/OrderPaymentSearch.php @@ -0,0 +1,66 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + ]); + + return $dataProvider; + } +} diff --git a/views/order-payment/_form.php b/views/order-payment/_form.php new file mode 100644 index 0000000..7550722 --- /dev/null +++ b/views/order-payment/_form.php @@ -0,0 +1,44 @@ + + +
+ = Html::a('Create Order Payment', ['create'], ['class' => 'btn btn-success']) ?> +
+ = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'status', + [ + 'attribute' => 'title', + 'value' => 'lang.title', + ], + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> ++ = Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> + = Html::a('Delete', ['delete', 'id' => $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id', + ], + ]) ?> + +