Commit 25b2104324f516fb109607e42d6ac038d39998cc

Authored by Administrator
1 parent c242d006

add create_item to translate

controllers/OrderPaymentController.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +namespace artweb\artbox\ecommerce\controllers;
  4 +
  5 +use Yii;
  6 +use artweb\artbox\ecommerce\models\OrderPayment;
  7 +use artweb\artbox\ecommerce\models\OrderPaymentSearch;
  8 +use yii\web\Controller;
  9 +use yii\web\NotFoundHttpException;
  10 +use yii\filters\VerbFilter;
  11 +
  12 +/**
  13 + * OrderPaymentController implements the CRUD actions for OrderPayment model.
  14 + */
  15 +class OrderPaymentController extends Controller
  16 +{
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public function behaviors()
  21 + {
  22 + return [
  23 + 'verbs' => [
  24 + 'class' => VerbFilter::className(),
  25 + 'actions' => [
  26 + 'delete' => ['POST'],
  27 + ],
  28 + ],
  29 + ];
  30 + }
  31 +
  32 + /**
  33 + * Lists all OrderPayment models.
  34 + * @return mixed
  35 + */
  36 + public function actionIndex()
  37 + {
  38 + $searchModel = new OrderPaymentSearch();
  39 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  40 +
  41 + return $this->render('index', [
  42 + 'searchModel' => $searchModel,
  43 + 'dataProvider' => $dataProvider,
  44 + ]);
  45 + }
  46 +
  47 + /**
  48 + * Displays a single OrderPayment model.
  49 + * @param integer $id
  50 + * @return mixed
  51 + */
  52 + public function actionView($id)
  53 + {
  54 + return $this->render('view', [
  55 + 'model' => $this->findModel($id),
  56 + ]);
  57 + }
  58 +
  59 + /**
  60 + * Creates a new OrderPayment model.
  61 + * If creation is successful, the browser will be redirected to the 'view' page.
  62 + * @return mixed
  63 + */
  64 + public function actionCreate()
  65 + {
  66 + $model = new OrderPayment();
  67 + $model->generateLangs();
  68 + if ($model->load(Yii::$app->request->post())) {
  69 + $model->loadLangs(\Yii::$app->request);
  70 + if ($model->save() && $model->transactionStatus) {
  71 + return $this->redirect([
  72 + 'view',
  73 + 'id' => $model->id,
  74 + ]);
  75 + }
  76 +
  77 + }
  78 +
  79 + return $this->render('create', [
  80 + 'model' => $model,
  81 + 'modelLangs' => $model->modelLangs,
  82 + ]);
  83 + }
  84 +
  85 + /**
  86 + * Updates an existing OrderPayment model.
  87 + * If update is successful, the browser will be redirected to the 'view' page.
  88 + * @param integer $id
  89 + * @return mixed
  90 + */
  91 + public function actionUpdate($id)
  92 + {
  93 + $model = $this->findModel($id);
  94 + $model->generateLangs();
  95 + if ($model->load(Yii::$app->request->post())) {
  96 + $model->loadLangs(\Yii::$app->request);
  97 + if ($model->save() && $model->transactionStatus) {
  98 +
  99 + return $this->redirect([
  100 + 'view',
  101 + 'id' => $model->id,
  102 + ]);
  103 + }
  104 + }
  105 +
  106 + return $this->render('update', [
  107 + 'model' => $model,
  108 + 'modelLangs' => $model->modelLangs,
  109 + ]);
  110 + }
  111 +
  112 + /**
  113 + * Deletes an existing OrderPayment model.
  114 + * If deletion is successful, the browser will be redirected to the 'index' page.
  115 + * @param integer $id
  116 + * @return mixed
  117 + */
  118 + public function actionDelete($id)
  119 + {
  120 + $this->findModel($id)->delete();
  121 +
  122 + return $this->redirect(['index']);
  123 + }
  124 +
  125 + /**
  126 + * Finds the OrderPayment model based on its primary key value.
  127 + * If the model is not found, a 404 HTTP exception will be thrown.
  128 + * @param integer $id
  129 + * @return OrderPayment the loaded model
  130 + * @throws NotFoundHttpException if the model cannot be found
  131 + */
  132 + protected function findModel($id)
  133 + {
  134 + if (($model = OrderPayment::findOne($id)) !== null) {
  135 + return $model;
  136 + } else {
  137 + throw new NotFoundHttpException('The requested page does not exist.');
  138 + }
  139 + }
  140 +}
... ...
models/Order.php
... ... @@ -42,6 +42,7 @@
42 42 * @property double $amount_imposed
43 43 * @property string $shipping_by
44 44 * @property string $city
  45 + * @property string $deliveryString
45 46 */
46 47 class Order extends ActiveRecord
47 48 {
... ... @@ -126,16 +127,6 @@
126 127 'string',
127 128 'max' => 255,
128 129 ],
129   - [
130   - [ 'payment' ],
131   - 'in',
132   - 'range' => [
133   - 1,
134   - 2,
135   - 3,
136   - 4,
137   - ],
138   - ],
139 130 ];
140 131 }
141 132  
... ... @@ -151,19 +142,7 @@
151 142 'deleted_at' => Yii::t('app', 'ะ”ะฐั‚ะฐ ัƒะดะฐะปะตะฝะธั'),
152 143 ];
153 144 }
154   -
155   - // public function beforeSave($insert)
156   - // {
157   - // $this->user_id = Yii::$app->user->id;
158   - // $this->date_time = new Expression('NOW()');
159   - // return parent::beforeSave($insert);
160   - // }
161   - //
162   - // public function beforeDelete()
163   - // {
164   - // return parent::beforeDelete();
165   - // }
166   -
  145 +
167 146 public function addBasket($product_variant_id, $count)
168 147 {
169 148 $session = new Session;
... ... @@ -232,7 +211,11 @@
232 211 }
233 212 $session[ 'basket' ] = $this->data;
234 213 }
235   -
  214 +
  215 +
  216 + /**
  217 + * @return array
  218 + */
236 219 public function getBasketMods()
237 220 {
238 221 $session = new Session;
... ... @@ -287,21 +270,71 @@
287 270  
288 271 return $mod->price;
289 272 }
290   -
  273 +
  274 +
291 275 public function clearBasket()
292 276 {
293 277 $session = new Session;
294 278 $session->open();
295 279 $session[ 'basket' ] = NULL;
296 280 }
297   -
  281 +
  282 +
  283 + /**
  284 + * @return \yii\db\ActiveQuery
  285 + */
298 286 public function getUser()
299 287 {
300 288 return $this->hasOne(Customer::className(), [ 'id' => 'user_id' ]);
301 289 }
302   -
  290 +
  291 + /**
  292 + * @return \yii\db\ActiveQuery
  293 + */
303 294 public function getProducts()
304 295 {
305 296 return $this->hasMany(OrderProduct::className(), [ 'order_id' => 'id' ]);
306 297 }
  298 +
  299 +
  300 + /**
  301 + * @return \yii\db\ActiveQuery
  302 + */
  303 + public function getOrderDelivery(){
  304 + return $this->hasOne(Delivery::className(), ['id'=> 'delivery']);
  305 + }
  306 +
  307 + /**
  308 + * @return \yii\db\ActiveQuery
  309 + */
  310 + public function getOrderLabel(){
  311 + return $this->hasOne(Label::className(),['id'=> 'status']);
  312 + }
  313 +
  314 +
  315 +
  316 + /**
  317 + * @return \yii\db\ActiveQuery
  318 + */
  319 + public function getOrderPayment(){
  320 + return $this->hasOne(OrderPayment::className(),['id'=> 'payment']);
  321 + }
  322 +
  323 +
  324 + /**
  325 + * @return string
  326 + */
  327 + public function getDeliveryString(){
  328 + if(!empty($this->deliveryModel)){
  329 + if(!empty($this->deliveryModel->parent)){
  330 + return $this->deliveryModel->parent->lang->title .': '.$this->deliveryModel->lang->title;
  331 + } else {
  332 + return $this->deliveryModel->lang->title;
  333 + }
  334 + } else {
  335 + return '';
  336 + }
  337 + }
  338 +
  339 +
307 340 }
308 341 \ No newline at end of file
... ...
models/OrderPayment.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +namespace artweb\artbox\ecommerce\models;
  4 +
  5 +use artweb\artbox\language\behaviors\LanguageBehavior;
  6 +use Yii;
  7 +use yii\db\ActiveQuery;
  8 +use yii\db\ActiveRecord;
  9 +use yii\web\Request;
  10 +/**
  11 + * This is the model class for table "order_payment".
  12 + *
  13 + * @property integer $id
  14 + * @property integer $status
  15 + *
  16 + * @property OrderPaymentLang[] $orderPaymentLangs
  17 + *
  18 + * * From language behavior *
  19 + * @property orderPaymentLang $lang
  20 + * @property orderPaymentLang[] $langs
  21 + * @property orderPaymentLang $objectLang
  22 + * @property string $ownerKey
  23 + * @property string $langKey
  24 + * @property orderPaymentLang[] $modelLangs
  25 + * @property bool $transactionStatus
  26 + * @method string getOwnerKey()
  27 + * @method void setOwnerKey( string $value )
  28 + * @method string getLangKey()
  29 + * @method void setLangKey( string $value )
  30 + * @method ActiveQuery getLangs()
  31 + * @method ActiveQuery getLang( integer $language_id )
  32 + * @method OrderPaymentLang[] generateLangs()
  33 + * @method void loadLangs( Request $request )
  34 + * @method bool linkLangs()
  35 + * @method bool saveLangs()
  36 + * @method bool getTransactionStatus()
  37 + * * End language behavior
  38 + */
  39 +class OrderPayment extends \yii\db\ActiveRecord
  40 +{
  41 +
  42 +
  43 + const ACTIVE = 1;
  44 + const INACTIVE = 2;
  45 + /**
  46 + * @inheritdoc
  47 + */
  48 + public static function tableName()
  49 + {
  50 + return 'order_payment';
  51 + }
  52 +
  53 +
  54 + public function behaviors()
  55 + {
  56 + return [
  57 + 'language' => [
  58 + 'class' => LanguageBehavior::className(),
  59 + 'objectLang' => OrderPaymentLang::className(),
  60 + 'ownerKey' => 'id',
  61 + 'langKey' => 'order_payment_id',
  62 + ],
  63 + ];
  64 + }
  65 +
  66 + /**
  67 + * @inheritdoc
  68 + */
  69 + public function rules()
  70 + {
  71 + return [
  72 + [['status'], 'integer'],
  73 + [
  74 + [ 'status' ],
  75 + 'default',
  76 + 'value' => 1,
  77 + ],
  78 + ];
  79 + }
  80 +
  81 + /**
  82 + * @inheritdoc
  83 + */
  84 + public function attributeLabels()
  85 + {
  86 + return [
  87 + 'id' => \Yii::t('app','ID'),
  88 + 'status' => \Yii::t('app','ะกั‚ะฐั‚ัƒั'),
  89 + ];
  90 + }
  91 +
  92 + /**
  93 + * @return \yii\db\ActiveQuery
  94 + */
  95 + public function getOrderPaymentLangs()
  96 + {
  97 + return $this->hasMany(OrderPaymentLang::className(), ['order_payment_id' => 'id']);
  98 + }
  99 +}
... ...
models/OrderPaymentLang.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +namespace artweb\artbox\ecommerce\models;
  4 +
  5 +use artweb\artbox\language\models\Language;
  6 +use Yii;
  7 +
  8 +/**
  9 + * This is the model class for table "order_payment_lang".
  10 + *
  11 + * @property integer $id
  12 + * @property integer $order_payment_id
  13 + * @property integer $language_id
  14 + * @property string $title
  15 + * @property string $text
  16 + *
  17 + * @property Language $language
  18 + * @property OrderPayment $orderPayment
  19 + */
  20 +class OrderPaymentLang extends \yii\db\ActiveRecord
  21 +{
  22 + /**
  23 + * @inheritdoc
  24 + */
  25 + public static function tableName()
  26 + {
  27 + return 'order_payment_lang';
  28 + }
  29 +
  30 + /**
  31 + * @inheritdoc
  32 + */
  33 + public function rules()
  34 + {
  35 + return [
  36 + [['order_payment_id', 'language_id', 'title'], 'required'],
  37 + [['order_payment_id', 'language_id'], 'integer'],
  38 + [['text'], 'string'],
  39 + [['title'], 'string', 'max' => 255],
  40 + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']],
  41 + [['order_payment_id'], 'exist', 'skipOnError' => true, 'targetClass' => OrderPayment::className(), 'targetAttribute' => ['order_payment_id' => 'id']],
  42 + ];
  43 + }
  44 +
  45 + /**
  46 + * @inheritdoc
  47 + */
  48 + public function attributeLabels()
  49 + {
  50 + return [
  51 + 'id' => 'ID',
  52 + 'order_payment_id' => 'Order Payment ID',
  53 + 'language_id' => 'Language ID',
  54 + 'title' => 'Title',
  55 + 'text' => 'Text',
  56 + ];
  57 + }
  58 +
  59 + /**
  60 + * @return \yii\db\ActiveQuery
  61 + */
  62 + public function getLanguage()
  63 + {
  64 + return $this->hasOne(Language::className(), ['id' => 'language_id']);
  65 + }
  66 +
  67 + /**
  68 + * @return \yii\db\ActiveQuery
  69 + */
  70 + public function getOrderPayment()
  71 + {
  72 + return $this->hasOne(OrderPayment::className(), ['id' => 'order_payment_id']);
  73 + }
  74 +}
... ...
models/OrderPaymentSearch.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +namespace artweb\artbox\ecommerce\models;
  4 +
  5 +use Yii;
  6 +use yii\base\Model;
  7 +use yii\data\ActiveDataProvider;
  8 +use artweb\artbox\ecommerce\models\OrderPayment;
  9 +
  10 +/**
  11 + * OrderPaymentSearch represents the model behind the search form about `artweb\artbox\ecommerce\models\OrderPayment`.
  12 + */
  13 +class OrderPaymentSearch extends OrderPayment
  14 +{
  15 + /**
  16 + * @inheritdoc
  17 + */
  18 + public function rules()
  19 + {
  20 + return [
  21 + [['id'], 'integer'],
  22 + ];
  23 + }
  24 +
  25 + /**
  26 + * @inheritdoc
  27 + */
  28 + public function scenarios()
  29 + {
  30 + // bypass scenarios() implementation in the parent class
  31 + return Model::scenarios();
  32 + }
  33 +
  34 + /**
  35 + * Creates data provider instance with search query applied
  36 + *
  37 + * @param array $params
  38 + *
  39 + * @return ActiveDataProvider
  40 + */
  41 + public function search($params)
  42 + {
  43 + $query = OrderPayment::find();
  44 +
  45 + // add conditions that should always apply here
  46 +
  47 + $dataProvider = new ActiveDataProvider([
  48 + 'query' => $query,
  49 + ]);
  50 +
  51 + $this->load($params);
  52 +
  53 + if (!$this->validate()) {
  54 + // uncomment the following line if you do not want to return any records when validation fails
  55 + // $query->where('0=1');
  56 + return $dataProvider;
  57 + }
  58 +
  59 + // grid filtering conditions
  60 + $query->andFilterWhere([
  61 + 'id' => $this->id,
  62 + ]);
  63 +
  64 + return $dataProvider;
  65 + }
  66 +}
... ...
views/order-payment/_form.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +use artweb\artbox\ecommerce\models\OrderPaymentLang;
  4 +use artweb\artbox\language\widgets\LanguageForm;
  5 +use kartik\select2\Select2;
  6 +use yii\helpers\Html;
  7 +use yii\widgets\ActiveForm;
  8 +
  9 +/* @var $this yii\web\View */
  10 +/* @var $model artweb\artbox\ecommerce\models\OrderPayment */
  11 +/* @var $form yii\widgets\ActiveForm */
  12 +/* @var $modelLangs OrderPaymentLang */
  13 +?>
  14 +
  15 +<div class="order-payment-form">
  16 +
  17 + <?php $form = ActiveForm::begin(); ?>
  18 +
  19 + <?= $form->field($model, 'status')
  20 + ->widget(Select2::className(), ( [
  21 + 'name' => 'status',
  22 + 'hideSearch' => true,
  23 + 'data' => [
  24 + 1 => \Yii::t('app', 'Active'),
  25 + 2 => \Yii::t('app', 'Inactive'),
  26 + ],
  27 + 'options' => [ 'placeholder' => \Yii::t('app', 'Select status...') ],
  28 + 'pluginOptions' => [
  29 + 'allowClear' => true,
  30 + ],
  31 + ] )) ?>
  32 +
  33 + <?= LanguageForm::widget([
  34 + 'modelLangs' => $modelLangs,
  35 + 'formView' => '@artweb/artbox/ecommerce/views/order-payment/_form_language',
  36 + 'form' => $form,
  37 + ]) ?>
  38 + <div class="form-group">
  39 + <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
  40 + </div>
  41 +
  42 + <?php ActiveForm::end(); ?>
  43 +
  44 +</div>
... ...
views/order-payment/_form_language.php 0 โ†’ 100755
  1 +<?php
  2 +use artweb\artbox\ecommerce\models\OrderPaymentLang;
  3 +use artweb\artbox\language\models\Language;
  4 +use yii\web\View;
  5 +use yii\widgets\ActiveForm;
  6 +
  7 +/**
  8 + * @var OrderPaymentLang $model_lang
  9 + * @var Language $language
  10 + * @var ActiveForm $form
  11 + * @var View $this
  12 + */
  13 +?>
  14 +
  15 +
  16 +
  17 +
  18 +<?= $form->field($model_lang, '[' . $language->id . ']title')->textInput(['maxlength' => true]) ?>
  19 +
  20 +
  21 +
  22 +
  23 +
... ...
views/order-payment/_search.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\ActiveForm;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model artweb\artbox\ecommerce\models\OrderPaymentSearch */
  8 +/* @var $form yii\widgets\ActiveForm */
  9 +?>
  10 +
  11 +<div class="order-payment-search">
  12 +
  13 + <?php $form = ActiveForm::begin([
  14 + 'action' => ['index'],
  15 + 'method' => 'get',
  16 + ]); ?>
  17 +
  18 + <?= $form->field($model, 'id') ?>
  19 +
  20 + <div class="form-group">
  21 + <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
  22 + <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
  23 + </div>
  24 +
  25 + <?php ActiveForm::end(); ?>
  26 +
  27 +</div>
... ...
views/order-payment/create.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model artweb\artbox\ecommerce\models\OrderPayment */
  8 +
  9 +$this->title = 'Create Order Payment';
  10 +$this->params['breadcrumbs'][] = ['label' => 'Order Payments', 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="order-payment-create">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 + <?= $this->render('_form', [
  18 + 'model' => $model,
  19 + 'modelLangs' => $modelLangs
  20 + ]) ?>
  21 +
  22 +
  23 +</div>
... ...
views/order-payment/index.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\grid\GridView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $searchModel artweb\artbox\ecommerce\models\OrderPaymentSearch */
  8 +/* @var $dataProvider yii\data\ActiveDataProvider */
  9 +
  10 +$this->title = 'Order Payments';
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="order-payment-index">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 + <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
  17 +
  18 + <p>
  19 + <?= Html::a('Create Order Payment', ['create'], ['class' => 'btn btn-success']) ?>
  20 + </p>
  21 + <?= GridView::widget([
  22 + 'dataProvider' => $dataProvider,
  23 + 'filterModel' => $searchModel,
  24 + 'columns' => [
  25 + ['class' => 'yii\grid\SerialColumn'],
  26 +
  27 + 'status',
  28 + [
  29 + 'attribute' => 'title',
  30 + 'value' => 'lang.title',
  31 + ],
  32 +
  33 + ['class' => 'yii\grid\ActionColumn'],
  34 + ],
  35 + ]); ?>
  36 +</div>
... ...
views/order-payment/update.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +
  5 +/* @var $this yii\web\View */
  6 +/* @var $model artweb\artbox\ecommerce\models\OrderPayment */
  7 +
  8 +$this->title = 'Update Order Payment: ' . $model->id;
  9 +$this->params['breadcrumbs'][] = ['label' => 'Order Payments', 'url' => ['index']];
  10 +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
  11 +$this->params['breadcrumbs'][] = 'Update';
  12 +?>
  13 +<div class="order-payment-update">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 +
  18 + <?= $this->render('_form', [
  19 + 'model' => $model,
  20 + 'modelLangs' => $modelLangs
  21 + ]) ?>
  22 +
  23 +
  24 +</div>
... ...
views/order-payment/view.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +use yii\helpers\Html;
  4 +use yii\widgets\DetailView;
  5 +
  6 +/* @var $this yii\web\View */
  7 +/* @var $model artweb\artbox\ecommerce\models\OrderPayment */
  8 +
  9 +$this->title = $model->id;
  10 +$this->params['breadcrumbs'][] = ['label' => 'Order Payments', 'url' => ['index']];
  11 +$this->params['breadcrumbs'][] = $this->title;
  12 +?>
  13 +<div class="order-payment-view">
  14 +
  15 + <h1><?= Html::encode($this->title) ?></h1>
  16 +
  17 + <p>
  18 + <?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
  19 + <?= Html::a('Delete', ['delete', 'id' => $model->id], [
  20 + 'class' => 'btn btn-danger',
  21 + 'data' => [
  22 + 'confirm' => 'Are you sure you want to delete this item?',
  23 + 'method' => 'post',
  24 + ],
  25 + ]) ?>
  26 + </p>
  27 +
  28 + <?= DetailView::widget([
  29 + 'model' => $model,
  30 + 'attributes' => [
  31 + 'id',
  32 + ],
  33 + ]) ?>
  34 +
  35 +</div>
... ...