[
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
/*public function actionLogin()
{
//return
}*/
/**
* Affiche et gère les erreurs.
*/
public function actionError()
{
$exception = \Yii::$app->errorHandler->exception;
if ($exception !== null) {
if ($exception->getMessage() == 'Producteur introuvable') {
\Yii::$app->getResponse()->redirect(
$this->getUrlManagerFrontend()->createAbsoluteUrl(['site/error', 'producer_not_found' => true])
)->send();
} else {
return $this->render('error', ['exception' => $exception]);
}
}
}
public function actionIndex()
{
return $this->render('index');
}
public function actionProducts()
{
$productModule = $this->getProductModule();
$productCategoryArray = $this->getProductCategoryModule()->findProductCategories();
$dataProviderProductsByCategories = [];
foreach ($productCategoryArray as $productCategory) {
$dataProviderProductsByCategories[$productCategory->id] = new ActiveDataProvider([
'query' => $productModule->queryProductsByProductCategory($productCategory)->query(),
'pagination' => [
'pageSize' => 500,
],
'sort' => false,
]);
$this->filterProductsPublic($dataProviderProductsByCategories[$productCategory->id]);
}
$queryProducts = Product::find()
->andWhere([
'id_producer' => $this->getProducerCurrent()->id,
'status' => Product::STATUS_ONLINE,
'id_product_category' => null,
])
->with('productPointSale')
->orderBy('order ASC');
$dataProviderProducts = new ActiveDataProvider([
'query' => $queryProducts,
'pagination' => [
'pageSize' => 500,
],
'sort' => false,
]);
$this->filterProductsPublic($dataProviderProducts);
$products = $queryProducts->all();
foreach ($dataProviderProductsByCategories as $dataProvider) {
$products = array_merge(
$products,
$dataProvider->query->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('products', [
'dataProviderProductsByCategories' => $dataProviderProductsByCategories,
'dataProviderProducts' => $dataProviderProducts,
'hasProductPhoto' => $hasProductPhoto,
'hasProductWeight' => $hasProductWeight,
'categories' => $productCategoryArray,
]);
}
public function actionPointsSale()
{
$pointSaleModule = $this->getPointSaleModule();
$dataProviderPointsSale = new ActiveDataProvider([
'query' => $pointSaleModule->queryPointSalesPublic($this->getProducerCurrent()),
'pagination' => [
'pageSize' => 50,
],
'sort' => false,
]);
return $this->render('points-sale', [
'dataProviderPointsSale' => $dataProviderPointsSale,
]);
}
public function filterProductsPublic($dataProviderProducts)
{
$productModule = $this->getProductModule();
$models = $dataProviderProducts->getModels();
foreach($models as $index => $product) {
if(!$productModule->isPublic($product)) {
unset($models[$index]);
}
}
$dataProviderProducts->setModels($models);
}
/**
* Affiche et traite le formulaire de contact dédié aux producteurs.
*/
public function actionContact()
{
$featureModule = $this->getFeatureModule();
if($featureModule->getChecker()->isDisabled(Feature::ALIAS_CONTACT)) {
return $this->redirect(['site/index']);
}
$model = new ContactForm();
$producer = $this->getProducerCurrent();
if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
$isSent = false;
if ($producer->contact_email && strlen($producer->contact_email) > 0 && $model->sendEmail($producer)) {
$isSent = true;
}
if ($isSent) {
$this->setFlash('success', 'Votre message a bien été envoyé.');
} else {
$this->setFlash('error', 'Il y a eu une erreur lors de l\'envoi de votre message.');
}
$model = new ContactForm();
}
return $this->render('contact', [
'model' => $model,
'producer' => $this->getProducerCurrent()
]);
}
public function actionSupport()
{
$featureModule = $this->getFeatureModule();
if($featureModule->getChecker()->isDisabled(Feature::ALIAS_SHOP_SUPPORT)) {
return $this->redirect(['site/index']);
}
$model = new ContactForm();
$producer = $this->getProducerCurrent();
if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
$isSent = false;
if ($model->sendEmailShopSupport($producer)) {
$isSent = true;
}
if ($isSent) {
$this->setFlash('success', 'Votre message a bien été envoyé.');
} else {
$this->setFlash('error', 'Il y a eu une erreur lors de l\'envoi de votre message.');
}
$model = new ContactForm();
}
return $this->render('support', [
'model' => $model,
'producer' => $this->getProducerCurrent()
]);
}
/**
* Ajoute ou supprime un producteur des favoris de l'utilisateur.
* Redirige vers la page d'accueil du producteur.
*/
public function actionBookmarks(string $action)
{
$producer = $this->getProducerCurrent();
$userCurrent = $this->getUserCurrent();
if($userCurrent) {
$userProducer = $this->getUserProducerModule()
->createUserProducerIfNotExist($userCurrent, $producer);
if ($action == 'add') {
$userProducer->bookmark = 1;
$this->setFlash(
'success',
'Le producteur ' . Html::encode($producer->name) . ' vient d\'être ajouté à votre liste de producteurs.'
);
} else {
$userProducer->bookmark = 0;
$this->setFlash(
'success',
'Le producteur ' . Html::encode($producer->name) . ' vient d\'être supprimé de votre liste de producteurs.'
);
}
$userProducer->save();
}
return $this->redirect(['site/index']);
}
/**
* Affiche les mentions légales du producteur.
*/
public function actionMentions()
{
$producer = $this->getProducerCurrent();
if (!strlen($producer->mentions)) {
throw new \yii\base\UserException('Mentions légales introuvables.');
}
return $this->render('mentions', [
'producer' => $producer
]);
}
/**
* Affiche les conditions générales de vente du producteur.
*/
public function actionGcs()
{
$producer = $this->getProducerCurrent();
if (!strlen($producer->gcs)) {
throw new \yii\base\UserException('Conditions générales de vente introuvables.');
}
return $this->render('gcs', [
'producer' => $producer
]);
}
}
?>