Commit 612a4ea17131a8fe4ebf5ec1c25d25a7c6489839
1 parent
2e96ba93
big commti
Showing
13 changed files
with
99 additions
and
95 deletions
Show diff stats
backend/controllers/BrandController.php
@@ -80,20 +80,7 @@ class BrandController extends Controller | @@ -80,20 +80,7 @@ class BrandController extends Controller | ||
80 | public function actionCreate() | 80 | public function actionCreate() |
81 | { | 81 | { |
82 | $model = new Brand(); | 82 | $model = new Brand(); |
83 | - if ($model->load(Yii::$app->request->post())) { | ||
84 | - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { | ||
85 | - $model->image = $image->name; | ||
86 | - } | ||
87 | - if ($model->save() && $image) { | ||
88 | - | ||
89 | - $imgDir = Yii::getAlias('@storage/brand/'); | ||
90 | - | ||
91 | - if(!is_dir($imgDir)) { | ||
92 | - mkdir($imgDir, 0755, true); | ||
93 | - } | ||
94 | - | ||
95 | - $image->saveAs(Yii::getAlias('@storage/brand/' . $image->name)); | ||
96 | - } | 83 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { |
97 | 84 | ||
98 | return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->brand_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams)); | 85 | return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->brand_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams)); |
99 | } else { | 86 | } else { |
@@ -113,20 +100,7 @@ class BrandController extends Controller | @@ -113,20 +100,7 @@ class BrandController extends Controller | ||
113 | { | 100 | { |
114 | $model = $this->findModel($id); | 101 | $model = $this->findModel($id); |
115 | 102 | ||
116 | - if ($model->load(Yii::$app->request->post())) { | ||
117 | - if ( ($image = UploadedFile::getInstance($model, 'image')) ) { | ||
118 | - $model->image = $image->name; | ||
119 | - } | ||
120 | - if ($model->save() && $image) { | ||
121 | - | ||
122 | - $imgDir = Yii::getAlias('@storage/brands/'); | ||
123 | - | ||
124 | - if(!is_dir($imgDir)) { | ||
125 | - mkdir($imgDir, 0755, true); | ||
126 | - } | ||
127 | - | ||
128 | - $image->saveAs(Yii::getAlias('@storage/brands/' . $image->name)); | ||
129 | - } | 103 | + if ($model->load(Yii::$app->request->post()) && $model->save()) { |
130 | 104 | ||
131 | return $this->redirect(['view', 'id' => $model->brand_id]); | 105 | return $this->redirect(['view', 'id' => $model->brand_id]); |
132 | } else { | 106 | } else { |
backend/views/event/_form.php
@@ -67,7 +67,7 @@ use mihaildev\elfinder\ElFinder; | @@ -67,7 +67,7 @@ use mihaildev\elfinder\ElFinder; | ||
67 | ], | 67 | ], |
68 | 'pluginOptions' => [ | 68 | 'pluginOptions' => [ |
69 | 'allowedFileExtensions' => ['jpg', 'gif', 'png'], | 69 | 'allowedFileExtensions' => ['jpg', 'gif', 'png'], |
70 | - 'initialPreview' => !empty($model->bannerUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->bannerUrl, 'list') : '', | 70 | + 'initialPreview' => !empty($model->getImageUrl('banner')) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->getImageUrl('banner'), 'list') : '', |
71 | 'overwriteInitial' => true, | 71 | 'overwriteInitial' => true, |
72 | 'showRemove' => false, | 72 | 'showRemove' => false, |
73 | 'showUpload' => false, | 73 | 'showUpload' => false, |
backend/views/slider-image/_form.php
@@ -12,6 +12,7 @@ use kartik\date\DatePicker; | @@ -12,6 +12,7 @@ use kartik\date\DatePicker; | ||
12 | /* @var $form yii\widgets\ActiveForm */ | 12 | /* @var $form yii\widgets\ActiveForm */ |
13 | ?> | 13 | ?> |
14 | 14 | ||
15 | + | ||
15 | <div class="slider-image-form"> | 16 | <div class="slider-image-form"> |
16 | 17 | ||
17 | <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> | 18 | <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> |
common/behaviors/SaveImgBehavior.php
@@ -14,8 +14,8 @@ use yii\web\UploadedFile; | @@ -14,8 +14,8 @@ use yii\web\UploadedFile; | ||
14 | class SaveImgBehavior extends Behavior | 14 | class SaveImgBehavior extends Behavior |
15 | { | 15 | { |
16 | 16 | ||
17 | - | ||
18 | - public $directory; | 17 | + public $fields; |
18 | + //public $directory; | ||
19 | 19 | ||
20 | public function events() | 20 | public function events() |
21 | { | 21 | { |
@@ -27,57 +27,62 @@ class SaveImgBehavior extends Behavior | @@ -27,57 +27,62 @@ class SaveImgBehavior extends Behavior | ||
27 | 27 | ||
28 | public function beforeUpdate($event) | 28 | public function beforeUpdate($event) |
29 | { | 29 | { |
30 | + foreach($this->fields as $field){ | ||
31 | + if ( ($image = UploadedFile::getInstance($this->owner, $field['name'])) ) { | ||
32 | + $this->owner->image = $image->name; | ||
33 | + } | ||
30 | 34 | ||
35 | + if(!$this->owner->image){ | ||
36 | + $this->owner->image = $this->owner->getOldAttribute($field['name']); | ||
37 | + } | ||
31 | 38 | ||
32 | - if ( ($image = UploadedFile::getInstance($this->owner, 'image')) ) { | ||
33 | - $this->owner->image = $image->name; | ||
34 | - } | ||
35 | 39 | ||
36 | - if(!$this->owner->image){ | ||
37 | - $this->owner->image = $this->owner->getOldAttribute('image'); | ||
38 | - } | 40 | + if ($image) { |
41 | + $imgDir = \Yii::getAlias('@storage/'.$field['directory'].'/'); | ||
39 | 42 | ||
43 | + if(!is_dir($imgDir)) { | ||
44 | + mkdir($imgDir, 0755, true); | ||
45 | + } | ||
40 | 46 | ||
41 | - if ($image) { | ||
42 | - $imgDir = \Yii::getAlias('@storage/'.$this->directory.'/'); | ||
43 | - | ||
44 | - if(!is_dir($imgDir)) { | ||
45 | - mkdir($imgDir, 0755, true); | 47 | + $image->saveAs(\Yii::getAlias('@storage/'.$field['directory'].'/' . $image->name)); |
46 | } | 48 | } |
47 | - | ||
48 | - $image->saveAs(\Yii::getAlias('@storage/'.$this->directory.'/' . $image->name)); | ||
49 | } | 49 | } |
50 | + | ||
51 | + | ||
52 | + | ||
50 | } | 53 | } |
51 | 54 | ||
52 | 55 | ||
53 | public function beforeInsert($event) | 56 | public function beforeInsert($event) |
54 | { | 57 | { |
58 | + foreach($this->fields as $field){ | ||
55 | 59 | ||
60 | + if ( ($image = UploadedFile::getInstance($this->owner, $field['name'])) ) { | ||
61 | + $this->owner->image = $image->name; | ||
62 | + } | ||
56 | 63 | ||
57 | - if ( ($image = UploadedFile::getInstance($this->owner, 'image')) ) { | ||
58 | - $this->owner->image = $image->name; | ||
59 | - } | ||
60 | 64 | ||
61 | 65 | ||
66 | + if ($image) { | ||
67 | + $imgDir = \Yii::getAlias('@storage/'.$field['directory'].'/'); | ||
62 | 68 | ||
63 | - if ($image) { | ||
64 | - $imgDir = \Yii::getAlias('@storage/'.$this->directory.'/'); | 69 | + if(!is_dir($imgDir)) { |
70 | + mkdir($imgDir, 0755, true); | ||
71 | + } | ||
65 | 72 | ||
66 | - if(!is_dir($imgDir)) { | ||
67 | - mkdir($imgDir, 0755, true); | 73 | + $image->saveAs(\Yii::getAlias('@storage/'.$field['directory'].'/' . $image->name)); |
68 | } | 74 | } |
69 | - | ||
70 | - $image->saveAs(\Yii::getAlias('@storage/'.$this->directory.'/' . $image->name)); | ||
71 | } | 75 | } |
72 | } | 76 | } |
73 | 77 | ||
74 | - | ||
75 | - | ||
76 | - public function getImageFile() { | ||
77 | - return empty($this->owner->image) ? null : '/storage/'.$this->directory.'/'. $this->owner->image; | 78 | + public function getImageFile($image = 'image') { |
79 | + return empty($this->owner->$image) ? null : '/storage/'.$this->fields[0]['directory'].'/'. $this->owner->$image; | ||
78 | } | 80 | } |
79 | 81 | ||
80 | - public function getImageUrl() { | ||
81 | - return empty($this->owner->image) ? null : '/storage/'.$this->directory.'/'. $this->owner->image; | 82 | + public function getImageUrl($image = 'image') { |
83 | + return empty($this->owner->$image) ? null : '/storage/'.$this->fields[0]['directory'].'/'. $this->owner->$image; | ||
82 | } | 84 | } |
85 | + | ||
86 | + | ||
87 | + | ||
83 | } | 88 | } |
84 | \ No newline at end of file | 89 | \ No newline at end of file |
common/models/Articles.php
@@ -44,7 +44,9 @@ class Articles extends \yii\db\ActiveRecord | @@ -44,7 +44,9 @@ class Articles extends \yii\db\ActiveRecord | ||
44 | return [ | 44 | return [ |
45 | [ | 45 | [ |
46 | 'class' => SaveImgBehavior::className(), | 46 | 'class' => SaveImgBehavior::className(), |
47 | - 'directory' => 'articles' | 47 | + 'fields' => [ |
48 | + ['name'=>'image','directory' => 'articles' ] | ||
49 | + ] | ||
48 | ], | 50 | ], |
49 | 'slug' => [ | 51 | 'slug' => [ |
50 | 'class' => 'common\behaviors\Slug', | 52 | 'class' => 'common\behaviors\Slug', |
common/models/Banner.php
@@ -37,7 +37,9 @@ class Banner extends \yii\db\ActiveRecord | @@ -37,7 +37,9 @@ class Banner extends \yii\db\ActiveRecord | ||
37 | return [ | 37 | return [ |
38 | [ | 38 | [ |
39 | 'class' => SaveImgBehavior::className(), | 39 | 'class' => SaveImgBehavior::className(), |
40 | - 'directory' => 'banner' | 40 | + 'fields' => [ |
41 | + ['name'=>'image','directory' => 'banner' ] | ||
42 | + ] | ||
41 | ], | 43 | ], |
42 | ]; | 44 | ]; |
43 | } | 45 | } |
common/models/Bg.php
@@ -21,7 +21,9 @@ class Bg extends \yii\db\ActiveRecord | @@ -21,7 +21,9 @@ class Bg extends \yii\db\ActiveRecord | ||
21 | return [ | 21 | return [ |
22 | [ | 22 | [ |
23 | 'class' => SaveImgBehavior::className(), | 23 | 'class' => SaveImgBehavior::className(), |
24 | - 'directory' => 'bg' | 24 | + 'fields' => [ |
25 | + ['name'=>'image','directory' => 'bg' ] | ||
26 | + ] | ||
25 | ], | 27 | ], |
26 | ]; | 28 | ]; |
27 | } | 29 | } |
common/models/Event.php
@@ -47,7 +47,10 @@ class Event extends \yii\db\ActiveRecord | @@ -47,7 +47,10 @@ class Event extends \yii\db\ActiveRecord | ||
47 | return [ | 47 | return [ |
48 | [ | 48 | [ |
49 | 'class' => SaveImgBehavior::className(), | 49 | 'class' => SaveImgBehavior::className(), |
50 | - 'directory' => 'event' | 50 | + 'fields' => [ |
51 | + ['name'=>'imageUpload','directory' => 'event' ], | ||
52 | + ['name'=>'banner','directory' => 'event' ], | ||
53 | + ] | ||
51 | ], | 54 | ], |
52 | TimestampBehavior::className(), | 55 | TimestampBehavior::className(), |
53 | 'slug' => [ | 56 | 'slug' => [ |
@@ -131,17 +134,10 @@ class Event extends \yii\db\ActiveRecord | @@ -131,17 +134,10 @@ class Event extends \yii\db\ActiveRecord | ||
131 | } | 134 | } |
132 | 135 | ||
133 | 136 | ||
134 | - public function getBannerFile() { | ||
135 | - return empty($this->image) ? null : Yii::getAlias('@imagesDir/event/'. $this->banner); | ||
136 | - } | ||
137 | - | ||
138 | 137 | ||
139 | public function getProducts(){ | 138 | public function getProducts(){ |
140 | return $this->hasMany(Product::className(),['product_id' => 'product_id'] )->viaTable('events_to_products', ['event_id' => 'event_id']); | 139 | return $this->hasMany(Product::className(),['product_id' => 'product_id'] )->viaTable('events_to_products', ['event_id' => 'event_id']); |
141 | } | 140 | } |
142 | 141 | ||
143 | - public function getBannerUrl() | ||
144 | - { | ||
145 | - return empty($this->image) ? null : Yii::getAlias('@imagesUrl/event/' . $this->banner); | ||
146 | - } | 142 | + |
147 | } | 143 | } |
common/models/SliderImage.php
@@ -39,7 +39,9 @@ class SliderImage extends \yii\db\ActiveRecord | @@ -39,7 +39,9 @@ class SliderImage extends \yii\db\ActiveRecord | ||
39 | return [ | 39 | return [ |
40 | [ | 40 | [ |
41 | 'class' => SaveImgBehavior::className(), | 41 | 'class' => SaveImgBehavior::className(), |
42 | - 'directory' => 'slider' | 42 | + 'fields' => [ |
43 | + ['name'=>'image','directory' => 'slider' ] | ||
44 | + ] | ||
43 | ] | 45 | ] |
44 | ]; | 46 | ]; |
45 | } | 47 | } |
common/modules/product/models/Brand.php
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | namespace common\modules\product\models; | 3 | namespace common\modules\product\models; |
4 | 4 | ||
5 | +use common\behaviors\SaveImgBehavior; | ||
5 | use common\behaviors\Slug; | 6 | use common\behaviors\Slug; |
6 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; | 7 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; |
7 | use yii\web\UploadedFile; | 8 | use yii\web\UploadedFile; |
@@ -40,9 +41,19 @@ class Brand extends \yii\db\ActiveRecord | @@ -40,9 +41,19 @@ class Brand extends \yii\db\ActiveRecord | ||
40 | } | 41 | } |
41 | 42 | ||
42 | 43 | ||
44 | + /** | ||
45 | + * @inheritdoc | ||
46 | + */ | ||
47 | + | ||
43 | public function behaviors() | 48 | public function behaviors() |
44 | { | 49 | { |
45 | return [ | 50 | return [ |
51 | + [ | ||
52 | + 'class' => SaveImgBehavior::className(), | ||
53 | + 'fields' => [ | ||
54 | + ['name'=>'image','directory' => 'brands' ] | ||
55 | + ] | ||
56 | + ], | ||
46 | 'slug' => [ | 57 | 'slug' => [ |
47 | 'class' => 'common\behaviors\Slug', | 58 | 'class' => 'common\behaviors\Slug', |
48 | 'in_attribute' => 'name', | 59 | 'in_attribute' => 'name', |
@@ -101,11 +112,11 @@ class Brand extends \yii\db\ActiveRecord | @@ -101,11 +112,11 @@ class Brand extends \yii\db\ActiveRecord | ||
101 | } | 112 | } |
102 | 113 | ||
103 | public function getImageFile() { | 114 | public function getImageFile() { |
104 | - return empty($this->image) ? null : Yii::getAlias('@imagesDir/brands/'. $this->image); | 115 | + return empty($this->image) ? null : '/storage/brands/'. $this->image; |
105 | } | 116 | } |
106 | 117 | ||
107 | - public function getImageUrl() | ||
108 | - { | ||
109 | - return empty($this->image) ? null : Yii::getAlias('@imagesUrl/brands/' . $this->image); | 118 | + public function getImageUrl() { |
119 | + return empty($this->image) ? null : '/storage/brands/'. $this->image; | ||
110 | } | 120 | } |
121 | + | ||
111 | } | 122 | } |
common/modules/product/models/Product.php
@@ -303,20 +303,24 @@ class Product extends \yii\db\ActiveRecord | @@ -303,20 +303,24 @@ class Product extends \yii\db\ActiveRecord | ||
303 | parent::afterSave($insert, $changedAttributes); | 303 | parent::afterSave($insert, $changedAttributes); |
304 | 304 | ||
305 | 305 | ||
306 | - $this->unlinkAll('categories', true); | ||
307 | - $this->unlinkAll('options',true); | ||
308 | - | 306 | + if(!empty($this->categories)){ |
307 | + $categories = Category::findAll($this->categories); | ||
308 | + $this->unlinkAll('categories', true); | ||
309 | + foreach($categories as $category){ | ||
310 | + $this->link('categories', $category); | ||
311 | + } | ||
312 | + } | ||
309 | 313 | ||
310 | - $categories = Category::findAll($this->categories); | ||
311 | - $options = TaxOption::findAll($this->options); | ||
312 | 314 | ||
313 | - foreach($options as $option){ | ||
314 | - $this->link('options', $option); | ||
315 | - } | ||
316 | - foreach($categories as $category){ | ||
317 | - $this->link('categories', $category); | 315 | + if(!empty($this->options)){ |
316 | + $options = TaxOption::findAll($this->options); | ||
317 | + $this->unlinkAll('options',true); | ||
318 | + foreach($options as $option){ | ||
319 | + $this->link('options', $option); | ||
320 | + } | ||
318 | } | 321 | } |
319 | 322 | ||
323 | + | ||
320 | if (!empty($this->_variants)) { | 324 | if (!empty($this->_variants)) { |
321 | $todel = []; | 325 | $todel = []; |
322 | foreach ($this->variants ?: [] as $_variant) { | 326 | foreach ($this->variants ?: [] as $_variant) { |
frontend/web/css/css_header.css
@@ -14521,3 +14521,6 @@ ul.product-special li.promo div{ | @@ -14521,3 +14521,6 @@ ul.product-special li.promo div{ | ||
14521 | position: relative; | 14521 | position: relative; |
14522 | overflow: hidden; | 14522 | overflow: hidden; |
14523 | } | 14523 | } |
14524 | +.btn-fixeds{ | ||
14525 | + z-index: 1000; | ||
14526 | +} | ||
14524 | \ No newline at end of file | 14527 | \ No newline at end of file |
frontend/widgets/views/slider.php
@@ -6,22 +6,27 @@ use yii\helpers\Html; | @@ -6,22 +6,27 @@ use yii\helpers\Html; | ||
6 | use yii\helpers\Url; | 6 | use yii\helpers\Url; |
7 | use yii\web\View; | 7 | use yii\web\View; |
8 | use frontend\assets\FlipclockAsset; | 8 | use frontend\assets\FlipclockAsset; |
9 | +FlipclockAsset::register($this); | ||
9 | ?> | 10 | ?> |
10 | 11 | ||
11 | 12 | ||
12 | <div id="<?=$title?>" class="owl-carousel owl-theme"> | 13 | <div id="<?=$title?>" class="owl-carousel owl-theme"> |
13 | <?php foreach($slider->sliderImage as $image): | 14 | <?php foreach($slider->sliderImage as $image): |
14 | 15 | ||
15 | - if(!empty($image->end_at) && strtotime($row->end_at) > strtotime(date("Y-m-d"))){ | 16 | + |
17 | + ?> | ||
18 | + <div class="item"> | ||
19 | +<?php | ||
20 | + if(!empty($image->end_at) && strtotime($image->end_at) > strtotime(date("Y-m-d"))){ | ||
16 | ?> | 21 | ?> |
17 | - <div class="clock_style clock_<?= $row->primaryKey ?>"></div> | 22 | + <div class="clock_style clock_<?= $image->primaryKey ?>"></div> |
18 | <script type="text/javascript"> | 23 | <script type="text/javascript"> |
19 | var clock; | 24 | var clock; |
20 | 25 | ||
21 | $(document).ready(function() { | 26 | $(document).ready(function() { |
22 | var clock; | 27 | var clock; |
23 | 28 | ||
24 | - clock = $('.clock_<?= $row->primaryKey ?>').FlipClock({ | 29 | + clock = $('.clock_<?= $image->primaryKey ?>').FlipClock({ |
25 | clockFace: 'DailyCounter', | 30 | clockFace: 'DailyCounter', |
26 | language: 'ru', | 31 | language: 'ru', |
27 | classes: { | 32 | classes: { |
@@ -36,7 +41,7 @@ use frontend\assets\FlipclockAsset; | @@ -36,7 +41,7 @@ use frontend\assets\FlipclockAsset; | ||
36 | }, | 41 | }, |
37 | }); | 42 | }); |
38 | 43 | ||
39 | - clock.setTime(<?= strtotime($row->end_at) - strtotime(date("Y-m-d H:i:s"))?>); | 44 | + clock.setTime(<?= strtotime($image->end_at) - strtotime(date("Y-m-d H:i:s"))?>); |
40 | clock.setCountdown(true); | 45 | clock.setCountdown(true); |
41 | clock.start(); | 46 | clock.start(); |
42 | 47 | ||
@@ -44,11 +49,8 @@ use frontend\assets\FlipclockAsset; | @@ -44,11 +49,8 @@ use frontend\assets\FlipclockAsset; | ||
44 | </script> | 49 | </script> |
45 | 50 | ||
46 | 51 | ||
47 | - <?php | ||
48 | - } | ||
49 | - | ||
50 | - ?> | ||
51 | - <div class="item"> | 52 | + <?php |
53 | + }?> | ||
52 | <?= Html::img(ArtboxImageHelper::getImageSrc($image->imageUrl,'slider'))?> | 54 | <?= Html::img(ArtboxImageHelper::getImageSrc($image->imageUrl,'slider'))?> |
53 | </div> | 55 | </div> |
54 | 56 |