- <?php
-
-
-
- namespace producer\controllers;
-
- use common\helpers\GlobalParam;
- use common\models\Producer;
-
- class SiteController extends ProducerBaseController
- {
-
-
-
- public function behaviors()
- {
- return [];
- }
-
- public function actions()
- {
- return [
- 'captcha' => [
- 'class' => 'yii\captcha\CaptchaAction',
- 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
- ],
- ];
- }
-
-
-
- public function actionError()
- {
- $exception = Yii::$app->errorHandler->exception;
-
- if ($exception !== null) {
- if ($exception->getMessage() == 'Producteur introuvable') {
- Yii::$app->getResponse()->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/error', 'producer_not_found' => true]))->send();
- return;
- } else {
- return $this->render('error', ['exception' => $exception]);
- }
- }
- }
-
-
-
- public function actionIndex()
- {
-
- $dataProviderPointsSale = new ActiveDataProvider([
- 'query' => PointSale::find()
- ->where([
- 'id_producer' => $this->getProducer()->id,
- 'restricted_access' => 0
- ]),
- 'pagination' => [
- 'pageSize' => 50,
- ],
- 'sort' => false,
- ]);
-
-
- $queryProducts = Product::find()
- ->andWhere([
- 'id_producer' => $this->getProducer()->id,
- 'active' => true
- ])
- ->orderBy('order ASC') ;
- $dataProviderProducts = new ActiveDataProvider([
- 'query' => $queryProducts,
- 'pagination' => [
- 'pageSize' => 50,
- ],
- 'sort' => false,
- ]);
-
- $products = $queryProducts->all() ;
-
- $hasProductPhoto = false ;
- $hasProductWeight = false ;
-
- foreach($products as $product) {
- if(strlen($product->photo) > 0) {
- $hasProductPhoto = true ;
- }
- if($product->weight && $product->weight > 0) {
- $hasProductWeight = true ;
- }
- }
-
- return $this->render('index', [
- 'dataProviderPointsSale' => $dataProviderPointsSale,
- 'dataProviderProducts' => $dataProviderProducts,
- 'hasProductPhoto' => $hasProductPhoto,
- 'hasProductWeight' => $hasProductWeight
- ]);
- }
-
-
-
- public function actionContact()
- {
- $model = new ContactForm();
- $producer = $this->getProducer();
-
- if ($model->load(Yii::$app->request->post()) && $model->validate()) {
- $isSent = false ;
- if (is_array($producer->contact)) {
- $email = '' ;
- $contact = $producer->getMainContact() ;
- if($contact) {
- $email = $contact->email ;
- }
-
- if(strlen($email) && $model->sendEmail($email)) {
- $isSent = true ;
- }
- }
-
- if($isSent) {
- Yii::$app->session->setFlash('success', 'Votre message a bien été envoyé.');
- }
- else {
- Yii::$app->session->setFlash('error', 'Il y a eu une erreur lors de l\'envoi de votre message.');
- }
-
- return $this->refresh();
- } else {
- return $this->render('contact', [
- 'model' => $model,
- ]);
- }
- }
-
-
-
- public function actionBookmarks($action)
- {
- $producer = $this->getProducer();
- $userProducer = UserProducer::find()
- ->where([
- 'id_user' => User::getCurrentId(),
- 'id_producer' => $producer->id
- ])
- ->one();
-
- if (!$userProducer) {
- $userProducer = Producer::addUser(User::getCurrentId(), $producer->id);
- }
-
- if ($userProducer) {
- if ($action == 'add') {
- $userProducer->bookmark = 1;
- Yii::$app->session->setFlash('success', 'Le producteur <strong>' . Html::encode($producer->name) . '</strong> vient d\'être ajouté à vos favoris.');
- } else {
- $userProducer->bookmark = 0;
- Yii::$app->session->setFlash('success', 'Le producteur <strong>' . Html::encode($producer->name) . '</strong> vient d\'être supprimé de vos favoris.');
- }
- $userProducer->save();
- }
-
- $this->redirect(['site/index']);
- }
-
-
-
- public function actionMentions()
- {
- $producer = GlobalParam::getCurrentProducer();
-
- if (!strlen($producer->mentions)) {
- throw new \yii\base\UserException('Mentions légales introuvables.');
- }
-
- return $this->render('mentions', [
- 'producer' => $producer
- ]);
- }
-
-
-
- public function actionGcs()
- {
- $producer = GlobalParam::getCurrentProducer();
-
- if (!strlen($producer->gcs)) {
- throw new \yii\base\UserException('Conditions générales de vente introuvables.');
- }
-
- return $this->render('gcs', [
- 'producer' => $producer
- ]);
- }
- }
-
- ?>
|