diff --git a/backend/views/event/_form.php b/backend/views/event/_form.php index 8acfb7c..9dae734 100755 --- a/backend/views/event/_form.php +++ b/backend/views/event/_form.php @@ -90,6 +90,10 @@ use mihaildev\elfinder\ElFinder; field($model, 'status')->checkbox() ?> + field($model, 'sale')->checkbox() ?> + + field($model, 'percent')->textInput() ?> +
diff --git a/common/models/Event.php b/common/models/Event.php index 81ba40e..1d34519 100755 --- a/common/models/Event.php +++ b/common/models/Event.php @@ -5,6 +5,8 @@ use common\behaviors\SaveImgBehavior; use common\modules\product\models\Product; use Yii; use yii\behaviors\TimestampBehavior; +use yii\helpers\ArrayHelper; + /** * This is the model class for table "event". * @@ -89,7 +91,7 @@ class Event extends \yii\db\ActiveRecord { return [ [['body', 'seo_text'], 'string'], - [['created_at', 'updated_at' ], 'integer'], + [['created_at', 'updated_at','percent','sale' ], 'integer'], [['name', 'alias', 'image', 'meta_title', 'description', 'h1','end_at','banner'], 'string', 'max' => 255], [['name','body'], 'required'], [['imageUpload'], 'safe'], @@ -118,6 +120,8 @@ class Event extends \yii\db\ActiveRecord 'end_at' => Yii::t('app', 'end_at'), 'status' => Yii::t('app', 'Статус акции'), 'products_file' => Yii::t('app', 'Загрузка файла'), + 'sale' => Yii::t('app', 'Распродажа'), + 'percent' => Yii::t('app', 'Процент'), ]; } @@ -139,5 +143,9 @@ class Event extends \yii\db\ActiveRecord return $this->hasMany(Product::className(),['product_id' => 'product_id'] )->viaTable('events_to_products', ['event_id' => 'event_id']); } + public static function getSaleEvents(){ + return ArrayHelper::toArray(self::find()->select('percent')->distinct('percent')->where('sale=true AND percent IS NOT NULL')->all()); + } + } diff --git a/frontend/controllers/EventController.php b/frontend/controllers/EventController.php index 8880598..4fc4b55 100755 --- a/frontend/controllers/EventController.php +++ b/frontend/controllers/EventController.php @@ -39,6 +39,18 @@ class EventController extends Controller ]); } + public function actionSale($percent) + { + + $model = Event::find()->where(['percent'=>$percent])->one(); + $productProvider = new ActiveDataProvider([ + 'query' => $model->getProducts(), + ]); + return $this->render('show', [ + 'productProvider' => $productProvider, + 'model' => $model, + ]); + } protected function findModel($alias) { diff --git a/frontend/views/layouts/main-menu.php b/frontend/views/layouts/main-menu.php index 2f97a2e..10e4ab0 100644 --- a/frontend/views/layouts/main-menu.php +++ b/frontend/views/layouts/main-menu.php @@ -5,6 +5,8 @@ use yii\helpers\Html; use yii\helpers\Url; $models = Category::find()->all(); + + ?> diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index ff5b487..981c40f 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -11,6 +11,8 @@ use common\models\Basket; use yii\web\View; use yii\widgets\Breadcrumbs; use frontend\widgets\Seo; +use common\models\Event; + AppAsset::register($this); ?> beginPage() ?> @@ -84,10 +86,9 @@ use frontend\widgets\Seo; Распродажа
-- libgit2 0.21.4