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
common/models/Event.php
... | ... | @@ -5,6 +5,8 @@ use common\behaviors\SaveImgBehavior; |
5 | 5 | use common\modules\product\models\Product; |
6 | 6 | use Yii; |
7 | 7 | use yii\behaviors\TimestampBehavior; |
8 | +use yii\helpers\ArrayHelper; | |
9 | + | |
8 | 10 | /** |
9 | 11 | * This is the model class for table "event". |
10 | 12 | * |
... | ... | @@ -89,7 +91,7 @@ class Event extends \yii\db\ActiveRecord |
89 | 91 | { |
90 | 92 | return [ |
91 | 93 | [['body', 'seo_text'], 'string'], |
92 | - [['created_at', 'updated_at' ], 'integer'], | |
94 | + [['created_at', 'updated_at','percent','sale' ], 'integer'], | |
93 | 95 | [['name', 'alias', 'image', 'meta_title', 'description', 'h1','end_at','banner'], 'string', 'max' => 255], |
94 | 96 | [['name','body'], 'required'], |
95 | 97 | [['imageUpload'], 'safe'], |
... | ... | @@ -118,6 +120,8 @@ class Event extends \yii\db\ActiveRecord |
118 | 120 | 'end_at' => Yii::t('app', 'end_at'), |
119 | 121 | 'status' => Yii::t('app', 'Статус акции'), |
120 | 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 | 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 | 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 | 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 | 11 | use yii\web\View; |
12 | 12 | use yii\widgets\Breadcrumbs; |
13 | 13 | use frontend\widgets\Seo; |
14 | +use common\models\Event; | |
15 | + | |
14 | 16 | AppAsset::register($this); |
15 | 17 | ?> |
16 | 18 | <?php $this->beginPage() ?> |
... | ... | @@ -84,10 +86,9 @@ use frontend\widgets\Seo; |
84 | 86 | <a href="#" class="new_cat_link">Распродажа</a> |
85 | 87 | <div> |
86 | 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 | 92 | </ul> |
92 | 93 | </div> |
93 | 94 | </li> | ... | ... |