Commit 96410438711eb1ff5fa9f2890e0d82ab9fe40cc7
1 parent
a04c0e15
Project admin complete
Showing
18 changed files
with
599 additions
and
236 deletions
Show diff stats
backend/controllers/ProjectController.php
| ... | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | use common\modules\product\models\Product; |
| 11 | 11 | use common\modules\product\models\ProductVariant; |
| 12 | 12 | use Yii; |
| 13 | + use yii\helpers\ArrayHelper; | |
| 13 | 14 | use yii\web\Controller; |
| 14 | 15 | use yii\web\NotFoundHttpException; |
| 15 | 16 | use yii\filters\VerbFilter; |
| ... | ... | @@ -203,10 +204,11 @@ |
| 203 | 204 | $products = Product::find() |
| 204 | 205 | ->distinct() |
| 205 | 206 | ->select([ |
| 206 | - 'product.product_id', | |
| 207 | + 'product_lang.name', | |
| 207 | 208 | 'product.product_id', |
| 208 | 209 | ]) |
| 209 | 210 | ->joinWith('variants', true, 'INNER JOIN') |
| 211 | + ->joinWith('lang', true, 'INNER JOIN') | |
| 210 | 212 | ->indexBy('product_id') |
| 211 | 213 | ->asArray() |
| 212 | 214 | ->column(); |
| ... | ... | @@ -222,9 +224,11 @@ |
| 222 | 224 | if(!empty( $model->product_id ) && !empty( $products[ $model->product_id ] )) { |
| 223 | 225 | $variants = ProductVariant::find() |
| 224 | 226 | ->select([ |
| 225 | - 'product_variant_id', | |
| 227 | + 'product_variant_lang.name', | |
| 228 | + 'product_variant.product_variant_id', | |
| 226 | 229 | ]) |
| 227 | - ->where([ 'product_id' => $model->product_id ]) | |
| 230 | + ->joinWith('lang', true, 'INNER JOIN') | |
| 231 | + ->where([ 'product_variant.product_id' => $model->product_id ]) | |
| 228 | 232 | ->asArray() |
| 229 | 233 | ->indexBy('product_variant_id') |
| 230 | 234 | ->column(); |
| ... | ... | @@ -261,10 +265,11 @@ |
| 261 | 265 | } |
| 262 | 266 | $products = Product::find() |
| 263 | 267 | ->select([ |
| 264 | - 'product.product_id', | |
| 268 | + 'product_lang.name', | |
| 265 | 269 | 'product.product_id', |
| 266 | 270 | ]) |
| 267 | 271 | ->joinWith('variants', true, 'INNER JOIN') |
| 272 | + ->joinWith('lang', true, 'INNER JOIN') | |
| 268 | 273 | ->indexBy('product_id') |
| 269 | 274 | ->asArray() |
| 270 | 275 | ->column(); |
| ... | ... | @@ -272,9 +277,11 @@ |
| 272 | 277 | if(!empty( $model->product_id ) && !empty( $products[ $model->product_id ] )) { |
| 273 | 278 | $variants = ProductVariant::find() |
| 274 | 279 | ->select([ |
| 275 | - 'product_variant_id', | |
| 280 | + 'product_variant_lang.name', | |
| 281 | + 'product_variant.product_variant_id', | |
| 276 | 282 | ]) |
| 277 | - ->where([ 'product_id' => $model->product_id ]) | |
| 283 | + ->joinWith('lang', true, 'INNER JOIN') | |
| 284 | + ->where([ 'product_variant.product_id' => $model->product_id ]) | |
| 278 | 285 | ->asArray() |
| 279 | 286 | ->indexBy('product_variant_id') |
| 280 | 287 | ->column(); |
| ... | ... | @@ -308,13 +315,19 @@ |
| 308 | 315 | $response = \Yii::$app->response; |
| 309 | 316 | $response->format = $response::FORMAT_JSON; |
| 310 | 317 | $product = Product::find() |
| 311 | - ->with('variants') | |
| 312 | - ->where([ 'product_id' => $product_id ]) | |
| 318 | + ->joinWith('variants.lang', true, 'INNER JOIN') | |
| 319 | + ->where([ 'product.product_id' => $product_id ]) | |
| 313 | 320 | ->one(); |
| 314 | 321 | if(empty( $product ) || empty( $product->variants )) { |
| 315 | 322 | throw new NotFoundHttpException(); |
| 316 | 323 | } |
| 317 | - return $product->variants; | |
| 324 | + $variants = ArrayHelper::toArray($product->variants, [ | |
| 325 | + 'common\modules\product\models\ProductVariant' => [ | |
| 326 | + 'product_variant_id', | |
| 327 | + 'lang', | |
| 328 | + ], | |
| 329 | + ]); | |
| 330 | + return $variants; | |
| 318 | 331 | } |
| 319 | 332 | |
| 320 | 333 | /** | ... | ... |
backend/views/project/index.php
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -use yii\helpers\Html; | |
| 4 | -use yii\grid\GridView; | |
| 5 | - | |
| 6 | -/* @var $this yii\web\View */ | |
| 7 | -/* @var $searchModel common\models\ArticlesSearch */ | |
| 8 | -/* @var $dataProvider yii\data\ActiveDataProvider */ | |
| 9 | - | |
| 10 | -$this->title = \Yii::t('app', 'Project'); | |
| 11 | -$this->params['breadcrumbs'][] = $this->title; | |
| 2 | + | |
| 3 | + use yii\helpers\Html; | |
| 4 | + use yii\grid\GridView; | |
| 5 | + | |
| 6 | + /** | |
| 7 | + * @var yii\web\View $this | |
| 8 | + * @var common\models\ArticlesSearch $searchModel | |
| 9 | + * @var yii\data\ActiveDataProvider $dataProvider | |
| 10 | + */ | |
| 11 | + $this->title = \Yii::t('app', 'Project'); | |
| 12 | + $this->params[ 'breadcrumbs' ][] = $this->title; | |
| 12 | 13 | ?> |
| 13 | 14 | <div class="articles-index"> |
| 14 | - | |
| 15 | + | |
| 15 | 16 | <h1><?= Html::encode($this->title) ?></h1> |
| 16 | - | |
| 17 | + | |
| 17 | 18 | <p> |
| 18 | - <?= Html::a(\Yii::t('app', 'Create Project'), ['create'], ['class' => 'btn btn-success']) ?> | |
| 19 | + <?= Html::a(\Yii::t('app', 'Create Project'), [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> | |
| 19 | 20 | </p> |
| 20 | 21 | <?= GridView::widget([ |
| 21 | 22 | 'dataProvider' => $dataProvider, |
| 22 | - 'filterModel' => $searchModel, | |
| 23 | - 'columns' => [ | |
| 24 | - ['class' => 'yii\grid\SerialColumn'], | |
| 23 | + 'filterModel' => $searchModel, | |
| 24 | + 'columns' => [ | |
| 25 | 25 | 'project_id', |
| 26 | 26 | 'date_add:date', |
| 27 | 27 | [ |
| 28 | - 'class' => 'yii\grid\ActionColumn', | |
| 29 | - 'buttons' => [ | |
| 28 | + 'attribute' => 'title', | |
| 29 | + 'value' => 'lang.title', | |
| 30 | + ], | |
| 31 | + 'image.imageUrl:image', | |
| 32 | + [ | |
| 33 | + 'class' => 'yii\grid\ActionColumn', | |
| 34 | + 'buttons' => [ | |
| 30 | 35 | 'product' => function($url, $model) { |
| 31 | - return Html::a(Html::tag('span', '', ['class' => 'glyphicon glyphicon-list']), $url); | |
| 32 | - } | |
| 36 | + return Html::a(Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-list' ]), $url); | |
| 37 | + }, | |
| 33 | 38 | ], |
| 34 | 39 | 'template' => '{product} {view} {update} {delete}', |
| 35 | 40 | ], | ... | ... |
backend/views/project/product-create.php
| ... | ... | @@ -14,9 +14,19 @@ |
| 14 | 14 | * @var ProductToProject $model |
| 15 | 15 | * @var array $variants |
| 16 | 16 | */ |
| 17 | - $this->title = \Yii::t('app', 'Create product to project'); | |
| 17 | + if($model->isNewRecord) { | |
| 18 | + $this->title = \Yii::t('app', 'Create product to project'); | |
| 19 | + } else { | |
| 20 | + $this->title = \Yii::t('app', 'Update product to project'); | |
| 21 | + } | |
| 18 | 22 | $this->params[ 'breadcrumbs' ][] = [ |
| 19 | - 'label' => \Yii::t('app', 'Products to project'), | |
| 23 | + 'label' => \Yii::t('app', 'Project'), | |
| 24 | + 'url' => [ | |
| 25 | + 'index', | |
| 26 | + ], | |
| 27 | + ]; | |
| 28 | + $this->params[ 'breadcrumbs' ][] = [ | |
| 29 | + 'label' => \Yii::t('app', 'Products to project' . ': ' . $project->lang->title), | |
| 20 | 30 | 'url' => [ |
| 21 | 31 | 'product', |
| 22 | 32 | 'id' => $project->project_id, |
| ... | ... | @@ -24,26 +34,26 @@ |
| 24 | 34 | ]; |
| 25 | 35 | $this->params[ 'breadcrumbs' ][] = $this->title; |
| 26 | 36 | ?> |
| 27 | -<div class="articles-create"> | |
| 28 | - <h1><?= Html::encode($this->title) ?></h1> | |
| 29 | - <?php | |
| 30 | - $form = ActiveForm::begin(); | |
| 31 | - echo $form->field($model, 'product_id') | |
| 32 | - ->dropDownList($products, [ 'prompt' => \Yii::t('app', 'Выберите коллекцию')]); | |
| 33 | - ?> | |
| 34 | - <div class="<?php echo( !empty( $variants ) ? '' : 'hidden' ); ?> product_variant_container"> | |
| 37 | + <div class="articles-create"> | |
| 38 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 39 | + <?php | |
| 40 | + $form = ActiveForm::begin(); | |
| 41 | + echo $form->field($model, 'product_id') | |
| 42 | + ->dropDownList($products, [ 'prompt' => \Yii::t('app', 'Выберите коллекцию') ]); | |
| 43 | + ?> | |
| 44 | + <div class="<?php echo( !empty( $variants ) ? '' : 'hidden' ); ?> product_variant_container"> | |
| 45 | + <?php | |
| 46 | + echo $form->field($model, 'product_variant_id') | |
| 47 | + ->dropDownList($variants, [ 'prompt' => \Yii::t('app', 'Выберите товар') ]); | |
| 48 | + ?> | |
| 49 | + </div> | |
| 35 | 50 | <?php |
| 36 | - echo $form->field($model, 'product_variant_id') | |
| 37 | - ->dropDownList($variants, [ 'prompt' => \Yii::t('app', 'Выберите товар')]); | |
| 51 | + echo Html::submitInput(( $model->isNewRecord ? \Yii::t('app', 'Добавить') : \Yii::t('app', 'Обновить') ), [ 'class' => 'btn btn-success' ]); | |
| 52 | + $form::end(); | |
| 38 | 53 | ?> |
| 39 | 54 | </div> |
| 40 | - <?php | |
| 41 | - echo Html::submitInput(($model->isNewRecord?\Yii::t('app', 'Добавить'):\Yii::t('app', 'Обновить')), [ 'class' => 'btn btn-success' ]); | |
| 42 | - $form::end(); | |
| 43 | - ?> | |
| 44 | -</div> | |
| 45 | 55 | <?php |
| 46 | -$this->registerJs(" | |
| 56 | + $this->registerJs(" | |
| 47 | 57 | $(document).on( |
| 48 | 58 | 'change', '#producttoproject-product_id', function(e) |
| 49 | 59 | { |
| ... | ... | @@ -62,11 +72,11 @@ $this->registerJs(" |
| 62 | 72 | $.each( |
| 63 | 73 | data, function(key, value) |
| 64 | 74 | { |
| 75 | + | |
| 65 | 76 | $(dropDown) |
| 66 | - .append('<option value=\"' + value.product_variant_id + '\">' + value.product_variant_id + '</option>'); | |
| 77 | + .append('<option value=\"' + value.product_variant_id + '\">' + value.lang.name + '</option>'); | |
| 67 | 78 | } |
| 68 | 79 | ); |
| 69 | - console.log('hiodde'); | |
| 70 | 80 | $(container).removeClass('hidden'); |
| 71 | 81 | } |
| 72 | 82 | } | ... | ... |
backend/views/project/product.php
| ... | ... | @@ -16,7 +16,11 @@ |
| 16 | 16 | * @var Project $project |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | - $this->title = \Yii::t('app', 'Product to project'); | |
| 19 | + $this->title = \Yii::t('app', 'Product to project: ') . $project->lang->title; | |
| 20 | + $this->params[ 'breadcrumbs' ][] = [ | |
| 21 | + 'label' => \Yii::t('app', 'Project'), | |
| 22 | + 'url' => [ 'index' ], | |
| 23 | + ]; | |
| 20 | 24 | $this->params[ 'breadcrumbs' ][] = $this->title; |
| 21 | 25 | ?> |
| 22 | 26 | <div class="articles-index"> |
| ... | ... | @@ -33,9 +37,32 @@ |
| 33 | 37 | 'dataProvider' => $dataProvider, |
| 34 | 38 | 'filterModel' => $searchModel, |
| 35 | 39 | 'columns' => [ |
| 36 | - [ 'class' => 'yii\grid\SerialColumn' ], | |
| 37 | - 'product_variant_id', | |
| 38 | - 'project_id', | |
| 40 | + [ | |
| 41 | + 'attribute' => 'variant_name', | |
| 42 | + 'value' => function($model) { | |
| 43 | + /** | |
| 44 | + * @var ProductToProject $model | |
| 45 | + */ | |
| 46 | + return Html::a($model->productVariant->lang->name, [ | |
| 47 | + 'product/variant/view', | |
| 48 | + 'id' => $model->productVariant->product_variant_id, | |
| 49 | + ]); | |
| 50 | + }, | |
| 51 | + 'format' => 'html', | |
| 52 | + ], | |
| 53 | + [ | |
| 54 | + 'attribute' => 'product_name', | |
| 55 | + 'value' => function($model) { | |
| 56 | + /** | |
| 57 | + * @var ProductToProject $model | |
| 58 | + */ | |
| 59 | + return Html::a($model->product->lang->name, [ | |
| 60 | + 'product/manage/view', | |
| 61 | + 'id' => $model->product->product_id, | |
| 62 | + ]); | |
| 63 | + }, | |
| 64 | + 'format' => 'html', | |
| 65 | + ], | |
| 39 | 66 | [ |
| 40 | 67 | 'class' => 'yii\grid\ActionColumn', |
| 41 | 68 | 'template' => '{update} {delete}', | ... | ... |
backend/views/project/update.php
| ... | ... | @@ -10,13 +10,13 @@ |
| 10 | 10 | * @var Project $model |
| 11 | 11 | * @var ProjectLang $model_langs |
| 12 | 12 | */ |
| 13 | - $this->title = \Yii::t('app', 'Update Project').': ' . $model->project_id; | |
| 13 | + $this->title = \Yii::t('app', 'Update Project').': ' . $model->lang->title; | |
| 14 | 14 | $this->params[ 'breadcrumbs' ][] = [ |
| 15 | 15 | 'label' => \Yii::t('app', 'Project'), |
| 16 | 16 | 'url' => [ 'index' ], |
| 17 | 17 | ]; |
| 18 | 18 | $this->params[ 'breadcrumbs' ][] = [ |
| 19 | - 'label' => $model->project_id, | |
| 19 | + 'label' => $model->lang->title, | |
| 20 | 20 | 'url' => [ |
| 21 | 21 | 'view', |
| 22 | 22 | 'id' => $model->project_id, | ... | ... |
backend/views/project/view.php
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -use yii\helpers\Html; | |
| 4 | -use yii\widgets\DetailView; | |
| 5 | - | |
| 6 | -/* @var $this yii\web\View */ | |
| 7 | -/* @var $model common\models\Project */ | |
| 8 | - | |
| 9 | -$this->title = $model->project_id; | |
| 10 | -$this->params['breadcrumbs'][] = ['label' => \Yii::t('app', 'Project'), 'url' => ['index']]; | |
| 11 | -$this->params['breadcrumbs'][] = $this->title; | |
| 2 | + | |
| 3 | + use yii\helpers\Html; | |
| 4 | + use yii\widgets\DetailView; | |
| 5 | + | |
| 6 | + /** | |
| 7 | + * @var yii\web\View $this | |
| 8 | + * @var common\models\Project $model | |
| 9 | + */ | |
| 10 | + $this->title = $model->lang->title; | |
| 11 | + $this->params[ 'breadcrumbs' ][] = [ | |
| 12 | + 'label' => \Yii::t('app', 'Project'), | |
| 13 | + 'url' => [ 'index' ], | |
| 14 | + ]; | |
| 15 | + $this->params[ 'breadcrumbs' ][] = $this->title; | |
| 12 | 16 | ?> |
| 13 | 17 | <div class="articles-view"> |
| 14 | - | |
| 18 | + | |
| 15 | 19 | <h1><?= Html::encode($this->title) ?></h1> |
| 16 | - | |
| 20 | + | |
| 17 | 21 | <p> |
| 18 | - <?= Html::a(\Yii::t('app', 'Update'), ['update', 'id' => $model->project_id], ['class' => 'btn btn-primary']) ?> | |
| 19 | - <?= Html::a(\Yii::t('app', 'Delete'), ['delete', 'id' => $model->project_id], [ | |
| 22 | + <?= Html::a(\Yii::t('app', 'Update'), [ | |
| 23 | + 'update', | |
| 24 | + 'id' => $model->project_id, | |
| 25 | + ], [ 'class' => 'btn btn-primary' ]) ?> | |
| 26 | + <?= Html::a(\Yii::t('app', 'Delete'), [ | |
| 27 | + 'delete', | |
| 28 | + 'id' => $model->project_id, | |
| 29 | + ], [ | |
| 20 | 30 | 'class' => 'btn btn-danger', |
| 21 | - 'data' => [ | |
| 31 | + 'data' => [ | |
| 22 | 32 | 'confirm' => \Yii::t('app', 'Are you sure you want to delete this item?'), |
| 23 | - 'method' => 'post', | |
| 33 | + 'method' => 'post', | |
| 24 | 34 | ], |
| 25 | 35 | ]) ?> |
| 26 | 36 | </p> |
| 27 | - | |
| 37 | + | |
| 28 | 38 | <?= DetailView::widget([ |
| 29 | - 'model' => $model, | |
| 39 | + 'model' => $model, | |
| 30 | 40 | 'attributes' => [ |
| 31 | 41 | 'project_id', |
| 32 | 42 | 'date_add:date', |
| 43 | + 'lang.title', | |
| 44 | + 'lang.alias', | |
| 45 | + 'lang.description:html', | |
| 46 | + 'image.imageUrl:image', | |
| 33 | 47 | ], |
| 34 | 48 | ]) ?> |
| 35 | 49 | ... | ... |
common/models/ArticlesSearch.php
common/models/ProductToProject.php
| ... | ... | @@ -37,7 +37,7 @@ |
| 37 | 37 | [ |
| 38 | 38 | 'product_variant_id', |
| 39 | 39 | 'project_id', |
| 40 | - 'product_id' | |
| 40 | + 'product_id', | |
| 41 | 41 | ], |
| 42 | 42 | 'required', |
| 43 | 43 | ], |
| ... | ... | @@ -104,6 +104,6 @@ |
| 104 | 104 | return $this->hasOne(Product::className(), [ |
| 105 | 105 | 'product_id' => 'product_id', |
| 106 | 106 | ]) |
| 107 | - ->viaTable('product_variant', [ 'product_variant_id' => 'product_variant_id' ]); | |
| 107 | + ->viaTable('product_variant as pv', [ 'product_variant_id' => 'product_variant_id' ]); | |
| 108 | 108 | } |
| 109 | 109 | } | ... | ... |
common/models/ProductToProjectSearch.php
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -namespace common\models; | |
| 4 | - | |
| 5 | -use Yii; | |
| 6 | -use yii\base\Model; | |
| 7 | -use yii\data\ActiveDataProvider; | |
| 8 | -use common\models\ProductToProject; | |
| 9 | - | |
| 10 | -/** | |
| 11 | - * ProductToProjectSearch represents the model behind the search form about `common\models\ProductToProject`. | |
| 12 | - */ | |
| 13 | -class ProductToProjectSearch extends ProductToProject | |
| 14 | -{ | |
| 2 | + | |
| 3 | + namespace common\models; | |
| 4 | + | |
| 5 | + use Yii; | |
| 6 | + use yii\base\Model; | |
| 7 | + use yii\data\ActiveDataProvider; | |
| 8 | + use common\models\ProductToProject; | |
| 9 | + | |
| 15 | 10 | /** |
| 16 | - * @inheritdoc | |
| 11 | + * ProductToProjectSearch represents the model behind the search form about | |
| 12 | + * `common\models\ProductToProject`. | |
| 17 | 13 | */ |
| 18 | - public function rules() | |
| 14 | + class ProductToProjectSearch extends ProductToProject | |
| 19 | 15 | { |
| 20 | - return [ | |
| 21 | - [['product_to_project_id', 'product_variant_id', 'project_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 = ProductToProject::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'); | |
| 16 | + | |
| 17 | + public $variant_name; | |
| 18 | + | |
| 19 | + public $product_name; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * @inheritdoc | |
| 23 | + */ | |
| 24 | + public function rules() | |
| 25 | + { | |
| 26 | + return [ | |
| 27 | + [ | |
| 28 | + [ | |
| 29 | + 'variant_name', | |
| 30 | + 'product_name', | |
| 31 | + ], | |
| 32 | + 'safe', | |
| 33 | + ], | |
| 34 | + ]; | |
| 35 | + } | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * @inheritdoc | |
| 39 | + */ | |
| 40 | + public function scenarios() | |
| 41 | + { | |
| 42 | + // bypass scenarios() implementation in the parent class | |
| 43 | + return Model::scenarios(); | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Creates data provider instance with search query applied | |
| 48 | + * | |
| 49 | + * @param array $params | |
| 50 | + * | |
| 51 | + * @return ActiveDataProvider | |
| 52 | + */ | |
| 53 | + public function search($params) | |
| 54 | + { | |
| 55 | + $query = ProductToProject::find() | |
| 56 | + ->joinWith('productVariant.lang') | |
| 57 | + ->joinWith('product.lang'); | |
| 58 | + | |
| 59 | + // add conditions that should always apply here | |
| 60 | + | |
| 61 | + $dataProvider = new ActiveDataProvider([ | |
| 62 | + 'query' => $query, | |
| 63 | + 'sort' => [ | |
| 64 | + 'attributes' => [ | |
| 65 | + 'variant_name' => [ | |
| 66 | + 'asc' => [ 'product_variant_lang.name' => SORT_ASC ], | |
| 67 | + 'desc' => [ 'product_variant_lang.name' => SORT_DESC ], | |
| 68 | + ], | |
| 69 | + 'product_name' => [ | |
| 70 | + 'asc' => [ 'product_lang.name' => SORT_ASC ], | |
| 71 | + 'desc' => [ 'product_lang.name' => SORT_DESC ], | |
| 72 | + ], | |
| 73 | + ], | |
| 74 | + ], | |
| 75 | + ]); | |
| 76 | + | |
| 77 | + $this->load($params); | |
| 78 | + | |
| 79 | + if(!$this->validate()) { | |
| 80 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 81 | + // $query->where('0=1'); | |
| 82 | + return $dataProvider; | |
| 83 | + } | |
| 84 | + | |
| 85 | + // grid filtering conditions | |
| 86 | + $query->andFilterWhere([ | |
| 87 | + 'like', | |
| 88 | + 'product_variant_lang.name', | |
| 89 | + $this->variant_name, | |
| 90 | + ]) | |
| 91 | + ->andFilterWhere([ | |
| 92 | + 'like', | |
| 93 | + 'product_lang.name', | |
| 94 | + $this->product_name, | |
| 95 | + ]); | |
| 96 | + | |
| 56 | 97 | return $dataProvider; |
| 57 | 98 | } |
| 58 | - | |
| 59 | - // grid filtering conditions | |
| 60 | - $query->andFilterWhere([ | |
| 61 | - 'product_to_project_id' => $this->product_to_project_id, | |
| 62 | - 'product_variant_id' => $this->product_variant_id, | |
| 63 | - 'project_id' => $this->project_id, | |
| 64 | - ]); | |
| 65 | - | |
| 66 | - return $dataProvider; | |
| 67 | 99 | } |
| 68 | -} | ... | ... |
common/models/Project.php
| ... | ... | @@ -81,14 +81,6 @@ |
| 81 | 81 | 'safe', |
| 82 | 82 | ], |
| 83 | 83 | [ |
| 84 | - [ | |
| 85 | - 'title', | |
| 86 | - 'link', | |
| 87 | - ], | |
| 88 | - 'string', | |
| 89 | - 'max' => 255, | |
| 90 | - ], | |
| 91 | - [ | |
| 92 | 84 | [ 'date_add' ], |
| 93 | 85 | 'filter', |
| 94 | 86 | 'filter' => function($value) { |
| ... | ... | @@ -105,8 +97,6 @@ |
| 105 | 97 | { |
| 106 | 98 | return [ |
| 107 | 99 | 'project_id' => 'Project ID', |
| 108 | - 'title' => 'Title', | |
| 109 | - 'link' => 'Link', | |
| 110 | 100 | 'description' => 'Description', |
| 111 | 101 | 'date_add' => 'Date Add', |
| 112 | 102 | 'images' => 'Images', | ... | ... |
common/models/ProjectSearch.php
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -namespace common\models; | |
| 4 | - | |
| 5 | -use yii\base\Model; | |
| 6 | -use yii\data\ActiveDataProvider; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * ProjectSearch represents the model behind the search form about `common\models\Project`. | |
| 10 | - */ | |
| 11 | -class ProjectSearch extends Project | |
| 12 | -{ | |
| 13 | 2 | |
| 14 | - public function behaviors() | |
| 15 | - { | |
| 16 | - return []; | |
| 17 | - } | |
| 3 | + namespace common\models; | |
| 4 | + | |
| 5 | + use yii\base\Model; | |
| 6 | + use yii\data\ActiveDataProvider; | |
| 18 | 7 | |
| 19 | 8 | /** |
| 20 | - * @inheritdoc | |
| 21 | - */ | |
| 22 | - public function rules() | |
| 23 | - { | |
| 24 | - return [ | |
| 25 | - [['project_id', 'date_add'], 'integer'], | |
| 26 | - ]; | |
| 27 | - } | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * @inheritdoc | |
| 31 | - */ | |
| 32 | - public function scenarios() | |
| 33 | - { | |
| 34 | - // bypass scenarios() implementation in the parent class | |
| 35 | - return Model::scenarios(); | |
| 36 | - } | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * Creates data provider instance with search query applied | |
| 40 | - * | |
| 41 | - * @param array $params | |
| 42 | - * | |
| 43 | - * @return ActiveDataProvider | |
| 9 | + * ProjectSearch represents the model behind the search form about `common\models\Project`. | |
| 44 | 10 | */ |
| 45 | - public function search($params) | |
| 11 | + class ProjectSearch extends Project | |
| 46 | 12 | { |
| 47 | - $query = Project::find(); | |
| 48 | - | |
| 49 | - // add conditions that should always apply here | |
| 50 | - | |
| 51 | - $dataProvider = new ActiveDataProvider([ | |
| 52 | - 'query' => $query, | |
| 53 | - ]); | |
| 54 | - | |
| 55 | - $this->load($params); | |
| 56 | - | |
| 57 | - if (!$this->validate()) { | |
| 58 | - // uncomment the following line if you do not want to return any records when validation fails | |
| 59 | - // $query->where('0=1'); | |
| 13 | + | |
| 14 | + public $title; | |
| 15 | + | |
| 16 | + public function behaviors() | |
| 17 | + { | |
| 18 | + return []; | |
| 19 | + } | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * @inheritdoc | |
| 23 | + */ | |
| 24 | + public function rules() | |
| 25 | + { | |
| 26 | + return [ | |
| 27 | + [ | |
| 28 | + [ | |
| 29 | + 'project_id', | |
| 30 | + 'date_add', | |
| 31 | + ], | |
| 32 | + 'integer', | |
| 33 | + ], | |
| 34 | + [ | |
| 35 | + [ 'title' ], | |
| 36 | + 'safe', | |
| 37 | + ], | |
| 38 | + ]; | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * @inheritdoc | |
| 43 | + */ | |
| 44 | + public function scenarios() | |
| 45 | + { | |
| 46 | + // bypass scenarios() implementation in the parent class | |
| 47 | + return Model::scenarios(); | |
| 48 | + } | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Creates data provider instance with search query applied | |
| 52 | + * | |
| 53 | + * @param array $params | |
| 54 | + * | |
| 55 | + * @return ActiveDataProvider | |
| 56 | + */ | |
| 57 | + public function search($params) | |
| 58 | + { | |
| 59 | + $query = Project::find() | |
| 60 | + ->joinWith('lang'); | |
| 61 | + | |
| 62 | + // add conditions that should always apply here | |
| 63 | + | |
| 64 | + $dataProvider = new ActiveDataProvider([ | |
| 65 | + 'query' => $query, | |
| 66 | + 'sort' => [ | |
| 67 | + 'attributes' => [ | |
| 68 | + 'project_id', | |
| 69 | + 'date_add', | |
| 70 | + 'title' => [ | |
| 71 | + 'asc' => [ 'project_lang.title' => SORT_ASC ], | |
| 72 | + 'desc' => [ 'project_lang.title' => SORT_DESC ], | |
| 73 | + ], | |
| 74 | + ], | |
| 75 | + ], | |
| 76 | + ]); | |
| 77 | + | |
| 78 | + $this->load($params); | |
| 79 | + | |
| 80 | + if(!$this->validate()) { | |
| 81 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 82 | + // $query->where('0=1'); | |
| 83 | + return $dataProvider; | |
| 84 | + } | |
| 85 | + | |
| 86 | + // grid filtering conditions | |
| 87 | + $query->andFilterWhere([ | |
| 88 | + 'project_id' => $this->project_id, | |
| 89 | + 'date_add' => $this->date_add, | |
| 90 | + ]); | |
| 91 | + | |
| 92 | + $query->andFilterWhere([ | |
| 93 | + 'like', | |
| 94 | + 'project_lang.title', | |
| 95 | + $this->title, | |
| 96 | + ]); | |
| 97 | + | |
| 60 | 98 | return $dataProvider; |
| 61 | 99 | } |
| 62 | - | |
| 63 | - // grid filtering conditions | |
| 64 | - $query->andFilterWhere([ | |
| 65 | - 'project_id' => $this->project_id, | |
| 66 | - 'date_add' => $this->date_add, | |
| 67 | - ]); | |
| 68 | - | |
| 69 | - return $dataProvider; | |
| 70 | 100 | } |
| 71 | -} | ... | ... |
common/modules/product/controllers/ManageController.php
| ... | ... | @@ -365,14 +365,37 @@ |
| 365 | 365 | } |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | + public function actionExportProcess($from, $filename) | |
| 369 | + { | |
| 370 | + | |
| 371 | + $model = new Export(); | |
| 372 | + if(Yii::$app->request->isAjax) { | |
| 373 | + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |
| 374 | + return $model->process($filename,$from); | |
| 375 | + } | |
| 376 | + } | |
| 377 | + | |
| 368 | 378 | public function actionExport() |
| 369 | 379 | { |
| 370 | 380 | $model = new Export(); |
| 371 | - if(( $file = $model->process(Yii::getAlias('@uploadDir')) )) { | |
| 372 | - return Yii::$app->response->sendFile($file) | |
| 373 | - ->send(); | |
| 381 | + | |
| 382 | + if($model->load(Yii::$app->request->post())) { | |
| 383 | + \Yii::$app->session->set('export_lang', $model->lang); | |
| 384 | + return $this->render('export-process', [ | |
| 385 | + 'model' => $model, | |
| 386 | + 'method' => 'export', | |
| 387 | + ]); | |
| 374 | 388 | } |
| 375 | - throw new NotFoundHttpException('Error'); | |
| 389 | + | |
| 390 | + return $this->render('export', [ | |
| 391 | + 'model' => $model, | |
| 392 | + ]); | |
| 393 | + // $model = new Export(); | |
| 394 | + // if(( $file = $model->process(Yii::getAlias('@uploadDir')) )) { | |
| 395 | + // return Yii::$app->response->sendFile($file) | |
| 396 | + // ->send(); | |
| 397 | + // } | |
| 398 | + // throw new NotFoundHttpException('Error'); | |
| 376 | 399 | } |
| 377 | 400 | |
| 378 | 401 | /** | ... | ... |
common/modules/product/models/Export.php
| ... | ... | @@ -2,37 +2,64 @@ |
| 2 | 2 | |
| 3 | 3 | namespace common\modules\product\models; |
| 4 | 4 | |
| 5 | + use common\modules\language\models\Language; | |
| 5 | 6 | use yii\base\Model; |
| 6 | 7 | |
| 7 | 8 | class Export extends Model |
| 8 | 9 | { |
| 9 | 10 | |
| 11 | + public $lang; | |
| 12 | + | |
| 13 | + public $file; | |
| 14 | + | |
| 10 | 15 | public $errors = []; |
| 11 | 16 | |
| 12 | 17 | public $output = []; |
| 13 | 18 | |
| 14 | - public function process($dirName, $filename = NULL, $use_not_enables = false) | |
| 19 | + public function rules() | |
| 20 | + { | |
| 21 | + return [ | |
| 22 | + [ | |
| 23 | + 'lang', | |
| 24 | + 'integer', | |
| 25 | + ], | |
| 26 | + [ | |
| 27 | + 'lang', | |
| 28 | + 'default', | |
| 29 | + 'value' => Language::getCurrent()->language_id, | |
| 30 | + ], | |
| 31 | + ]; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public function process($filename = NULL, $from = 0) | |
| 15 | 35 | { |
| 16 | - if(is_null($filename)) { | |
| 36 | + $limit = 100; | |
| 37 | + | |
| 38 | + if(empty( $filename )) { | |
| 17 | 39 | $filename = 'products_' . date('d_m_Y_H_i') . '.csv'; |
| 40 | + $handle = fopen(\Yii::getAlias('@storage/sync/') . $filename, "w"); | |
| 41 | + } else { | |
| 42 | + $handle = fopen(\Yii::getAlias('@storage/sync/') . $filename, "a"); | |
| 18 | 43 | } |
| 19 | - setlocale(LC_ALL, 'ru_RU.CP1251'); | |
| 20 | - $handle = fopen($dirName . '/' . $filename, "w"); | |
| 44 | + | |
| 45 | + $language = Language::findOne(\Yii::$app->session->get('export_lang', Language::getDefaultLanguage()->language_id)); | |
| 46 | + Language::setCurrent($language->url); | |
| 47 | + | |
| 21 | 48 | $products = Product::find() |
| 22 | - ->joinWith([ | |
| 23 | - 'variantsWithFilters', | |
| 24 | - 'brand', | |
| 25 | - 'categories', | |
| 26 | - ]) | |
| 27 | - ->with('filters') | |
| 49 | + ->with('variantsWithFilters', 'brand.lang', 'categories.lang', 'filters') | |
| 50 | + ->joinWith('lang', true, 'INNER JOIN') | |
| 51 | + ->limit($limit) | |
| 52 | + ->offset($from) | |
| 28 | 53 | ->all(); |
| 29 | - | |
| 54 | + $filesize = Product::find() | |
| 55 | + ->joinWith('lang', true, 'INNER JOIN') | |
| 56 | + ->count(); | |
| 30 | 57 | foreach($products as $product) { |
| 31 | 58 | $mods = []; |
| 32 | 59 | $filterString = $this->convertFilterToString($product->filters); |
| 33 | 60 | |
| 34 | 61 | foreach($product->variantsWithFilters as $variant) { |
| 35 | - $color = $variant->name; | |
| 62 | + $color = $variant->lang->name; | |
| 36 | 63 | $mods[] = $variant->sku . '=' . $this->convertFilterToString($variant->filters) . '=' . $color . '=' . ( ( !empty( $variant->image ) ) ? $variant->image->image : '' ) . '=' . $variant->stock; |
| 37 | 64 | } |
| 38 | 65 | |
| ... | ... | @@ -40,17 +67,17 @@ |
| 40 | 67 | |
| 41 | 68 | $categories = []; |
| 42 | 69 | foreach($product->categories as $value) { |
| 43 | - $categories[] = $value->name; | |
| 70 | + $categories[] = $value->lang->name; | |
| 44 | 71 | } |
| 45 | 72 | |
| 46 | 73 | $categories = implode(',', $categories); |
| 47 | 74 | |
| 48 | 75 | $list = [ |
| 49 | 76 | $categories, |
| 50 | - $product->brand->name, | |
| 51 | - $product->name, | |
| 77 | + ( ( !empty( $product->brand ) ) ? $product->brand->lang->name : '' ), | |
| 78 | + $product->lang->name, | |
| 52 | 79 | '', |
| 53 | - ( ( !empty( $product->description ) ) ? $product->description : '' ), | |
| 80 | + ( ( !empty( $product->lang->description ) ) ? $product->lang->description : '' ), | |
| 54 | 81 | $filterString, |
| 55 | 82 | ( !empty( $product->variant ) ) ? $product->variant->price_old : '', |
| 56 | 83 | ( !empty( $product->variant ) ) ? $product->variant->price : '', |
| ... | ... | @@ -62,23 +89,40 @@ |
| 62 | 89 | implode(',', $fotos), |
| 63 | 90 | ]; |
| 64 | 91 | $to_write = array_merge($list, $mods); |
| 65 | - foreach($to_write as &$cell) { | |
| 66 | - $cell = iconv("UTF-8", "WINDOWS-1251", $cell); | |
| 67 | - } | |
| 68 | 92 | fputcsv($handle, $to_write, ';'); |
| 69 | 93 | unset( $product ); |
| 70 | 94 | } |
| 71 | 95 | |
| 72 | 96 | fclose($handle); |
| 73 | 97 | |
| 74 | - return $dirName . '/' . $filename; | |
| 98 | + $from += $limit; | |
| 99 | + $end = false; | |
| 100 | + if($from > $filesize) { | |
| 101 | + $end = true; | |
| 102 | + } | |
| 103 | + | |
| 104 | + $result = [ | |
| 105 | + 'end' => $end, | |
| 106 | + 'from' => $from, | |
| 107 | + 'totalsize' => $filesize, | |
| 108 | + 'filename' => $filename, | |
| 109 | + ]; | |
| 110 | + | |
| 111 | + if($end) { | |
| 112 | + $result = array_merge($result, [ | |
| 113 | + 'link' => '/storage/sync/' . $filename, | |
| 114 | + ]); | |
| 115 | + } | |
| 116 | + | |
| 117 | + return $result; | |
| 118 | + | |
| 75 | 119 | } |
| 76 | 120 | |
| 77 | 121 | public function convertFilterToString($filters) |
| 78 | 122 | { |
| 79 | 123 | $fittersArray = []; |
| 80 | 124 | foreach($filters as $filter) { |
| 81 | - $fittersArray[ $filter->taxGroup->alias ][] = $filter->value; | |
| 125 | + $fittersArray[ $filter->taxGroup->alias ][] = $filter->lang->value; | |
| 82 | 126 | } |
| 83 | 127 | $filterString = []; |
| 84 | 128 | ... | ... |
common/modules/product/models/Product.php
| ... | ... | @@ -268,6 +268,7 @@ |
| 268 | 268 | public function getVariantsWithFilters() |
| 269 | 269 | { |
| 270 | 270 | return $this->hasMany(ProductVariant::className(), [ 'product_id' => 'product_id' ]) |
| 271 | + ->joinWith('lang', true, 'INNER JOIN') | |
| 271 | 272 | ->with([ |
| 272 | 273 | 'filters', |
| 273 | 274 | 'image', |
| ... | ... | @@ -537,7 +538,8 @@ |
| 537 | 538 | { |
| 538 | 539 | return $this->hasMany(TaxOption::className(), [ 'tax_option_id' => 'option_id' ]) |
| 539 | 540 | ->viaTable('product_option', [ 'product_id' => 'product_id' ]) |
| 540 | - ->joinWith('taxGroup'); | |
| 541 | + ->joinWith('taxGroup.lang', true, 'INNER JOIN') | |
| 542 | + ->joinWith('lang', true, 'INNER JOIN'); | |
| 541 | 543 | } |
| 542 | 544 | |
| 543 | 545 | public function getProductSpec() | ... | ... |
common/modules/product/models/ProductVariant.php
| ... | ... | @@ -199,7 +199,8 @@ |
| 199 | 199 | |
| 200 | 200 | return $this->hasMany(TaxOption::className(), [ 'tax_option_id' => 'option_id' ]) |
| 201 | 201 | ->viaTable('product_variant_option', [ 'product_variant_id' => 'product_variant_id' ]) |
| 202 | - ->joinWith('taxGroup'); | |
| 202 | + ->joinWith('taxGroup.lang', true, 'INNER JOIN') | |
| 203 | + ->joinWith('lang', true, 'INNER JOIN'); | |
| 203 | 204 | } |
| 204 | 205 | |
| 205 | 206 | /** | ... | ... |
common/modules/product/views/manage/export-process.php
0 → 100644
| 1 | +<?php | |
| 2 | + /** | |
| 3 | + * @var View $this | |
| 4 | + */ | |
| 5 | + | |
| 6 | +use yii\helpers\Html; | |
| 7 | + use yii\web\View; | |
| 8 | + use yii\widgets\ActiveForm; | |
| 9 | + | |
| 10 | +?> | |
| 11 | +<?php | |
| 12 | +$this->registerJs("var in_process=true; | |
| 13 | + var count=1; | |
| 14 | + var filename = null; | |
| 15 | + | |
| 16 | + doExport(0,filename); | |
| 17 | + | |
| 18 | + function doExport(from,filename) { | |
| 19 | + from = typeof(from) != 'undefined' ? from : 0; | |
| 20 | + | |
| 21 | + $.ajax({ | |
| 22 | + method: 'get', | |
| 23 | + url: '".Yii::$app->request->baseUrl .'/product/manage/export-process'."', | |
| 24 | + data: { | |
| 25 | + from:from, | |
| 26 | + filename: filename | |
| 27 | + }, | |
| 28 | + dataType: 'json', | |
| 29 | + success: function(data){ | |
| 30 | + | |
| 31 | + var per = Math.round(100*data.from/data.totalsize)+'%'; | |
| 32 | + $('#progressbar div').css({width: per}); | |
| 33 | + | |
| 34 | + if(data != false && !data.end) | |
| 35 | + { | |
| 36 | + doExport(data.from,data.filename); | |
| 37 | + } | |
| 38 | + else | |
| 39 | + { | |
| 40 | + console.log(data.link); | |
| 41 | + $(progressbar).hide('fast'); | |
| 42 | + $('#result_link').attr('href', data.link).removeClass('hidden'); | |
| 43 | + in_process = false; | |
| 44 | + } | |
| 45 | + }, | |
| 46 | + error: function(xhr, status, errorThrown) { | |
| 47 | + } | |
| 48 | + }); | |
| 49 | + }"); | |
| 50 | +?> | |
| 51 | + | |
| 52 | +<!--<script>--> | |
| 53 | +<!-- var in_process=true;--> | |
| 54 | +<!-- var count=1;--> | |
| 55 | +<!-- var filename = null;--> | |
| 56 | +<!-- --> | |
| 57 | +<!-- doExport(0,filename);--> | |
| 58 | +<!-- --> | |
| 59 | +<!-- function doExport(from,filename) {--> | |
| 60 | +<!-- from = typeof(from) != 'undefined' ? from : 0;--> | |
| 61 | +<!-- --> | |
| 62 | +<!-- $.ajax({--> | |
| 63 | +<!-- method: 'get',--> | |
| 64 | +<!-- url: '".Yii::$app->request->baseUrl .'/product/manage/export-process'."',--> | |
| 65 | +<!-- data: {--> | |
| 66 | +<!-- from:from,--> | |
| 67 | +<!-- filename: filename--> | |
| 68 | +<!-- },--> | |
| 69 | +<!-- dataType: 'json',--> | |
| 70 | +<!-- success: function(data){--> | |
| 71 | +<!-- --> | |
| 72 | +<!-- var per = Math.round(100*data.from/data.totalsize)+'%';--> | |
| 73 | +<!-- $('#progressbar div').css({width: per});--> | |
| 74 | +<!-- --> | |
| 75 | +<!-- if(data != false && !data.end)--> | |
| 76 | +<!-- {--> | |
| 77 | +<!-- doExport(data.from,data.filename);--> | |
| 78 | +<!-- }--> | |
| 79 | +<!-- else--> | |
| 80 | +<!-- {--> | |
| 81 | +<!-- console.log(data.link);--> | |
| 82 | +<!-- progressbar.hide('fast');--> | |
| 83 | +<!-- in_process = false;--> | |
| 84 | +<!-- }--> | |
| 85 | +<!-- },--> | |
| 86 | +<!-- error: function(xhr, status, errorThrown) {--> | |
| 87 | +<!-- }--> | |
| 88 | +<!-- });--> | |
| 89 | +<!-- }--> | |
| 90 | +<!--</script>--> | |
| 91 | + | |
| 92 | +<div class="product-import-process-form"> | |
| 93 | + <h1>Экспорт данных товаров</h1> | |
| 94 | + | |
| 95 | + <?= \yii\jui\ProgressBar::widget([ | |
| 96 | + 'clientOptions' => [ | |
| 97 | + 'value' => 100, | |
| 98 | + 'label' => '' | |
| 99 | + ], | |
| 100 | + 'options' => [ | |
| 101 | + 'id' => 'progressbar' | |
| 102 | + ], | |
| 103 | + ]);?> | |
| 104 | + <ul id="process-result"></ul> | |
| 105 | + <a id="result_link" href="" class="hidden">Получай ВАСЯ!</a> | |
| 106 | +</div> | ... | ... |
| 1 | +<?php | |
| 2 | + | |
| 3 | + use common\modules\language\models\Language; | |
| 4 | + use yii\helpers\Html; | |
| 5 | + use yii\widgets\ActiveForm; | |
| 6 | + | |
| 7 | +?> | |
| 8 | + | |
| 9 | +<div class="product-import-form"> | |
| 10 | + <?php $form = ActiveForm::begin([ | |
| 11 | + 'enableClientValidation' => false, | |
| 12 | + 'options' => [ 'enctype' => 'multipart/form-data' ], | |
| 13 | + ]); ?> | |
| 14 | + | |
| 15 | + <?php if($model->errors) : ?> | |
| 16 | + <div class="error"> | |
| 17 | + <?= implode("<br>\n", $model->errors); ?> | |
| 18 | + </div> | |
| 19 | + <?php endif ?> | |
| 20 | + | |
| 21 | + <?php if($model->output) : ?> | |
| 22 | + <h2>Лог операции</h2> | |
| 23 | + <div class="success" style="height: 10em;overflow: auto;border: 1px solid #000"> | |
| 24 | + <?= implode("<br>\n", $model->output); ?> | |
| 25 | + </div> | |
| 26 | + <?php endif ?> | |
| 27 | + | |
| 28 | + <?= $form->field($model, 'lang') | |
| 29 | + ->dropDownList(Language::find() | |
| 30 | + ->select([ | |
| 31 | + 'name', | |
| 32 | + 'language_id', | |
| 33 | + ]) | |
| 34 | + ->where([ 'status' => 1 ]) | |
| 35 | + ->orderBy([ 'default' => SORT_DESC ]) | |
| 36 | + ->asArray() | |
| 37 | + ->indexBy('language_id') | |
| 38 | + ->column()) ?> | |
| 39 | + | |
| 40 | + <?php /*= $form->field($model, 'file')->widget(\kartik\file\FileInput::classname(), [ | |
| 41 | + 'language' => 'ru', | |
| 42 | + 'options' => [ | |
| 43 | + 'multiple' => false, | |
| 44 | + ], | |
| 45 | + 'pluginOptions' => [ | |
| 46 | + 'allowedFileExtensions' => ['csv'], | |
| 47 | + 'overwriteInitial' => true, | |
| 48 | + 'showRemove' => false, | |
| 49 | + 'showUpload' => false, | |
| 50 | + ], | |
| 51 | + ])*/ ?> | |
| 52 | + | |
| 53 | + <div class="form-group"> | |
| 54 | + <?= Html::submitButton(Yii::t('product', 'Import'), [ 'class' => 'btn btn-primary' ]) ?> | |
| 55 | + </div> | |
| 56 | + | |
| 57 | + <?php ActiveForm::end(); ?> | |
| 58 | +</div> | |
| 0 | 59 | \ No newline at end of file | ... | ... |
common/modules/rubrication/models/TaxGroup.php
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | namespace common\modules\rubrication\models; |
| 4 | 4 | |
| 5 | 5 | use common\modules\language\behaviors\LanguageBehavior; |
| 6 | + use common\modules\language\models\Language; | |
| 6 | 7 | use common\modules\product\models\Category; |
| 7 | 8 | use yii\db\ActiveQuery; |
| 8 | 9 | use yii\db\ActiveRecord; |
| ... | ... | @@ -143,4 +144,13 @@ |
| 143 | 144 | return $this->hasMany(TaxOption::className(), [ 'tax_group_id' => 'tax_group_id' ]) |
| 144 | 145 | ->inverseOf('taxGroup'); |
| 145 | 146 | } |
| 147 | + | |
| 148 | + public function getAlias() { | |
| 149 | + $default_lang = Language::getDefaultLanguage(); | |
| 150 | + /** | |
| 151 | + * @var TaxGroupLang $lang | |
| 152 | + */ | |
| 153 | + $lang = $this->getLang($default_lang->language_id)->one(); | |
| 154 | + return $lang->alias; | |
| 155 | + } | |
| 146 | 156 | } | ... | ... |