Commit 3d655028a8eec43dd8fc8e51c7f0351dc87b872c
1 parent
be03d9ce
-Commint after vication
Showing
2 changed files
with
79 additions
and
25 deletions
Show diff stats
models/BrandSize.php
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | namespace artweb\artbox\ecommerce\models; |
| 4 | 4 | |
| 5 | +use artweb\artbox\behaviors\SaveImgBehavior; | |
| 5 | 6 | use Yii; |
| 6 | 7 | |
| 7 | 8 | /** |
| ... | ... | @@ -12,11 +13,25 @@ use Yii; |
| 12 | 13 | * @property string $image |
| 13 | 14 | * |
| 14 | 15 | * @property Brand $brand |
| 15 | - * @property BrandSizeToCategory[] $brandSizeToCategories | |
| 16 | 16 | * @property Category[] $categories |
| 17 | 17 | */ |
| 18 | 18 | class BrandSize extends \yii\db\ActiveRecord |
| 19 | 19 | { |
| 20 | + public function behaviors() | |
| 21 | + { | |
| 22 | + return [ | |
| 23 | + 'image' => [ | |
| 24 | + 'class' => SaveImgBehavior::className(), | |
| 25 | + 'fields' => [ | |
| 26 | + [ | |
| 27 | + 'name' => 'image', | |
| 28 | + 'directory' => 'products', | |
| 29 | + ], | |
| 30 | + ], | |
| 31 | + ], | |
| 32 | + ]; | |
| 33 | + } | |
| 34 | + | |
| 20 | 35 | /** |
| 21 | 36 | * @inheritdoc |
| 22 | 37 | */ |
| ... | ... | @@ -60,14 +75,6 @@ class BrandSize extends \yii\db\ActiveRecord |
| 60 | 75 | /** |
| 61 | 76 | * @return \yii\db\ActiveQuery |
| 62 | 77 | */ |
| 63 | - public function getBrandSizeToCategories() | |
| 64 | - { | |
| 65 | - return $this->hasMany(BrandSizeToCategory::className(), ['brand_size_id' => 'id']); | |
| 66 | - } | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * @return \yii\db\ActiveQuery | |
| 70 | - */ | |
| 71 | 78 | public function getCategories() |
| 72 | 79 | { |
| 73 | 80 | return $this->hasMany(Category::className(), ['id' => 'category_id'])->viaTable('brand_size_to_category', ['brand_size_id' => 'id']); | ... | ... |
views/brand-size/_form.php
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -use yii\helpers\Html; | |
| 4 | -use yii\widgets\ActiveForm; | |
| 5 | - | |
| 6 | -/* @var $this yii\web\View */ | |
| 7 | -/* @var $model artweb\artbox\ecommerce\models\BrandSize */ | |
| 8 | -/* @var $form yii\widgets\ActiveForm */ | |
| 2 | + | |
| 3 | + use artweb\artbox\ecommerce\models\BrandSize; | |
| 4 | + use yii\helpers\Html; | |
| 5 | + use yii\helpers\Url; | |
| 6 | + use yii\web\View; | |
| 7 | + use yii\widgets\ActiveForm; | |
| 8 | + use artweb\artbox\components\artboximage\ArtboxImageHelper; | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * @var View $this | |
| 12 | + * @var BrandSize $model | |
| 13 | + * @var ActiveForm $form | |
| 14 | + */ | |
| 9 | 15 | ?> |
| 10 | 16 | |
| 11 | 17 | <div class="brand-size-form"> |
| 12 | - | |
| 18 | + | |
| 13 | 19 | <?php $form = ActiveForm::begin(); ?> |
| 20 | + | |
| 21 | + <?= $form->field($model, 'brand_id') | |
| 22 | + ->textInput() ?> | |
| 23 | + | |
| 24 | + <?= $form->field($model, 'image') | |
| 25 | + ->widget( | |
| 26 | + \kartik\file\FileInput::className(), | |
| 27 | + [ | |
| 28 | + 'language' => 'ru', | |
| 29 | + 'options' => [ | |
| 30 | + 'accept' => 'image/*', | |
| 31 | + 'multiple' => false, | |
| 32 | + 'deleteurl' => $model->isNewRecord ? false : Url::to( | |
| 33 | + [ | |
| 34 | + '/ecommerce/manage/delete-size', | |
| 35 | + 'id' => $model->id, | |
| 36 | + ] | |
| 37 | + ), | |
| 38 | + 'class' => $model->isNewRecord ? '' : 'artbox-delete-file', | |
| 39 | + ], | |
| 40 | + 'pluginOptions' => [ | |
| 41 | + 'allowedFileExtensions' => [ | |
| 42 | + 'jpg', | |
| 43 | + 'gif', | |
| 44 | + 'png', | |
| 45 | + ], | |
| 46 | + 'initialPreview' => !empty( | |
| 47 | + $model->getBehavior('image') | |
| 48 | + ->getImageUrl(0, false) | |
| 49 | + ) ? ArtboxImageHelper::getImage( | |
| 50 | + $model->getBehavior('image')->imageUrl, | |
| 51 | + 'list' | |
| 52 | + ) : '', | |
| 53 | + 'initialPreviewShowDelete' => false, | |
| 54 | + 'overwriteInitial' => true, | |
| 55 | + 'showRemove' => true, | |
| 56 | + 'showUpload' => false, | |
| 57 | + 'showClose' => false, | |
| 58 | + 'previewFileType' => 'image', | |
| 59 | + ], | |
| 60 | + ] | |
| 61 | + ); ?> | |
| 14 | 62 | |
| 15 | - <?= $form->field($model, 'brand_id')->textInput() ?> | |
| 16 | - | |
| 17 | - <?= $form->field($model, 'image')->textInput(['maxlength' => true]) ?> | |
| 18 | - | |
| 19 | - <div class="form-group"> | |
| 20 | - <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
| 21 | - </div> | |
| 22 | - | |
| 63 | + <div class="form-group"> | |
| 64 | + <?= Html::submitButton( | |
| 65 | + $model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), | |
| 66 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
| 67 | + ) ?> | |
| 68 | + </div> | |
| 69 | + | |
| 23 | 70 | <?php ActiveForm::end(); ?> |
| 24 | 71 | |
| 25 | 72 | </div> | ... | ... |