Commit 9ec47b63d8c5e11f9c6158f286376c047aeabd8f
1 parent
573db3b2
big commti
Showing
5 changed files
with
32 additions
and
5 deletions
Show diff stats
backend/views/event/_form.php
@@ -90,6 +90,10 @@ use mihaildev\elfinder\ElFinder; | @@ -90,6 +90,10 @@ use mihaildev\elfinder\ElFinder; | ||
90 | 90 | ||
91 | <?= $form->field($model, 'status')->checkbox() ?> | 91 | <?= $form->field($model, 'status')->checkbox() ?> |
92 | 92 | ||
93 | + <?= $form->field($model, 'sale')->checkbox() ?> | ||
94 | + | ||
95 | + <?= $form->field($model, 'percent')->textInput() ?> | ||
96 | + | ||
93 | 97 | ||
94 | 98 | ||
95 | <div class="form-group"> | 99 | <div class="form-group"> |
common/models/Event.php
@@ -5,6 +5,8 @@ use common\behaviors\SaveImgBehavior; | @@ -5,6 +5,8 @@ use common\behaviors\SaveImgBehavior; | ||
5 | use common\modules\product\models\Product; | 5 | use common\modules\product\models\Product; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\behaviors\TimestampBehavior; | 7 | use yii\behaviors\TimestampBehavior; |
8 | +use yii\helpers\ArrayHelper; | ||
9 | + | ||
8 | /** | 10 | /** |
9 | * This is the model class for table "event". | 11 | * This is the model class for table "event". |
10 | * | 12 | * |
@@ -89,7 +91,7 @@ class Event extends \yii\db\ActiveRecord | @@ -89,7 +91,7 @@ class Event extends \yii\db\ActiveRecord | ||
89 | { | 91 | { |
90 | return [ | 92 | return [ |
91 | [['body', 'seo_text'], 'string'], | 93 | [['body', 'seo_text'], 'string'], |
92 | - [['created_at', 'updated_at' ], 'integer'], | 94 | + [['created_at', 'updated_at','percent','sale' ], 'integer'], |
93 | [['name', 'alias', 'image', 'meta_title', 'description', 'h1','end_at','banner'], 'string', 'max' => 255], | 95 | [['name', 'alias', 'image', 'meta_title', 'description', 'h1','end_at','banner'], 'string', 'max' => 255], |
94 | [['name','body'], 'required'], | 96 | [['name','body'], 'required'], |
95 | [['imageUpload'], 'safe'], | 97 | [['imageUpload'], 'safe'], |
@@ -118,6 +120,8 @@ class Event extends \yii\db\ActiveRecord | @@ -118,6 +120,8 @@ class Event extends \yii\db\ActiveRecord | ||
118 | 'end_at' => Yii::t('app', 'end_at'), | 120 | 'end_at' => Yii::t('app', 'end_at'), |
119 | 'status' => Yii::t('app', 'Статус акции'), | 121 | 'status' => Yii::t('app', 'Статус акции'), |
120 | 'products_file' => Yii::t('app', 'Загрузка файла'), | 122 | 'products_file' => Yii::t('app', 'Загрузка файла'), |
123 | + 'sale' => Yii::t('app', 'Распродажа'), | ||
124 | + 'percent' => Yii::t('app', 'Процент'), | ||
121 | ]; | 125 | ]; |
122 | } | 126 | } |
123 | 127 | ||
@@ -139,5 +143,9 @@ class Event extends \yii\db\ActiveRecord | @@ -139,5 +143,9 @@ class Event extends \yii\db\ActiveRecord | ||
139 | return $this->hasMany(Product::className(),['product_id' => 'product_id'] )->viaTable('events_to_products', ['event_id' => 'event_id']); | 143 | return $this->hasMany(Product::className(),['product_id' => 'product_id'] )->viaTable('events_to_products', ['event_id' => 'event_id']); |
140 | } | 144 | } |
141 | 145 | ||
146 | + public static function getSaleEvents(){ | ||
147 | + return ArrayHelper::toArray(self::find()->select('percent')->distinct('percent')->where('sale=true AND percent IS NOT NULL')->all()); | ||
148 | + } | ||
149 | + | ||
142 | 150 | ||
143 | } | 151 | } |
frontend/controllers/EventController.php
@@ -39,6 +39,18 @@ class EventController extends Controller | @@ -39,6 +39,18 @@ class EventController extends Controller | ||
39 | ]); | 39 | ]); |
40 | } | 40 | } |
41 | 41 | ||
42 | + public function actionSale($percent) | ||
43 | + { | ||
44 | + | ||
45 | + $model = Event::find()->where(['percent'=>$percent])->one(); | ||
46 | + $productProvider = new ActiveDataProvider([ | ||
47 | + 'query' => $model->getProducts(), | ||
48 | + ]); | ||
49 | + return $this->render('show', [ | ||
50 | + 'productProvider' => $productProvider, | ||
51 | + 'model' => $model, | ||
52 | + ]); | ||
53 | + } | ||
42 | 54 | ||
43 | protected function findModel($alias) | 55 | protected function findModel($alias) |
44 | { | 56 | { |
frontend/views/layouts/main-menu.php
frontend/views/layouts/main.php
@@ -11,6 +11,8 @@ use common\models\Basket; | @@ -11,6 +11,8 @@ use common\models\Basket; | ||
11 | use yii\web\View; | 11 | use yii\web\View; |
12 | use yii\widgets\Breadcrumbs; | 12 | use yii\widgets\Breadcrumbs; |
13 | use frontend\widgets\Seo; | 13 | use frontend\widgets\Seo; |
14 | +use common\models\Event; | ||
15 | + | ||
14 | AppAsset::register($this); | 16 | AppAsset::register($this); |
15 | ?> | 17 | ?> |
16 | <?php $this->beginPage() ?> | 18 | <?php $this->beginPage() ?> |
@@ -84,10 +86,9 @@ use frontend\widgets\Seo; | @@ -84,10 +86,9 @@ use frontend\widgets\Seo; | ||
84 | <a href="#" class="new_cat_link">Распродажа</a> | 86 | <a href="#" class="new_cat_link">Распродажа</a> |
85 | <div> | 87 | <div> |
86 | <ul> | 88 | <ul> |
87 | - <li><a href="#">Скидка -50%</a></li> | ||
88 | - <li><a href="#">Скидка -60%</a></li> | ||
89 | - <li><a href="#">Скидка -30%</a></li> | ||
90 | - <li><a href="#">Скидка -40%</a></li> | 89 | + <?php foreach(Event::getSaleEvents() as $sale):?> |
90 | + <li><?php echo Html::a('Скидка -'.$sale['percent'].'%',Url::to (['event/sale', 'percent' => $sale['percent']])) ?></li> | ||
91 | + <?php endforeach;?> | ||
91 | </ul> | 92 | </ul> |
92 | </div> | 93 | </div> |
93 | </li> | 94 | </li> |