Commit b3ee7cf048a8d025f5b408e06747c3f92ff1cd19
1 parent
8a724a04
-Brand description WYSIWYG
Showing
4 changed files
with
284 additions
and
167 deletions
Show diff stats
backend/views/brand/_form.php
1 | <?php | 1 | <?php |
2 | - | ||
3 | -use yii\helpers\Html; | ||
4 | -use yii\widgets\ActiveForm; | ||
5 | - | ||
6 | -/* @var $this yii\web\View */ | ||
7 | -/* @var $model common\modules\product\models\Brand */ | ||
8 | -/* @var $form yii\widgets\ActiveForm */ | 2 | + |
3 | + use mihaildev\ckeditor\CKEditor; | ||
4 | + use mihaildev\elfinder\ElFinder; | ||
5 | + use yii\helpers\Html; | ||
6 | + use yii\widgets\ActiveForm; | ||
7 | + | ||
8 | + /* @var $this yii\web\View */ | ||
9 | + /* @var $model common\modules\product\models\Brand */ | ||
10 | + /* @var $form yii\widgets\ActiveForm */ | ||
9 | ?> | 11 | ?> |
10 | 12 | ||
11 | <div class="brand-form"> | 13 | <div class="brand-form"> |
14 | + | ||
15 | + <?php $form = ActiveForm::begin( | ||
16 | + [ | ||
17 | + 'enableClientValidation' => false, | ||
18 | + 'options' => [ 'enctype' => 'multipart/form-data' ], | ||
19 | + ] | ||
20 | + ); ?> | ||
21 | + | ||
22 | + <?= $form->field($model, 'name') | ||
23 | + ->textInput() ?> | ||
24 | + | ||
25 | + <?= $form->field($model, 'alias') | ||
26 | + ->textInput([ 'maxlength' => true ]) ?> | ||
27 | + | ||
28 | + <?= $form->field($model, 'image') | ||
29 | + ->widget( | ||
30 | + \kartik\file\FileInput::classname(), | ||
31 | + [ | ||
32 | + 'language' => 'ru', | ||
33 | + 'options' => [ | ||
34 | + 'accept' => 'image/*', | ||
35 | + 'multiple' => false, | ||
36 | + ], | ||
37 | + 'pluginOptions' => [ | ||
38 | + 'allowedFileExtensions' => [ | ||
39 | + 'jpg', | ||
40 | + 'gif', | ||
41 | + 'png', | ||
42 | + ], | ||
43 | + 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage( | ||
44 | + $model->imageUrl, | ||
45 | + 'list' | ||
46 | + ) : '', | ||
47 | + 'overwriteInitial' => true, | ||
48 | + 'showRemove' => false, | ||
49 | + 'showUpload' => false, | ||
50 | + 'previewFileType' => 'image', | ||
51 | + ], | ||
52 | + ] | ||
53 | + ); ?> | ||
54 | + | ||
55 | + <?= $form->field($model, 'description') | ||
56 | + ->widget( | ||
57 | + CKEditor::className(), | ||
58 | + [ | ||
59 | + 'editorOptions' => ElFinder::ckeditorOptions( | ||
60 | + 'elfinder', | ||
61 | + [ | ||
62 | + 'preset' => 'full', | ||
63 | + //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать | ||
64 | + 'inline' => false, | ||
65 | + //по умолчанию false]), | ||
66 | + 'filebrowserUploadUrl' => Yii::$app->getUrlManager() | ||
67 | + ->createUrl('file/uploader/images-upload'), | ||
68 | + ] | ||
69 | + ), | ||
70 | + ] | ||
71 | + ) ?> | ||
72 | + | ||
73 | + <?= $form->field($model, 'meta_title') | ||
74 | + ->textInput([ 'maxlength' => true ]) ?> | ||
75 | + | ||
76 | + <?= $form->field($model, 'meta_desc') | ||
77 | + ->textarea([ 'rows' => 6 ]) ?> | ||
78 | + | ||
79 | + <?= $form->field($model, 'meta_robots') | ||
80 | + ->textInput([ 'maxlength' => true ]) ?> | ||
81 | + | ||
82 | + <?= $form->field($model, 'seo_text') | ||
83 | + ->textarea([ 'rows' => 6 ]) ?> | ||
84 | + | ||
85 | + <?= $form->field($model, 'in_menu') | ||
86 | + ->checkbox() ?> | ||
12 | 87 | ||
13 | - <?php $form = ActiveForm::begin([ | ||
14 | - 'enableClientValidation' => false, | ||
15 | - 'options' => ['enctype' => 'multipart/form-data'] | ||
16 | - ]); ?> | ||
17 | - | ||
18 | - <?= $form->field($model, 'name')->textInput() ?> | ||
19 | - | ||
20 | - <?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?> | ||
21 | - | ||
22 | - <?= $form->field($model, 'image')->widget(\kartik\file\FileInput::classname(), [ | ||
23 | - 'language' => 'ru', | ||
24 | - 'options' => [ | ||
25 | - 'accept' => 'image/*', | ||
26 | - 'multiple' => false, | ||
27 | - ], | ||
28 | - 'pluginOptions' => [ | ||
29 | - 'allowedFileExtensions' => ['jpg', 'gif', 'png'], | ||
30 | - 'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', | ||
31 | - 'overwriteInitial' => true, | ||
32 | - 'showRemove' => false, | ||
33 | - 'showUpload' => false, | ||
34 | - 'previewFileType' => 'image', | ||
35 | - ], | ||
36 | - ]); ?> | ||
37 | - | ||
38 | - <?= $form->field($model, 'meta_title')->textInput(['maxlength' => true]) ?> | ||
39 | - | ||
40 | - <?= $form->field($model, 'meta_desc')->textarea(['rows' => 6]) ?> | ||
41 | - | ||
42 | - <?= $form->field($model, 'meta_robots')->textInput(['maxlength' => true]) ?> | ||
43 | - | ||
44 | - <?= $form->field($model, 'seo_text')->textarea(['rows' => 6]) ?> | ||
45 | - | ||
46 | - <?= $form->field($model, 'in_menu')->checkbox()?> | ||
47 | - | ||
48 | - <div class="form-group"> | ||
49 | - <?= Html::submitButton($model->isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | ||
50 | - <?php if ($model->isNewRecord) :?> | ||
51 | - <?= Html::submitButton(Yii::t('product', 'Create and continue'), ['name' => 'create_and_new', 'class' => 'btn btn-primary']) ?> | ||
52 | - <?php endif?> | ||
53 | - </div> | ||
54 | - | 88 | + <div class="form-group"> |
89 | + <?= Html::submitButton( | ||
90 | + $model->isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), | ||
91 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | ||
92 | + ) ?> | ||
93 | + <?php if ($model->isNewRecord) : ?> | ||
94 | + <?= Html::submitButton( | ||
95 | + Yii::t('product', 'Create and continue'), | ||
96 | + [ | ||
97 | + 'name' => 'create_and_new', | ||
98 | + 'class' => 'btn btn-primary', | ||
99 | + ] | ||
100 | + ) ?> | ||
101 | + <?php endif ?> | ||
102 | + </div> | ||
103 | + | ||
55 | <?php ActiveForm::end(); ?> | 104 | <?php ActiveForm::end(); ?> |
56 | 105 | ||
57 | </div> | 106 | </div> |
common/modules/product/models/Brand.php
1 | <?php | 1 | <?php |
2 | - | ||
3 | -namespace common\modules\product\models; | ||
4 | - | ||
5 | -use common\behaviors\SaveImgBehavior; | ||
6 | -use common\behaviors\Slug; | ||
7 | -use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; | ||
8 | -use yii\web\UploadedFile; | ||
9 | -use Yii; | ||
10 | - | ||
11 | -/** | ||
12 | - * This is the model class for table "brand". | ||
13 | - * | ||
14 | - * @property integer $brand_id | ||
15 | - | ||
16 | - * @property integer $brand_name_id | ||
17 | - * @property string $alias | ||
18 | - * @property string $image | ||
19 | - * @property string $meta_title | ||
20 | - * @property string $meta_desc | ||
21 | - * @property string $meta_robots | ||
22 | - * @property string $seo_text | ||
23 | - * @property string $name | ||
24 | - * | ||
25 | - * @property BrandName $brandName | ||
26 | - * @property BrandName[] $brandNames | ||
27 | - * @property Product[] $products | ||
28 | - */ | ||
29 | -class Brand extends \yii\db\ActiveRecord | ||
30 | -{ | ||
31 | - public $imageUpload; | ||
32 | - | ||
33 | - public $_items_count = 0; | ||
34 | - | 2 | + |
3 | + namespace common\modules\product\models; | ||
4 | + | ||
5 | + use common\behaviors\SaveImgBehavior; | ||
6 | + use yii\db\ActiveRecord; | ||
7 | + use Yii; | ||
8 | + | ||
35 | /** | 9 | /** |
36 | - * @inheritdoc | 10 | + * This is the model class for table "brand". |
11 | + * | ||
12 | + * @property integer $brand_id | ||
13 | + * @property integer $brand_name_id | ||
14 | + * @property string $alias | ||
15 | + * @property string $image | ||
16 | + * @property string $meta_title | ||
17 | + * @property string $meta_desc | ||
18 | + * @property string $meta_robots | ||
19 | + * @property string $seo_text | ||
20 | + * @property string $name | ||
21 | + * @property string $description | ||
22 | + * @property Product[] $products | ||
37 | */ | 23 | */ |
38 | - public static function tableName() | 24 | + class Brand extends ActiveRecord |
39 | { | 25 | { |
40 | - return 'brand'; | 26 | + public $imageUpload; |
27 | + | ||
28 | + public $_items_count = 0; | ||
29 | + | ||
30 | + /** | ||
31 | + * @inheritdoc | ||
32 | + */ | ||
33 | + public static function tableName() | ||
34 | + { | ||
35 | + return 'brand'; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * @inheritdoc | ||
40 | + */ | ||
41 | + | ||
42 | + public function behaviors() | ||
43 | + { | ||
44 | + return [ | ||
45 | + [ | ||
46 | + 'class' => SaveImgBehavior::className(), | ||
47 | + 'fields' => [ | ||
48 | + [ | ||
49 | + 'name' => 'image', | ||
50 | + 'directory' => 'brands', | ||
51 | + ], | ||
52 | + ], | ||
53 | + ], | ||
54 | + 'slug' => [ | ||
55 | + 'class' => 'common\behaviors\Slug', | ||
56 | + 'in_attribute' => 'name', | ||
57 | + 'out_attribute' => 'alias', | ||
58 | + 'translit' => true, | ||
59 | + ], | ||
60 | + ]; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * @inheritdoc | ||
65 | + */ | ||
66 | + public function rules() | ||
67 | + { | ||
68 | + return [ | ||
69 | + [ | ||
70 | + [ | ||
71 | + 'name', | ||
72 | + 'description', | ||
73 | + ], | ||
74 | + 'string', | ||
75 | + ], | ||
76 | + [ | ||
77 | + [ 'brand_name_id' ], | ||
78 | + 'integer', | ||
79 | + ], | ||
80 | + [ | ||
81 | + [ 'in_menu' ], | ||
82 | + 'boolean', | ||
83 | + ], | ||
84 | + [ | ||
85 | + [ | ||
86 | + 'meta_desc', | ||
87 | + 'seo_text', | ||
88 | + ], | ||
89 | + 'string', | ||
90 | + ], | ||
91 | + [ | ||
92 | + [ | ||
93 | + 'alias', | ||
94 | + 'name', | ||
95 | + ], | ||
96 | + 'string', | ||
97 | + 'max' => 250, | ||
98 | + ], | ||
99 | + [ | ||
100 | + [ | ||
101 | + 'meta_title', | ||
102 | + 'image', | ||
103 | + ], | ||
104 | + 'string', | ||
105 | + 'max' => 255, | ||
106 | + ], | ||
107 | + [ | ||
108 | + [ 'meta_robots' ], | ||
109 | + 'string', | ||
110 | + 'max' => 50, | ||
111 | + ], | ||
112 | + [ | ||
113 | + [ 'imageUpload' ], | ||
114 | + 'safe', | ||
115 | + ], | ||
116 | + [ | ||
117 | + [ 'imageUpload' ], | ||
118 | + 'file', | ||
119 | + 'extensions' => 'jpg, gif, png', | ||
120 | + ], | ||
121 | + ]; | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * @inheritdoc | ||
126 | + */ | ||
127 | + public function attributeLabels() | ||
128 | + { | ||
129 | + return [ | ||
130 | + 'name' => Yii::t('product', 'Name of the brand'), | ||
131 | + 'brand_id' => Yii::t('product', 'Brand ID'), | ||
132 | + 'brand_name_id' => Yii::t('product', 'Brand Name ID'), | ||
133 | + 'alias' => Yii::t('product', 'Alias'), | ||
134 | + 'image' => Yii::t('product', 'Image'), | ||
135 | + 'imageUrl' => Yii::t('product', 'Image'), | ||
136 | + 'meta_title' => Yii::t('product', 'Meta Title'), | ||
137 | + 'meta_desc' => Yii::t('product', 'Meta Desc'), | ||
138 | + 'meta_robots' => Yii::t('product', 'Meta Robots'), | ||
139 | + 'seo_text' => Yii::t('product', 'Seo Text'), | ||
140 | + 'in_menu' => Yii::t('product', 'Выводить в меню'), | ||
141 | + 'description' => Yii::t('product', 'Описание'), | ||
142 | + ]; | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * @return \yii\db\ActiveQuery | ||
147 | + */ | ||
148 | + public function getProducts() | ||
149 | + { | ||
150 | + return $this->hasMany(Product::className(), [ 'brand_id' => 'brand_id' ]); | ||
151 | + } | ||
152 | + | ||
153 | + public function getImageFile() | ||
154 | + { | ||
155 | + return empty($this->image) ? NULL : '/storage/brands/' . $this->image; | ||
156 | + } | ||
157 | + | ||
158 | + public function getImageUrl() | ||
159 | + { | ||
160 | + return empty($this->image) ? NULL : '/storage/brands/' . $this->image; | ||
161 | + } | ||
162 | + | ||
41 | } | 163 | } |
42 | - | ||
43 | - | ||
44 | - /** | ||
45 | - * @inheritdoc | ||
46 | - */ | ||
47 | - | ||
48 | - public function behaviors() | ||
49 | - { | ||
50 | - return [ | ||
51 | - [ | ||
52 | - 'class' => SaveImgBehavior::className(), | ||
53 | - 'fields' => [ | ||
54 | - ['name'=>'image','directory' => 'brands' ] | ||
55 | - ] | ||
56 | - ], | ||
57 | - 'slug' => [ | ||
58 | - 'class' => 'common\behaviors\Slug', | ||
59 | - 'in_attribute' => 'name', | ||
60 | - 'out_attribute' => 'alias', | ||
61 | - 'translit' => true | ||
62 | - ], | ||
63 | - ]; | ||
64 | - } | ||
65 | - | ||
66 | - /** | ||
67 | - * @inheritdoc | ||
68 | - */ | ||
69 | - public function rules() | ||
70 | - { | ||
71 | - return [ | ||
72 | - [['name'], 'string'], | ||
73 | - [['brand_name_id'], 'integer'], | ||
74 | - [['in_menu'], 'boolean'], | ||
75 | - [['meta_desc', 'seo_text'], 'string'], | ||
76 | - [['alias', 'name'], 'string', 'max' => 250], | ||
77 | - [['meta_title', 'image'], 'string', 'max' => 255], | ||
78 | - [['meta_robots'], 'string', 'max' => 50], | ||
79 | - [['imageUpload'], 'safe'], | ||
80 | - [['imageUpload'], 'file', 'extensions' => 'jpg, gif, png'], | ||
81 | - ]; | ||
82 | - } | ||
83 | - | ||
84 | - /** | ||
85 | - * @inheritdoc | ||
86 | - */ | ||
87 | - public function attributeLabels() | ||
88 | - { | ||
89 | - return [ | ||
90 | - 'name' => Yii::t('product', 'Name of the brand'), | ||
91 | - 'brand_id' => Yii::t('product', 'Brand ID'), | ||
92 | - 'brand_name_id' => Yii::t('product', 'Brand Name ID'), | ||
93 | - 'alias' => Yii::t('product', 'Alias'), | ||
94 | - 'image' => Yii::t('product', 'Image'), | ||
95 | - 'imageUrl' => Yii::t('product', 'Image'), | ||
96 | - 'meta_title' => Yii::t('product', 'Meta Title'), | ||
97 | - 'meta_desc' => Yii::t('product', 'Meta Desc'), | ||
98 | - 'meta_robots' => Yii::t('product', 'Meta Robots'), | ||
99 | - 'seo_text' => Yii::t('product', 'Seo Text'), | ||
100 | - 'in_menu' => Yii::t('product', 'Выводить в меню'), | ||
101 | - ]; | ||
102 | - } | ||
103 | - | ||
104 | - | ||
105 | - | ||
106 | - /** | ||
107 | - * @return \yii\db\ActiveQuery | ||
108 | - */ | ||
109 | - public function getProducts() | ||
110 | - { | ||
111 | - return $this->hasMany(Product::className(), ['brand_id' => 'brand_id']); | ||
112 | - } | ||
113 | - | ||
114 | - public function getImageFile() { | ||
115 | - return empty($this->image) ? null : '/storage/brands/'. $this->image; | ||
116 | - } | ||
117 | - | ||
118 | - public function getImageUrl() { | ||
119 | - return empty($this->image) ? null : '/storage/brands/'. $this->image; | ||
120 | - } | ||
121 | - | ||
122 | -} |
console/migrations/m170202_140836_add_description_column_to_brand_table.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use yii\db\Migration; | ||
4 | + | ||
5 | +/** | ||
6 | + * Handles adding description to table `brand`. | ||
7 | + */ | ||
8 | +class m170202_140836_add_description_column_to_brand_table extends Migration | ||
9 | +{ | ||
10 | + /** | ||
11 | + * @inheritdoc | ||
12 | + */ | ||
13 | + public function up() | ||
14 | + { | ||
15 | + $this->addColumn('brand', 'description', $this->text()); | ||
16 | + } | ||
17 | + | ||
18 | + /** | ||
19 | + * @inheritdoc | ||
20 | + */ | ||
21 | + public function down() | ||
22 | + { | ||
23 | + $this->dropColumn('brand', 'description'); | ||
24 | + } | ||
25 | +} |
frontend/views/catalog/brand.php
@@ -46,7 +46,9 @@ $this->params['breadcrumbs'][] = $brand->name; | @@ -46,7 +46,9 @@ $this->params['breadcrumbs'][] = $brand->name; | ||
46 | <h1 class="title"><?= Seo::widget(['row' => 'h1']) ?></h1> | 46 | <h1 class="title"><?= Seo::widget(['row' => 'h1']) ?></h1> |
47 | 47 | ||
48 | <div class="brand-seo-text"> | 48 | <div class="brand-seo-text"> |
49 | - <?= !empty(Seo::widget(['row' => Seo::SEO_TEXT])) ? Seo::widget(['row' => Seo::SEO_TEXT]) : $brand->seo_text?> | 49 | + <?php |
50 | + if(!empty($brand->description)) echo $brand->description; | ||
51 | + ?> | ||
50 | </div> | 52 | </div> |
51 | <div class="clearfix"></div> | 53 | <div class="clearfix"></div> |
52 | 54 |