Commit fdce5f4affa3867439a4beef2b51c21f69417482
1 parent
b35124cf
- order
Showing
12 changed files
with
1274 additions
and
65 deletions
Show diff stats
controllers/OrderController.php
| @@ -3,13 +3,13 @@ | @@ -3,13 +3,13 @@ | ||
| 3 | namespace artbox\order\controllers; | 3 | namespace artbox\order\controllers; |
| 4 | 4 | ||
| 5 | use artbox\catalog\models\Variant; | 5 | use artbox\catalog\models\Variant; |
| 6 | - use artbox\order\models\Delivery; | ||
| 7 | - use artbox\order\models\Label; | 6 | + use artbox\core\admin\actions\Index; |
| 7 | + use artbox\order\labels\models\Delivery; | ||
| 8 | + use artbox\order\labels\models\Label; | ||
| 8 | use artbox\order\models\OrderProduct; | 9 | use artbox\order\models\OrderProduct; |
| 9 | - use artbox\order\models\Payment; | 10 | + use artbox\order\labels\models\Payment; |
| 10 | use Yii; | 11 | use Yii; |
| 11 | use artbox\order\models\Order; | 12 | use artbox\order\models\Order; |
| 12 | - use artbox\order\models\OrderSearch; | ||
| 13 | use yii\web\Controller; | 13 | use yii\web\Controller; |
| 14 | use yii\web\NotFoundHttpException; | 14 | use yii\web\NotFoundHttpException; |
| 15 | use yii\filters\VerbFilter; | 15 | use yii\filters\VerbFilter; |
| @@ -25,6 +25,11 @@ | @@ -25,6 +25,11 @@ | ||
| 25 | /** | 25 | /** |
| 26 | * @inheritdoc | 26 | * @inheritdoc |
| 27 | */ | 27 | */ |
| 28 | + public function getViewPath() | ||
| 29 | + { | ||
| 30 | + return '@artbox/order/views/order'; | ||
| 31 | + } | ||
| 32 | + | ||
| 28 | public function behaviors() | 33 | public function behaviors() |
| 29 | { | 34 | { |
| 30 | return [ | 35 | return [ |
| @@ -53,39 +58,43 @@ | @@ -53,39 +58,43 @@ | ||
| 53 | ]; | 58 | ]; |
| 54 | } | 59 | } |
| 55 | 60 | ||
| 56 | - /** | ||
| 57 | - * Lists all Order models. | ||
| 58 | - * | ||
| 59 | - * @return mixed | ||
| 60 | - */ | ||
| 61 | - public function actionIndex() | 61 | + public function actions() |
| 62 | { | 62 | { |
| 63 | - $searchModel = new OrderSearch(); | ||
| 64 | - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
| 65 | - $labels = Label::find() | ||
| 66 | - ->select( | ||
| 67 | - [ | ||
| 68 | - 'title', | ||
| 69 | - 'id', | ||
| 70 | - ] | ||
| 71 | - ) | ||
| 72 | - ->joinWith('lang') | ||
| 73 | - ->andWhere( | ||
| 74 | - [ | ||
| 75 | - 'status' => true, | ||
| 76 | - ] | ||
| 77 | - ) | ||
| 78 | - ->indexBy('id') | ||
| 79 | - ->column(); | ||
| 80 | - | ||
| 81 | - return $this->render( | ||
| 82 | - 'index', | ||
| 83 | - [ | ||
| 84 | - 'searchModel' => $searchModel, | ||
| 85 | - 'dataProvider' => $dataProvider, | ||
| 86 | - 'labels' => $labels, | ||
| 87 | - ] | ||
| 88 | - ); | 63 | + return [ |
| 64 | + 'index' => [ | ||
| 65 | + 'class' => Index::className(), | ||
| 66 | + 'columns' => [ | ||
| 67 | + 'name' => [ | ||
| 68 | + 'type' => Index::ACTION_COL, | ||
| 69 | + ], | ||
| 70 | + 'phone' => [ | ||
| 71 | + 'type' => Index::STRING_COL, | ||
| 72 | + ], | ||
| 73 | + 'email' => [ | ||
| 74 | + 'type' => Index::STRING_COL, | ||
| 75 | + ], | ||
| 76 | + 'label' => [ | ||
| 77 | + 'type' => Index::RELATION_COL, | ||
| 78 | + 'columnConfig' => [ | ||
| 79 | + 'relationField' => 'title', | ||
| 80 | + ], | ||
| 81 | + ], | ||
| 82 | + 'created_at' => [ | ||
| 83 | + 'type' => Index::DATETIME_COL, | ||
| 84 | + ], | ||
| 85 | + 'sort' => [ | ||
| 86 | + 'type' => Index::POSITION_COL, | ||
| 87 | + ], | ||
| 88 | + 'status' => [ | ||
| 89 | + 'type' => Index::STATUS_COL, | ||
| 90 | + ], | ||
| 91 | + ], | ||
| 92 | + 'model' => Order::className(), | ||
| 93 | + 'hasLanguage' => false, | ||
| 94 | + 'enableMassDelete' => false, | ||
| 95 | + 'modelPrimaryKey' => 'id', | ||
| 96 | + ], | ||
| 97 | + ]; | ||
| 89 | } | 98 | } |
| 90 | 99 | ||
| 91 | /** | 100 | /** |
| @@ -145,50 +154,50 @@ | @@ -145,50 +154,50 @@ | ||
| 145 | ); | 154 | ); |
| 146 | } else { | 155 | } else { |
| 147 | $labels = Label::find() | 156 | $labels = Label::find() |
| 148 | - ->joinWith('lang') | ||
| 149 | - ->select( | 157 | + ->joinWith('language') |
| 158 | + ->select( | ||
| 150 | [ | 159 | [ |
| 151 | 'title', | 160 | 'title', |
| 152 | 'id', | 161 | 'id', |
| 153 | ] | 162 | ] |
| 154 | ) | 163 | ) |
| 155 | - ->where( | 164 | + ->where( |
| 156 | [ | 165 | [ |
| 157 | 'status' => true, | 166 | 'status' => true, |
| 158 | ] | 167 | ] |
| 159 | ) | 168 | ) |
| 160 | - ->indexBy('id') | ||
| 161 | - ->column(); | 169 | + ->indexBy('id') |
| 170 | + ->column(); | ||
| 162 | $deliveries = Delivery::find() | 171 | $deliveries = Delivery::find() |
| 163 | - ->joinWith('lang') | ||
| 164 | - ->select( | 172 | + ->joinWith('language') |
| 173 | + ->select( | ||
| 165 | [ | 174 | [ |
| 166 | 'title', | 175 | 'title', |
| 167 | 'id', | 176 | 'id', |
| 168 | ] | 177 | ] |
| 169 | ) | 178 | ) |
| 170 | - ->where( | 179 | + ->where( |
| 171 | [ | 180 | [ |
| 172 | 'status' => true, | 181 | 'status' => true, |
| 173 | ] | 182 | ] |
| 174 | ) | 183 | ) |
| 175 | - ->indexBy('id') | ||
| 176 | - ->column(); | 184 | + ->indexBy('id') |
| 185 | + ->column(); | ||
| 177 | $payments = Payment::find() | 186 | $payments = Payment::find() |
| 178 | - ->joinWith('lang') | ||
| 179 | - ->select( | 187 | + ->joinWith('language') |
| 188 | + ->select( | ||
| 180 | [ | 189 | [ |
| 181 | 'title', | 190 | 'title', |
| 182 | 'id', | 191 | 'id', |
| 183 | ] | 192 | ] |
| 184 | ) | 193 | ) |
| 185 | - ->where( | 194 | + ->where( |
| 186 | [ | 195 | [ |
| 187 | 'status' => true, | 196 | 'status' => true, |
| 188 | ] | 197 | ] |
| 189 | ) | 198 | ) |
| 190 | - ->indexBy('id') | ||
| 191 | - ->column(); | 199 | + ->indexBy('id') |
| 200 | + ->column(); | ||
| 192 | return $this->render( | 201 | return $this->render( |
| 193 | 'create', | 202 | 'create', |
| 194 | [ | 203 | [ |
| @@ -224,7 +233,7 @@ | @@ -224,7 +233,7 @@ | ||
| 224 | ); | 233 | ); |
| 225 | } else { | 234 | } else { |
| 226 | $labels = Label::find() | 235 | $labels = Label::find() |
| 227 | - ->joinWith('lang') | 236 | + ->joinWith('language') |
| 228 | ->select( | 237 | ->select( |
| 229 | [ | 238 | [ |
| 230 | 'title', | 239 | 'title', |
| @@ -239,35 +248,35 @@ | @@ -239,35 +248,35 @@ | ||
| 239 | ->indexBy('id') | 248 | ->indexBy('id') |
| 240 | ->column(); | 249 | ->column(); |
| 241 | $deliveries = Delivery::find() | 250 | $deliveries = Delivery::find() |
| 242 | - ->joinWith('lang') | ||
| 243 | - ->select( | 251 | + ->joinWith('language') |
| 252 | + ->select( | ||
| 244 | [ | 253 | [ |
| 245 | 'title', | 254 | 'title', |
| 246 | 'id', | 255 | 'id', |
| 247 | ] | 256 | ] |
| 248 | ) | 257 | ) |
| 249 | - ->where( | 258 | + ->where( |
| 250 | [ | 259 | [ |
| 251 | 'status' => true, | 260 | 'status' => true, |
| 252 | ] | 261 | ] |
| 253 | ) | 262 | ) |
| 254 | - ->indexBy('id') | ||
| 255 | - ->column(); | 263 | + ->indexBy('id') |
| 264 | + ->column(); | ||
| 256 | $payments = Payment::find() | 265 | $payments = Payment::find() |
| 257 | - ->joinWith('lang') | ||
| 258 | - ->select( | 266 | + ->joinWith('language') |
| 267 | + ->select( | ||
| 259 | [ | 268 | [ |
| 260 | 'title', | 269 | 'title', |
| 261 | 'id', | 270 | 'id', |
| 262 | ] | 271 | ] |
| 263 | ) | 272 | ) |
| 264 | - ->where( | 273 | + ->where( |
| 265 | [ | 274 | [ |
| 266 | 'status' => true, | 275 | 'status' => true, |
| 267 | ] | 276 | ] |
| 268 | ) | 277 | ) |
| 269 | - ->indexBy('id') | ||
| 270 | - ->column(); | 278 | + ->indexBy('id') |
| 279 | + ->column(); | ||
| 271 | return $this->render( | 280 | return $this->render( |
| 272 | 'update', | 281 | 'update', |
| 273 | [ | 282 | [ |
| @@ -448,7 +457,7 @@ | @@ -448,7 +457,7 @@ | ||
| 448 | protected function getLabels() | 457 | protected function getLabels() |
| 449 | { | 458 | { |
| 450 | return Label::find() | 459 | return Label::find() |
| 451 | - ->joinWith('lang') | 460 | + ->joinWith('language') |
| 452 | ->select( | 461 | ->select( |
| 453 | [ | 462 | [ |
| 454 | 'title', | 463 | 'title', |
| @@ -470,7 +479,7 @@ | @@ -470,7 +479,7 @@ | ||
| 470 | protected function getPayments() | 479 | protected function getPayments() |
| 471 | { | 480 | { |
| 472 | return Payment::find() | 481 | return Payment::find() |
| 473 | - ->joinWith('lang') | 482 | + ->joinWith('language') |
| 474 | ->select( | 483 | ->select( |
| 475 | [ | 484 | [ |
| 476 | 'title', | 485 | 'title', |
| @@ -492,7 +501,7 @@ | @@ -492,7 +501,7 @@ | ||
| 492 | protected function getDeliveries() | 501 | protected function getDeliveries() |
| 493 | { | 502 | { |
| 494 | return Delivery::find() | 503 | return Delivery::find() |
| 495 | - ->joinWith('lang') | 504 | + ->joinWith('language') |
| 496 | ->select( | 505 | ->select( |
| 497 | [ | 506 | [ |
| 498 | 'title', | 507 | 'title', |
| 1 | +<?php | ||
| 2 | + /** | ||
| 3 | + * Created by PhpStorm. | ||
| 4 | + * User: stes | ||
| 5 | + * Date: 13.04.18 | ||
| 6 | + * Time: 11:15 | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | + namespace artbox\order\labels\controllers; | ||
| 10 | + | ||
| 11 | + use artbox\core\admin\actions\Create; | ||
| 12 | + use artbox\core\admin\actions\Delete; | ||
| 13 | + use artbox\core\admin\actions\Index; | ||
| 14 | + use artbox\core\admin\actions\Update; | ||
| 15 | + use artbox\core\admin\actions\View; | ||
| 16 | + use artbox\core\admin\interfaces\ControllerInterface; | ||
| 17 | + use artbox\core\admin\widgets\Form; | ||
| 18 | + use artbox\order\labels\models\Delivery; | ||
| 19 | + use yii\web\Controller; | ||
| 20 | + use yii\web\NotFoundHttpException; | ||
| 21 | + | ||
| 22 | + class DeliveryController extends Controller implements ControllerInterface | ||
| 23 | + { | ||
| 24 | + public function actions() | ||
| 25 | + { | ||
| 26 | + return [ | ||
| 27 | + 'index' => [ | ||
| 28 | + 'class' => Index::className(), | ||
| 29 | + 'columns' => [ | ||
| 30 | + 'title' => [ | ||
| 31 | + 'type' => Index::ACTION_COL, | ||
| 32 | + ], | ||
| 33 | + 'sort' => [ | ||
| 34 | + 'type' => Index::POSITION_COL, | ||
| 35 | + ], | ||
| 36 | + 'status' => [ | ||
| 37 | + 'type' => Index::STATUS_COL, | ||
| 38 | + ], | ||
| 39 | + ], | ||
| 40 | + 'model' => Delivery::className(), | ||
| 41 | + 'hasLanguage' => true, | ||
| 42 | + 'enableMassDelete' => true, | ||
| 43 | + 'modelPrimaryKey' => 'id', | ||
| 44 | + ], | ||
| 45 | + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), | ||
| 46 | + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), | ||
| 47 | + 'view' => [ | ||
| 48 | + 'class' => View::className(), | ||
| 49 | + 'model' => Delivery::className(), | ||
| 50 | + 'hasAlias' => false, | ||
| 51 | + 'hasGallery' => false, | ||
| 52 | + 'languageFields' => [ | ||
| 53 | + [ | ||
| 54 | + 'name' => 'title', | ||
| 55 | + 'type' => Form::STRING, | ||
| 56 | + ], | ||
| 57 | + [ | ||
| 58 | + 'name' => 'description', | ||
| 59 | + 'type' => Form::WYSIWYG, | ||
| 60 | + ], | ||
| 61 | + ], | ||
| 62 | + 'fields' => [ | ||
| 63 | + [ | ||
| 64 | + 'name' => 'status', | ||
| 65 | + 'type' => Form::BOOL, | ||
| 66 | + ], | ||
| 67 | + [ | ||
| 68 | + 'name' => 'sort', | ||
| 69 | + 'type' => Form::NUMBER, | ||
| 70 | + ], | ||
| 71 | + [ | ||
| 72 | + 'name' => 'value', | ||
| 73 | + 'type' => Form::NUMBER, | ||
| 74 | + ], | ||
| 75 | + [ | ||
| 76 | + 'name' => 'color', | ||
| 77 | + 'type' => Form::STRING, | ||
| 78 | + ], | ||
| 79 | + [ | ||
| 80 | + 'name' => 'default', | ||
| 81 | + 'type' => Form::BOOL, | ||
| 82 | + ], | ||
| 83 | + ], | ||
| 84 | + ], | ||
| 85 | + 'delete' => [ | ||
| 86 | + 'class' => Delete::className(), | ||
| 87 | + ], | ||
| 88 | + ]; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public function findModel($id) | ||
| 92 | + { | ||
| 93 | + $model = Delivery::find() | ||
| 94 | + ->with('languages') | ||
| 95 | + ->where([ 'id' => $id ]) | ||
| 96 | + ->one(); | ||
| 97 | + if ($model !== null) { | ||
| 98 | + return $model; | ||
| 99 | + } else { | ||
| 100 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public function newModel() | ||
| 105 | + { | ||
| 106 | + return new Delivery(); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public function deleteModel($id) | ||
| 110 | + { | ||
| 111 | + $page = Delivery::find() | ||
| 112 | + ->with('languages') | ||
| 113 | + ->where( | ||
| 114 | + [ | ||
| 115 | + 'id' => $id, | ||
| 116 | + ] | ||
| 117 | + ) | ||
| 118 | + ->one(); | ||
| 119 | + $langs = call_user_func( | ||
| 120 | + [ | ||
| 121 | + $page, | ||
| 122 | + 'getVariationModels', | ||
| 123 | + ] | ||
| 124 | + ); | ||
| 125 | + foreach ($langs as $lang) { | ||
| 126 | + if ($lang->alias !== null) { | ||
| 127 | + $lang->alias->delete(); | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + return $page->delete(); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + protected static function fieldsConfig() | ||
| 135 | + { | ||
| 136 | + return [ | ||
| 137 | + 'model' => Delivery::className(), | ||
| 138 | + 'hasAlias' => false, | ||
| 139 | + 'hasGallery' => false, | ||
| 140 | + 'languageFields' => [ | ||
| 141 | + [ | ||
| 142 | + 'name' => 'title', | ||
| 143 | + 'type' => Form::STRING, | ||
| 144 | + ], | ||
| 145 | + [ | ||
| 146 | + 'name' => 'description', | ||
| 147 | + 'type' => Form::WYSIWYG, | ||
| 148 | + ], | ||
| 149 | + ], | ||
| 150 | + 'fields' => [ | ||
| 151 | + [ | ||
| 152 | + 'name' => 'status', | ||
| 153 | + 'type' => Form::BOOL, | ||
| 154 | + ], | ||
| 155 | + [ | ||
| 156 | + 'name' => 'sort', | ||
| 157 | + 'type' => Form::NUMBER, | ||
| 158 | + ], | ||
| 159 | + [ | ||
| 160 | + 'name' => 'value', | ||
| 161 | + 'type' => Form::NUMBER, | ||
| 162 | + ], | ||
| 163 | + [ | ||
| 164 | + 'name' => 'color', | ||
| 165 | + 'type' => Form::STRING, | ||
| 166 | + ], | ||
| 167 | + [ | ||
| 168 | + 'name' => 'default', | ||
| 169 | + 'type' => Form::BOOL, | ||
| 170 | + ], | ||
| 171 | + | ||
| 172 | + ], | ||
| 173 | + ]; | ||
| 174 | + } | ||
| 175 | + } | ||
| 0 | \ No newline at end of file | 176 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace artbox\order\labels\controllers; | ||
| 4 | + | ||
| 5 | + use artbox\core\admin\actions\Create; | ||
| 6 | + use artbox\core\admin\actions\Delete; | ||
| 7 | + use artbox\core\admin\actions\Index; | ||
| 8 | + use artbox\core\admin\actions\Update; | ||
| 9 | + use artbox\core\admin\actions\View; | ||
| 10 | + use artbox\core\admin\interfaces\ControllerInterface; | ||
| 11 | + use artbox\core\admin\widgets\Form; | ||
| 12 | + use artbox\order\labels\models\Label; | ||
| 13 | + use yii\web\Controller; | ||
| 14 | + use yii\web\NotFoundHttpException; | ||
| 15 | + | ||
| 16 | + class LabelController extends Controller implements ControllerInterface | ||
| 17 | + { | ||
| 18 | + public function actions() | ||
| 19 | + { | ||
| 20 | + return [ | ||
| 21 | + 'index' => [ | ||
| 22 | + 'class' => Index::className(), | ||
| 23 | + 'columns' => [ | ||
| 24 | + 'title' => [ | ||
| 25 | + 'type' => Index::ACTION_COL, | ||
| 26 | + ], | ||
| 27 | + 'sort' => [ | ||
| 28 | + 'type' => Index::POSITION_COL, | ||
| 29 | + ], | ||
| 30 | + 'status' => [ | ||
| 31 | + 'type' => Index::STATUS_COL, | ||
| 32 | + ], | ||
| 33 | + ], | ||
| 34 | + 'model' => Label::className(), | ||
| 35 | + 'hasLanguage' => true, | ||
| 36 | + 'enableMassDelete' => true, | ||
| 37 | + 'modelPrimaryKey' => 'id', | ||
| 38 | + ], | ||
| 39 | + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), | ||
| 40 | + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), | ||
| 41 | + 'view' => [ | ||
| 42 | + 'class' => View::className(), | ||
| 43 | + 'model' => Label::className(), | ||
| 44 | + 'hasAlias' => false, | ||
| 45 | + 'hasGallery' => false, | ||
| 46 | + 'languageFields' => [ | ||
| 47 | + [ | ||
| 48 | + 'name' => 'title', | ||
| 49 | + 'type' => Form::STRING, | ||
| 50 | + ], | ||
| 51 | + [ | ||
| 52 | + 'name' => 'description', | ||
| 53 | + 'type' => Form::WYSIWYG, | ||
| 54 | + ], | ||
| 55 | + ], | ||
| 56 | + 'fields' => [ | ||
| 57 | + [ | ||
| 58 | + 'name' => 'status', | ||
| 59 | + 'type' => Form::BOOL, | ||
| 60 | + ], | ||
| 61 | + [ | ||
| 62 | + 'name' => 'sort', | ||
| 63 | + 'type' => Form::NUMBER, | ||
| 64 | + ], | ||
| 65 | + [ | ||
| 66 | + 'name' => 'value', | ||
| 67 | + 'type' => Form::NUMBER, | ||
| 68 | + ], | ||
| 69 | + [ | ||
| 70 | + 'name' => 'color', | ||
| 71 | + 'type' => Form::STRING, | ||
| 72 | + ], | ||
| 73 | + [ | ||
| 74 | + 'name' => 'default', | ||
| 75 | + 'type' => Form::BOOL, | ||
| 76 | + ], | ||
| 77 | + ], | ||
| 78 | + ], | ||
| 79 | + 'delete' => [ | ||
| 80 | + 'class' => Delete::className(), | ||
| 81 | + ], | ||
| 82 | + ]; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public function findModel($id) | ||
| 86 | + { | ||
| 87 | + $model = Label::find() | ||
| 88 | + ->with('languages') | ||
| 89 | + ->where([ 'id' => $id ]) | ||
| 90 | + ->one(); | ||
| 91 | + if ($model !== null) { | ||
| 92 | + return $model; | ||
| 93 | + } else { | ||
| 94 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public function newModel() | ||
| 99 | + { | ||
| 100 | + return new Label(); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public function deleteModel($id) | ||
| 104 | + { | ||
| 105 | + $page = Label::find() | ||
| 106 | + ->with('languages') | ||
| 107 | + ->where( | ||
| 108 | + [ | ||
| 109 | + 'id' => $id, | ||
| 110 | + ] | ||
| 111 | + ) | ||
| 112 | + ->one(); | ||
| 113 | + $langs = call_user_func( | ||
| 114 | + [ | ||
| 115 | + $page, | ||
| 116 | + 'getVariationModels', | ||
| 117 | + ] | ||
| 118 | + ); | ||
| 119 | + foreach ($langs as $lang) { | ||
| 120 | + if ($lang->alias !== null) { | ||
| 121 | + $lang->alias->delete(); | ||
| 122 | + } | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + return $page->delete(); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + protected static function fieldsConfig() | ||
| 129 | + { | ||
| 130 | + return [ | ||
| 131 | + 'model' => Label::className(), | ||
| 132 | + 'hasAlias' => false, | ||
| 133 | + 'hasGallery' => false, | ||
| 134 | + 'languageFields' => [ | ||
| 135 | + [ | ||
| 136 | + 'name' => 'title', | ||
| 137 | + 'type' => Form::STRING, | ||
| 138 | + ], | ||
| 139 | + [ | ||
| 140 | + 'name' => 'description', | ||
| 141 | + 'type' => Form::WYSIWYG, | ||
| 142 | + ], | ||
| 143 | + ], | ||
| 144 | + 'fields' => [ | ||
| 145 | + [ | ||
| 146 | + 'name' => 'status', | ||
| 147 | + 'type' => Form::BOOL, | ||
| 148 | + ], | ||
| 149 | + [ | ||
| 150 | + 'name' => 'sort', | ||
| 151 | + 'type' => Form::NUMBER, | ||
| 152 | + ], | ||
| 153 | + [ | ||
| 154 | + 'name' => 'value', | ||
| 155 | + 'type' => Form::NUMBER, | ||
| 156 | + ], | ||
| 157 | + [ | ||
| 158 | + 'name' => 'color', | ||
| 159 | + 'type' => Form::STRING, | ||
| 160 | + ], | ||
| 161 | + [ | ||
| 162 | + 'name' => 'default', | ||
| 163 | + 'type' => Form::BOOL, | ||
| 164 | + ], | ||
| 165 | + | ||
| 166 | + ], | ||
| 167 | + ]; | ||
| 168 | + } | ||
| 169 | + } | ||
| 0 | \ No newline at end of file | 170 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + /** | ||
| 3 | + * Created by PhpStorm. | ||
| 4 | + * User: stes | ||
| 5 | + * Date: 13.04.18 | ||
| 6 | + * Time: 11:24 | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | + namespace artbox\order\labels\controllers; | ||
| 10 | + | ||
| 11 | + use artbox\core\admin\actions\Create; | ||
| 12 | + use artbox\core\admin\actions\Delete; | ||
| 13 | + use artbox\core\admin\actions\Index; | ||
| 14 | + use artbox\core\admin\actions\Update; | ||
| 15 | + use artbox\core\admin\actions\View; | ||
| 16 | + use artbox\core\admin\interfaces\ControllerInterface; | ||
| 17 | + use artbox\core\admin\widgets\Form; | ||
| 18 | + use artbox\order\labels\models\Payment; | ||
| 19 | + use yii\web\Controller; | ||
| 20 | + use yii\web\NotFoundHttpException; | ||
| 21 | + | ||
| 22 | + class PaymentController extends Controller implements ControllerInterface | ||
| 23 | + { | ||
| 24 | + public function actions() | ||
| 25 | + { | ||
| 26 | + return [ | ||
| 27 | + 'index' => [ | ||
| 28 | + 'class' => Index::className(), | ||
| 29 | + 'columns' => [ | ||
| 30 | + 'title' => [ | ||
| 31 | + 'type' => Index::ACTION_COL, | ||
| 32 | + ], | ||
| 33 | + 'sort' => [ | ||
| 34 | + 'type' => Index::POSITION_COL, | ||
| 35 | + ], | ||
| 36 | + 'status' => [ | ||
| 37 | + 'type' => Index::STATUS_COL, | ||
| 38 | + ], | ||
| 39 | + ], | ||
| 40 | + 'model' => Payment::className(), | ||
| 41 | + 'hasLanguage' => true, | ||
| 42 | + 'enableMassDelete' => true, | ||
| 43 | + 'modelPrimaryKey' => 'id', | ||
| 44 | + ], | ||
| 45 | + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), | ||
| 46 | + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), | ||
| 47 | + 'view' => [ | ||
| 48 | + 'class' => View::className(), | ||
| 49 | + 'model' => Payment::className(), | ||
| 50 | + 'hasAlias' => false, | ||
| 51 | + 'hasGallery' => false, | ||
| 52 | + 'languageFields' => [ | ||
| 53 | + [ | ||
| 54 | + 'name' => 'title', | ||
| 55 | + 'type' => Form::STRING, | ||
| 56 | + ], | ||
| 57 | + [ | ||
| 58 | + 'name' => 'description', | ||
| 59 | + 'type' => Form::WYSIWYG, | ||
| 60 | + ], | ||
| 61 | + ], | ||
| 62 | + 'fields' => [ | ||
| 63 | + [ | ||
| 64 | + 'name' => 'status', | ||
| 65 | + 'type' => Form::BOOL, | ||
| 66 | + ], | ||
| 67 | + [ | ||
| 68 | + 'name' => 'sort', | ||
| 69 | + 'type' => Form::NUMBER, | ||
| 70 | + ], | ||
| 71 | + [ | ||
| 72 | + 'name' => 'value', | ||
| 73 | + 'type' => Form::NUMBER, | ||
| 74 | + ], | ||
| 75 | + [ | ||
| 76 | + 'name' => 'color', | ||
| 77 | + 'type' => Form::STRING, | ||
| 78 | + ], | ||
| 79 | + [ | ||
| 80 | + 'name' => 'default', | ||
| 81 | + 'type' => Form::BOOL, | ||
| 82 | + ], | ||
| 83 | + ], | ||
| 84 | + ], | ||
| 85 | + 'delete' => [ | ||
| 86 | + 'class' => Delete::className(), | ||
| 87 | + ], | ||
| 88 | + ]; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public function findModel($id) | ||
| 92 | + { | ||
| 93 | + $model = Payment::find() | ||
| 94 | + ->with('languages') | ||
| 95 | + ->where([ 'id' => $id ]) | ||
| 96 | + ->one(); | ||
| 97 | + if ($model !== null) { | ||
| 98 | + return $model; | ||
| 99 | + } else { | ||
| 100 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public function newModel() | ||
| 105 | + { | ||
| 106 | + return new Payment(); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public function deleteModel($id) | ||
| 110 | + { | ||
| 111 | + $page = Payment::find() | ||
| 112 | + ->with('languages') | ||
| 113 | + ->where( | ||
| 114 | + [ | ||
| 115 | + 'id' => $id, | ||
| 116 | + ] | ||
| 117 | + ) | ||
| 118 | + ->one(); | ||
| 119 | + $langs = call_user_func( | ||
| 120 | + [ | ||
| 121 | + $page, | ||
| 122 | + 'getVariationModels', | ||
| 123 | + ] | ||
| 124 | + ); | ||
| 125 | + foreach ($langs as $lang) { | ||
| 126 | + if ($lang->alias !== null) { | ||
| 127 | + $lang->alias->delete(); | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + return $page->delete(); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + protected static function fieldsConfig() | ||
| 135 | + { | ||
| 136 | + return [ | ||
| 137 | + 'model' => Payment::className(), | ||
| 138 | + 'hasAlias' => false, | ||
| 139 | + 'hasGallery' => false, | ||
| 140 | + 'languageFields' => [ | ||
| 141 | + [ | ||
| 142 | + 'name' => 'title', | ||
| 143 | + 'type' => Form::STRING, | ||
| 144 | + ], | ||
| 145 | + [ | ||
| 146 | + 'name' => 'description', | ||
| 147 | + 'type' => Form::WYSIWYG, | ||
| 148 | + ], | ||
| 149 | + ], | ||
| 150 | + 'fields' => [ | ||
| 151 | + [ | ||
| 152 | + 'name' => 'status', | ||
| 153 | + 'type' => Form::BOOL, | ||
| 154 | + ], | ||
| 155 | + [ | ||
| 156 | + 'name' => 'sort', | ||
| 157 | + 'type' => Form::NUMBER, | ||
| 158 | + ], | ||
| 159 | + [ | ||
| 160 | + 'name' => 'value', | ||
| 161 | + 'type' => Form::NUMBER, | ||
| 162 | + ], | ||
| 163 | + [ | ||
| 164 | + 'name' => 'color', | ||
| 165 | + 'type' => Form::STRING, | ||
| 166 | + ], | ||
| 167 | + [ | ||
| 168 | + 'name' => 'default', | ||
| 169 | + 'type' => Form::BOOL, | ||
| 170 | + ], | ||
| 171 | + | ||
| 172 | + ], | ||
| 173 | + ]; | ||
| 174 | + } | ||
| 175 | + } | ||
| 0 | \ No newline at end of file | 176 | \ No newline at end of file |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace artbox\order\labels\models; | ||
| 4 | + | ||
| 5 | + use artbox\core\behaviors\LanguageBehavior; | ||
| 6 | + use artbox\core\models\Language; | ||
| 7 | + use artbox\order\models\Order; | ||
| 8 | + use Yii; | ||
| 9 | + use yii\db\ActiveQuery; | ||
| 10 | + use yii\db\ActiveRecord; | ||
| 11 | + use yii2tech\ar\position\PositionBehavior; | ||
| 12 | + use yii2tech\ar\variation\VariationBehavior; | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * This is the model class for table "delivery". | ||
| 16 | + * | ||
| 17 | + * @property integer $id | ||
| 18 | + * @property integer $sort | ||
| 19 | + * @property float $value | ||
| 20 | + * @property boolean $status | ||
| 21 | + * @property boolean $default | ||
| 22 | + * @property DeliveryLang[] $deliveryLangs | ||
| 23 | + * @property Language[] $languages | ||
| 24 | + * @property \artbox\order\models\Order[] $orders | ||
| 25 | + * @see LanguageBehavior | ||
| 26 | + */ | ||
| 27 | + class Delivery extends ActiveRecord | ||
| 28 | + { | ||
| 29 | + /** | ||
| 30 | + * @inheritdoc | ||
| 31 | + */ | ||
| 32 | + public static function tableName() | ||
| 33 | + { | ||
| 34 | + return 'delivery'; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * @inheritdoc | ||
| 39 | + */ | ||
| 40 | + public function behaviors() | ||
| 41 | + { | ||
| 42 | + return [ | ||
| 43 | + 'translations' => [ | ||
| 44 | + 'class' => VariationBehavior::className(), | ||
| 45 | + 'variationsRelation' => 'languages', | ||
| 46 | + 'defaultVariationRelation' => 'language', | ||
| 47 | + 'variationOptionReferenceAttribute' => 'language_id', | ||
| 48 | + 'optionModelClass' => Language::className(), | ||
| 49 | + 'defaultVariationOptionReference' => function () { | ||
| 50 | + return Language::getCurrent()->id; | ||
| 51 | + }, | ||
| 52 | + 'optionQueryFilter' => function (ActiveQuery $query) { | ||
| 53 | + $query->where( | ||
| 54 | + [ | ||
| 55 | + 'status' => true, | ||
| 56 | + ] | ||
| 57 | + ); | ||
| 58 | + }, | ||
| 59 | + ], | ||
| 60 | + 'positionBehavior' => [ | ||
| 61 | + 'class' => PositionBehavior::className(), | ||
| 62 | + 'positionAttribute' => 'sort', | ||
| 63 | + ], | ||
| 64 | + ]; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * @inheritdoc | ||
| 69 | + */ | ||
| 70 | + public function rules() | ||
| 71 | + { | ||
| 72 | + return [ | ||
| 73 | + [ | ||
| 74 | + [ 'sort' ], | ||
| 75 | + 'integer', | ||
| 76 | + ], | ||
| 77 | + [ | ||
| 78 | + [ 'value' ], | ||
| 79 | + 'number', | ||
| 80 | + ], | ||
| 81 | + [ | ||
| 82 | + [ 'status' ], | ||
| 83 | + 'boolean', | ||
| 84 | + ], | ||
| 85 | + [ | ||
| 86 | + [ 'default' ], | ||
| 87 | + 'boolean', | ||
| 88 | + ], | ||
| 89 | + ]; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * @inheritdoc | ||
| 94 | + */ | ||
| 95 | + public function attributeLabels() | ||
| 96 | + { | ||
| 97 | + return [ | ||
| 98 | + 'id' => Yii::t('order', 'ID'), | ||
| 99 | + 'sort' => Yii::t('order', 'Sort'), | ||
| 100 | + 'value' => Yii::t('order', 'Value'), | ||
| 101 | + 'status' => Yii::t('order', 'Status'), | ||
| 102 | + 'default' => Yii::t('order', 'Default'), | ||
| 103 | + ]; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public function getLanguages() | ||
| 107 | + { | ||
| 108 | + return $this->hasMany(DeliveryLang::className(), [ 'delivery_id' => 'id' ]); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * @return \yii\db\ActiveQuery | ||
| 113 | + */ | ||
| 114 | + public function getLanguage() | ||
| 115 | + { | ||
| 116 | + return $this->hasOne(DeliveryLang::className(), [ 'delivery_id' => 'id' ]); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * @return \yii\db\ActiveQuery | ||
| 121 | + */ | ||
| 122 | + public function getOrders() | ||
| 123 | + { | ||
| 124 | + return $this->hasMany(Order::className(), [ 'delivery_id' => 'id' ]); | ||
| 125 | + } | ||
| 126 | + } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace artbox\order\labels\models; | ||
| 4 | + | ||
| 5 | + use artbox\core\models\Language; | ||
| 6 | + use Yii; | ||
| 7 | + use yii\db\ActiveRecord; | ||
| 8 | + | ||
| 9 | + /** | ||
| 10 | + * This is the model class for table "delivery_lang". | ||
| 11 | + * | ||
| 12 | + * @property integer $delivery_id | ||
| 13 | + * @property integer $language_id | ||
| 14 | + * @property string $title | ||
| 15 | + * @property string $description | ||
| 16 | + * @property Delivery $delivery | ||
| 17 | + * @property Language $language | ||
| 18 | + */ | ||
| 19 | + class DeliveryLang extends ActiveRecord | ||
| 20 | + { | ||
| 21 | + /** | ||
| 22 | + * @inheritdoc | ||
| 23 | + */ | ||
| 24 | + public static function tableName() | ||
| 25 | + { | ||
| 26 | + return 'delivery_lang'; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * @inheritdoc | ||
| 31 | + */ | ||
| 32 | + public function rules() | ||
| 33 | + { | ||
| 34 | + return [ | ||
| 35 | + [ | ||
| 36 | + [ | ||
| 37 | + 'title', | ||
| 38 | + ], | ||
| 39 | + 'required', | ||
| 40 | + ], | ||
| 41 | + [ | ||
| 42 | + [ | ||
| 43 | + 'delivery_id', | ||
| 44 | + 'language_id', | ||
| 45 | + ], | ||
| 46 | + 'integer', | ||
| 47 | + ], | ||
| 48 | + [ | ||
| 49 | + [ 'description' ], | ||
| 50 | + 'string', | ||
| 51 | + ], | ||
| 52 | + [ | ||
| 53 | + [ 'title' ], | ||
| 54 | + 'string', | ||
| 55 | + 'max' => 255, | ||
| 56 | + ], | ||
| 57 | + [ | ||
| 58 | + [ 'delivery_id' ], | ||
| 59 | + 'exist', | ||
| 60 | + 'skipOnError' => true, | ||
| 61 | + 'targetClass' => Delivery::className(), | ||
| 62 | + 'targetAttribute' => [ 'delivery_id' => 'id' ], | ||
| 63 | + ], | ||
| 64 | + [ | ||
| 65 | + [ 'language_id' ], | ||
| 66 | + 'exist', | ||
| 67 | + 'skipOnError' => true, | ||
| 68 | + 'targetClass' => Language::className(), | ||
| 69 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
| 70 | + ], | ||
| 71 | + ]; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * @inheritdoc | ||
| 76 | + */ | ||
| 77 | + public function attributeLabels() | ||
| 78 | + { | ||
| 79 | + return [ | ||
| 80 | + 'delivery_id' => Yii::t('order', 'Delivery ID'), | ||
| 81 | + 'language_id' => Yii::t('order', 'Language ID'), | ||
| 82 | + 'title' => Yii::t('order', 'Title'), | ||
| 83 | + 'description' => Yii::t('order', 'Description'), | ||
| 84 | + ]; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * @return \yii\db\ActiveQuery | ||
| 89 | + */ | ||
| 90 | + public function getDelivery() | ||
| 91 | + { | ||
| 92 | + return $this->hasOne(Delivery::className(), [ 'id' => 'delivery_id' ]); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace artbox\order\labels\models; | ||
| 4 | + | ||
| 5 | + use artbox\core\behaviors\LanguageBehavior; | ||
| 6 | + use artbox\core\models\Language; | ||
| 7 | + use artbox\order\models\Order; | ||
| 8 | + use Yii; | ||
| 9 | + use yii\db\ActiveQuery; | ||
| 10 | + use yii\db\ActiveRecord; | ||
| 11 | + use yii2tech\ar\position\PositionBehavior; | ||
| 12 | + use yii2tech\ar\variation\VariationBehavior; | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * This is the model class for table "label". | ||
| 16 | + * | ||
| 17 | + * @property integer $id | ||
| 18 | + * @property integer $sort | ||
| 19 | + * @property string $value | ||
| 20 | + * @property boolean $status | ||
| 21 | + * @property string $color | ||
| 22 | + * @property boolean $default | ||
| 23 | + * @property LabelLang[] $labelLangs | ||
| 24 | + * @property Language[] $languages | ||
| 25 | + * @property \artbox\order\models\Order[] $orders | ||
| 26 | + * @see LanguageBehavior | ||
| 27 | + */ | ||
| 28 | + class Label extends ActiveRecord | ||
| 29 | + { | ||
| 30 | + /** | ||
| 31 | + * @inheritdoc | ||
| 32 | + */ | ||
| 33 | + public static function tableName() | ||
| 34 | + { | ||
| 35 | + return 'label'; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * @inheritdoc | ||
| 40 | + */ | ||
| 41 | + public function behaviors() | ||
| 42 | + { | ||
| 43 | + return [ | ||
| 44 | + 'translations' => [ | ||
| 45 | + 'class' => VariationBehavior::className(), | ||
| 46 | + 'variationsRelation' => 'languages', | ||
| 47 | + 'defaultVariationRelation' => 'language', | ||
| 48 | + 'variationOptionReferenceAttribute' => 'language_id', | ||
| 49 | + 'optionModelClass' => Language::className(), | ||
| 50 | + 'defaultVariationOptionReference' => function () { | ||
| 51 | + return Language::getCurrent()->id; | ||
| 52 | + }, | ||
| 53 | + 'optionQueryFilter' => function (ActiveQuery $query) { | ||
| 54 | + $query->where( | ||
| 55 | + [ | ||
| 56 | + 'status' => true, | ||
| 57 | + ] | ||
| 58 | + ); | ||
| 59 | + }, | ||
| 60 | + ], | ||
| 61 | + 'positionBehavior' => [ | ||
| 62 | + 'class' => PositionBehavior::className(), | ||
| 63 | + 'positionAttribute' => 'sort', | ||
| 64 | + ], | ||
| 65 | + ]; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * @inheritdoc | ||
| 70 | + */ | ||
| 71 | + public function rules() | ||
| 72 | + { | ||
| 73 | + return [ | ||
| 74 | + [ | ||
| 75 | + [ 'sort' ], | ||
| 76 | + 'integer', | ||
| 77 | + ], | ||
| 78 | + [ | ||
| 79 | + [ 'color' ], | ||
| 80 | + 'string', | ||
| 81 | + ], | ||
| 82 | + [ | ||
| 83 | + [ 'value' ], | ||
| 84 | + 'number', | ||
| 85 | + ], | ||
| 86 | + [ | ||
| 87 | + [ 'status' ], | ||
| 88 | + 'boolean', | ||
| 89 | + ], | ||
| 90 | + [ | ||
| 91 | + [ 'default' ], | ||
| 92 | + 'boolean', | ||
| 93 | + ], | ||
| 94 | + ]; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * @inheritdoc | ||
| 99 | + */ | ||
| 100 | + public function attributeLabels() | ||
| 101 | + { | ||
| 102 | + return [ | ||
| 103 | + 'id' => Yii::t('order', 'ID'), | ||
| 104 | + 'sort' => Yii::t('order', 'Sort'), | ||
| 105 | + 'value' => Yii::t('order', 'Value'), | ||
| 106 | + 'status' => Yii::t('order', 'Status'), | ||
| 107 | + 'color' => Yii::t('order', 'Color'), | ||
| 108 | + 'default' => Yii::t('order', 'Default'), | ||
| 109 | + ]; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public function getLanguages() | ||
| 113 | + { | ||
| 114 | + return $this->hasMany(LabelLang::className(), [ 'label_id' => 'id' ]); | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * @return \yii\db\ActiveQuery | ||
| 119 | + */ | ||
| 120 | + public function getLanguage() | ||
| 121 | + { | ||
| 122 | + return $this->hasOne(LabelLang::className(), [ 'label_id' => 'id' ]); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + /** | ||
| 126 | + * @return \yii\db\ActiveQuery | ||
| 127 | + */ | ||
| 128 | + public function getOrders() | ||
| 129 | + { | ||
| 130 | + return $this->hasMany(Order::className(), [ 'label_id' => 'id' ]); | ||
| 131 | + } | ||
| 132 | + } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace artbox\order\labels\models; | ||
| 4 | + | ||
| 5 | + use artbox\core\models\Language; | ||
| 6 | + use Yii; | ||
| 7 | + use yii\db\ActiveRecord; | ||
| 8 | + | ||
| 9 | + /** | ||
| 10 | + * This is the model class for table "label_lang". | ||
| 11 | + * | ||
| 12 | + * @property integer $label_id | ||
| 13 | + * @property integer $language_id | ||
| 14 | + * @property string $title | ||
| 15 | + * @property string $description | ||
| 16 | + * @property Label $label | ||
| 17 | + * @property Language $language | ||
| 18 | + */ | ||
| 19 | + class LabelLang extends ActiveRecord | ||
| 20 | + { | ||
| 21 | + /** | ||
| 22 | + * @inheritdoc | ||
| 23 | + */ | ||
| 24 | + public static function tableName() | ||
| 25 | + { | ||
| 26 | + return 'label_lang'; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * @inheritdoc | ||
| 31 | + */ | ||
| 32 | + public function rules() | ||
| 33 | + { | ||
| 34 | + return [ | ||
| 35 | + [ | ||
| 36 | + [ | ||
| 37 | + 'title', | ||
| 38 | + ], | ||
| 39 | + 'required', | ||
| 40 | + ], | ||
| 41 | + [ | ||
| 42 | + [ | ||
| 43 | + 'label_id', | ||
| 44 | + 'language_id', | ||
| 45 | + ], | ||
| 46 | + 'integer', | ||
| 47 | + ], | ||
| 48 | + [ | ||
| 49 | + [ 'description' ], | ||
| 50 | + 'string', | ||
| 51 | + ], | ||
| 52 | + [ | ||
| 53 | + [ 'title' ], | ||
| 54 | + 'string', | ||
| 55 | + 'max' => 255, | ||
| 56 | + ], | ||
| 57 | + [ | ||
| 58 | + [ 'label_id' ], | ||
| 59 | + 'exist', | ||
| 60 | + 'skipOnError' => true, | ||
| 61 | + 'targetClass' => Label::className(), | ||
| 62 | + 'targetAttribute' => [ 'label_id' => 'id' ], | ||
| 63 | + ], | ||
| 64 | + [ | ||
| 65 | + [ 'language_id' ], | ||
| 66 | + 'exist', | ||
| 67 | + 'skipOnError' => true, | ||
| 68 | + 'targetClass' => Language::className(), | ||
| 69 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
| 70 | + ], | ||
| 71 | + ]; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * @inheritdoc | ||
| 76 | + */ | ||
| 77 | + public function attributeLabels() | ||
| 78 | + { | ||
| 79 | + return [ | ||
| 80 | + 'label_id' => Yii::t('order', 'Label ID'), | ||
| 81 | + 'language_id' => Yii::t('order', 'Language ID'), | ||
| 82 | + 'title' => Yii::t('order', 'Title'), | ||
| 83 | + 'description' => Yii::t('order', 'Description'), | ||
| 84 | + ]; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * @return \yii\db\ActiveQuery | ||
| 89 | + */ | ||
| 90 | + public function getLabel() | ||
| 91 | + { | ||
| 92 | + return $this->hasOne(Label::className(), [ 'id' => 'label_id' ]); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * @return \yii\db\ActiveQuery | ||
| 97 | + */ | ||
| 98 | + public function getLanguage() | ||
| 99 | + { | ||
| 100 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | ||
| 101 | + } | ||
| 102 | + } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace artbox\order\labels\models; | ||
| 4 | + | ||
| 5 | + use artbox\core\behaviors\LanguageBehavior; | ||
| 6 | + use artbox\core\models\Language; | ||
| 7 | + use artbox\order\models\Order; | ||
| 8 | + use Yii; | ||
| 9 | + use yii\db\ActiveQuery; | ||
| 10 | + use yii\db\ActiveRecord; | ||
| 11 | + use yii2tech\ar\position\PositionBehavior; | ||
| 12 | + use yii2tech\ar\variation\VariationBehavior; | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * This is the model class for table "payment". | ||
| 16 | + * | ||
| 17 | + * @property integer $id | ||
| 18 | + * @property integer $sort | ||
| 19 | + * @property boolean $status | ||
| 20 | + * @property boolean $default | ||
| 21 | + * @property \artbox\order\models\Order[] $orders | ||
| 22 | + * @property PaymentLang[] $paymentLangs | ||
| 23 | + * @property Language[] $languages | ||
| 24 | + * @see LanguageBehavior | ||
| 25 | + */ | ||
| 26 | + class Payment extends ActiveRecord | ||
| 27 | + { | ||
| 28 | + /** | ||
| 29 | + * @inheritdoc | ||
| 30 | + */ | ||
| 31 | + public static function tableName() | ||
| 32 | + { | ||
| 33 | + return 'payment'; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * @inheritdoc | ||
| 38 | + */ | ||
| 39 | + public function behaviors() | ||
| 40 | + { | ||
| 41 | + return [ | ||
| 42 | + 'translations' => [ | ||
| 43 | + 'class' => VariationBehavior::className(), | ||
| 44 | + 'variationsRelation' => 'languages', | ||
| 45 | + 'defaultVariationRelation' => 'language', | ||
| 46 | + 'variationOptionReferenceAttribute' => 'language_id', | ||
| 47 | + 'optionModelClass' => Language::className(), | ||
| 48 | + 'defaultVariationOptionReference' => function () { | ||
| 49 | + return Language::getCurrent()->id; | ||
| 50 | + }, | ||
| 51 | + 'optionQueryFilter' => function (ActiveQuery $query) { | ||
| 52 | + $query->where( | ||
| 53 | + [ | ||
| 54 | + 'status' => true, | ||
| 55 | + ] | ||
| 56 | + ); | ||
| 57 | + }, | ||
| 58 | + ], | ||
| 59 | + 'positionBehavior' => [ | ||
| 60 | + 'class' => PositionBehavior::className(), | ||
| 61 | + 'positionAttribute' => 'sort', | ||
| 62 | + ], | ||
| 63 | + ]; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * @inheritdoc | ||
| 68 | + */ | ||
| 69 | + public function rules() | ||
| 70 | + { | ||
| 71 | + return [ | ||
| 72 | + [ | ||
| 73 | + [ 'sort' ], | ||
| 74 | + 'integer', | ||
| 75 | + ], | ||
| 76 | + [ | ||
| 77 | + [ 'status' ], | ||
| 78 | + 'boolean', | ||
| 79 | + ], | ||
| 80 | + [ | ||
| 81 | + [ 'default' ], | ||
| 82 | + 'boolean', | ||
| 83 | + ], | ||
| 84 | + ]; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * @inheritdoc | ||
| 89 | + */ | ||
| 90 | + public function attributeLabels() | ||
| 91 | + { | ||
| 92 | + return [ | ||
| 93 | + 'id' => Yii::t('order', 'ID'), | ||
| 94 | + 'sort' => Yii::t('order', 'Sort'), | ||
| 95 | + 'status' => Yii::t('order', 'Status'), | ||
| 96 | + 'default' => Yii::t('order', 'Default'), | ||
| 97 | + ]; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public function getLanguages() | ||
| 101 | + { | ||
| 102 | + return $this->hasMany(PaymentLang::className(), [ 'payment_id' => 'id' ]); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * @return \yii\db\ActiveQuery | ||
| 107 | + */ | ||
| 108 | + public function getLanguage() | ||
| 109 | + { | ||
| 110 | + return $this->hasOne(PaymentLang::className(), [ 'payment_id' => 'id' ]); | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * @return \yii\db\ActiveQuery | ||
| 115 | + */ | ||
| 116 | + public function getOrders() | ||
| 117 | + { | ||
| 118 | + return $this->hasMany(Order::className(), [ 'payment_id' => 'id' ]); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | + namespace artbox\order\labels\models; | ||
| 4 | + | ||
| 5 | + use artbox\core\models\Language; | ||
| 6 | + use Yii; | ||
| 7 | + use yii\db\ActiveRecord; | ||
| 8 | + | ||
| 9 | + /** | ||
| 10 | + * This is the model class for table "payment_lang". | ||
| 11 | + * | ||
| 12 | + * @property integer $payment_id | ||
| 13 | + * @property integer $language_id | ||
| 14 | + * @property string $title | ||
| 15 | + * @property string $description | ||
| 16 | + * @property Language $language | ||
| 17 | + * @property Payment $payment | ||
| 18 | + */ | ||
| 19 | + class PaymentLang extends ActiveRecord | ||
| 20 | + { | ||
| 21 | + /** | ||
| 22 | + * @inheritdoc | ||
| 23 | + */ | ||
| 24 | + public static function tableName() | ||
| 25 | + { | ||
| 26 | + return 'payment_lang'; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * @inheritdoc | ||
| 31 | + */ | ||
| 32 | + public function rules() | ||
| 33 | + { | ||
| 34 | + return [ | ||
| 35 | + [ | ||
| 36 | + [ | ||
| 37 | + 'title', | ||
| 38 | + ], | ||
| 39 | + 'required', | ||
| 40 | + ], | ||
| 41 | + [ | ||
| 42 | + [ | ||
| 43 | + 'payment_id', | ||
| 44 | + 'language_id', | ||
| 45 | + ], | ||
| 46 | + 'integer', | ||
| 47 | + ], | ||
| 48 | + [ | ||
| 49 | + [ 'description' ], | ||
| 50 | + 'string', | ||
| 51 | + ], | ||
| 52 | + [ | ||
| 53 | + [ 'title' ], | ||
| 54 | + 'string', | ||
| 55 | + 'max' => 255, | ||
| 56 | + ], | ||
| 57 | + [ | ||
| 58 | + [ 'language_id' ], | ||
| 59 | + 'exist', | ||
| 60 | + 'skipOnError' => true, | ||
| 61 | + 'targetClass' => Language::className(), | ||
| 62 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
| 63 | + ], | ||
| 64 | + [ | ||
| 65 | + [ 'payment_id' ], | ||
| 66 | + 'exist', | ||
| 67 | + 'skipOnError' => true, | ||
| 68 | + 'targetClass' => Payment::className(), | ||
| 69 | + 'targetAttribute' => [ 'payment_id' => 'id' ], | ||
| 70 | + ], | ||
| 71 | + ]; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * @inheritdoc | ||
| 76 | + */ | ||
| 77 | + public function attributeLabels() | ||
| 78 | + { | ||
| 79 | + return [ | ||
| 80 | + 'payment_id' => Yii::t('order', 'Payment ID'), | ||
| 81 | + 'language_id' => Yii::t('order', 'Language ID'), | ||
| 82 | + 'title' => Yii::t('order', 'Title'), | ||
| 83 | + 'description' => Yii::t('order', 'Description'), | ||
| 84 | + ]; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * @return \yii\db\ActiveQuery | ||
| 89 | + */ | ||
| 90 | + public function getPayment() | ||
| 91 | + { | ||
| 92 | + return $this->hasOne(Payment::className(), [ 'id' => 'payment_id' ]); | ||
| 93 | + } | ||
| 94 | + } |
models/Order.php
| @@ -5,6 +5,9 @@ | @@ -5,6 +5,9 @@ | ||
| 5 | use Yii; | 5 | use Yii; |
| 6 | use yii\behaviors\TimestampBehavior; | 6 | use yii\behaviors\TimestampBehavior; |
| 7 | use yii\db\ActiveRecord; | 7 | use yii\db\ActiveRecord; |
| 8 | + use artbox\order\labels\models\Label; | ||
| 9 | + use artbox\order\labels\models\Payment; | ||
| 10 | + use artbox\order\labels\models\Delivery; | ||
| 8 | 11 | ||
| 9 | /** | 12 | /** |
| 10 | * This is the model class for table "order". | 13 | * This is the model class for table "order". |