From 25b2104324f516fb109607e42d6ac038d39998cc Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 23 Nov 2016 18:56:46 +0200 Subject: [PATCH] add create_item to translate --- controllers/OrderPaymentController.php | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/Order.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- models/OrderPayment.php | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/OrderPaymentLang.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/OrderPaymentSearch.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/order-payment/_form.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ views/order-payment/_form_language.php | 23 +++++++++++++++++++++++ views/order-payment/_search.php | 27 +++++++++++++++++++++++++++ views/order-payment/create.php | 23 +++++++++++++++++++++++ views/order-payment/index.php | 36 ++++++++++++++++++++++++++++++++++++ views/order-payment/update.php | 24 ++++++++++++++++++++++++ views/order-payment/view.php | 35 +++++++++++++++++++++++++++++++++++ 12 files changed, 651 insertions(+), 27 deletions(-) create mode 100644 controllers/OrderPaymentController.php create mode 100644 models/OrderPayment.php create mode 100644 models/OrderPaymentLang.php create mode 100644 models/OrderPaymentSearch.php create mode 100644 views/order-payment/_form.php create mode 100755 views/order-payment/_form_language.php create mode 100644 views/order-payment/_search.php create mode 100644 views/order-payment/create.php create mode 100644 views/order-payment/index.php create mode 100644 views/order-payment/update.php create mode 100644 views/order-payment/view.php 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 @@ + + +
+ + + + field($model, 'status') + ->widget(Select2::className(), ( [ + 'name' => 'status', + 'hideSearch' => true, + 'data' => [ + 1 => \Yii::t('app', 'Active'), + 2 => \Yii::t('app', 'Inactive'), + ], + 'options' => [ 'placeholder' => \Yii::t('app', 'Select status...') ], + 'pluginOptions' => [ + 'allowClear' => true, + ], + ] )) ?> + + $modelLangs, + 'formView' => '@artweb/artbox/ecommerce/views/order-payment/_form_language', + 'form' => $form, + ]) ?> +
+ isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/views/order-payment/_form_language.php b/views/order-payment/_form_language.php new file mode 100755 index 0000000..e0ea519 --- /dev/null +++ b/views/order-payment/_form_language.php @@ -0,0 +1,23 @@ + + + + + +field($model_lang, '[' . $language->id . ']title')->textInput(['maxlength' => true]) ?> + + + + + diff --git a/views/order-payment/_search.php b/views/order-payment/_search.php new file mode 100644 index 0000000..62879a1 --- /dev/null +++ b/views/order-payment/_search.php @@ -0,0 +1,27 @@ + + + diff --git a/views/order-payment/create.php b/views/order-payment/create.php new file mode 100644 index 0000000..053f69c --- /dev/null +++ b/views/order-payment/create.php @@ -0,0 +1,23 @@ +title = 'Create Order Payment'; +$this->params['breadcrumbs'][] = ['label' => 'Order Payments', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + 'modelLangs' => $modelLangs + ]) ?> + + +
diff --git a/views/order-payment/index.php b/views/order-payment/index.php new file mode 100644 index 0000000..588b22d --- /dev/null +++ b/views/order-payment/index.php @@ -0,0 +1,36 @@ +title = 'Order Payments'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'status', + [ + 'attribute' => 'title', + 'value' => 'lang.title', + ], + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> +
diff --git a/views/order-payment/update.php b/views/order-payment/update.php new file mode 100644 index 0000000..c48d1a7 --- /dev/null +++ b/views/order-payment/update.php @@ -0,0 +1,24 @@ +title = 'Update Order Payment: ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Order Payments', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + + render('_form', [ + 'model' => $model, + 'modelLangs' => $modelLangs + ]) ?> + + +
diff --git a/views/order-payment/view.php b/views/order-payment/view.php new file mode 100644 index 0000000..98e37c4 --- /dev/null +++ b/views/order-payment/view.php @@ -0,0 +1,35 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Order Payments', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + ], + ]) ?> + +
-- libgit2 0.21.4