Browse Source

Emails automatiques

feature/rotating_product
Guillaume Bourgeois 4 months ago
parent
commit
a41d8580d4
4 changed files with 73 additions and 25 deletions
  1. +11
    -1
      backend/views/user/view.php
  2. +15
    -19
      domain/User/User/NewsletterManager.php
  3. +13
    -0
      domain/User/UserProducer/UserProducerBuilder.php
  4. +34
    -5
      producer/views/newsletter/index.php

+ 11
- 1
backend/views/user/view.php View File



use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use common\helpers\Price; use common\helpers\Price;
use domain\Communication\Email\Email;
use domain\Order\Order\OrderModule; use domain\Order\Order\OrderModule;
use domain\Subscription\Subscription\SubscriptionModule; use domain\Subscription\Subscription\SubscriptionModule;
use domain\User\User\UserModule; use domain\User\User\UserModule;
<li class="list-group-item"> <li class="list-group-item">
<strong>Infolettre</strong> <strong>Infolettre</strong>
<span class="pull-right"> <span class="pull-right">
<?php $isUserSubscribedNewsletter = $userModule->getNewsletterManager()->isUserSubscribedNewsletter($model); ?>
<?php $isUserSubscribedNewsletter = $userModule->getNewsletterManager()->isUserSubscribedNewsletter($model, Email::TYPE_NEWSLETTER); ?>
<span class="label label-<?= $isUserSubscribedNewsletter ? 'success' : 'default' ?>"> <span class="label label-<?= $isUserSubscribedNewsletter ? 'success' : 'default' ?>">
<?= $isUserSubscribedNewsletter ? 'Oui' : 'Non' ?> <?= $isUserSubscribedNewsletter ? 'Oui' : 'Non' ?>
</span> </span>
</span> </span>
</li> </li>
<li class="list-group-item">
<strong>Emails de prise de commande</strong>
<span class="pull-right">
<?php $isUserSubscribedNewsletterOrderTaking = $userModule->getNewsletterManager()->isUserSubscribedNewsletter($model, Email::TYPE_ORDER_TAKING); ?>
<span class="label label-<?= $isUserSubscribedNewsletterOrderTaking ? 'success' : 'default' ?>">
<?= $isUserSubscribedNewsletterOrderTaking ? 'Oui' : 'Non' ?>
</span>
</span>
</li>
<?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?> <?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?>
<li class="list-group-item"> <li class="list-group-item">
<strong>Infolettre Souke</strong> <strong>Infolettre Souke</strong>

+ 15
- 19
domain/User/User/NewsletterManager.php View File

$this->userProducerBuilder = $this->loadService(UserProducerBuilder::class); $this->userProducerBuilder = $this->loadService(UserProducerBuilder::class);
} }


public function isUserSubscribedNewsletter(User $user = null): bool
public function isUserSubscribedNewsletter(User $user = null, string $type = Email::TYPE_NEWSLETTER): bool
{ {
if($user) { if($user) {
$userProducer = $this->userProducerRepository->findOneUserProducer($user); $userProducer = $this->userProducerRepository->findOneUserProducer($user);
if($userProducer && $userProducer->newsletter) {
$fieldNewsletter = ($type == Email::TYPE_NEWSLETTER) ? 'newsletter' : 'newsletter_order_taking';
if($userProducer && $userProducer->$fieldNewsletter) {
return true; return true;
} }
} }
} }


if($newsletterOrderTaking) { if($newsletterOrderTaking) {
$this->subscribeUserNewsletter($user, Email::TYPE_ORDER_TAKING);
} }
else { else {
$this->unsubscribeUserNewsletter($user, Email::TYPE_ORDER_TAKING);
} }
} }


public function subscribeUserNewsletter(User $user, string $type): bool public function subscribeUserNewsletter(User $user, string $type): bool
{ {
$userProducer = $this->userProducerBuilder->createUserProducerIfNotExist($user, $this->getProducerContext()); $userProducer = $this->userProducerBuilder->createUserProducerIfNotExist($user, $this->getProducerContext());

if($type == Email::TYPE_NEWSLETTER) {
return $this->userProducerBuilder->updateUserProducerNewsletter($userProducer, true);
}
elseif($type == Email::TYPE_ORDER_TAKING) {
return $this->userProducerBuilder->updateUserProducerNewsletterOrderTaking($userProducer, true);
}

return false;
return $this->userProducerBuilder->updateUserProducerNewsletterByType(
$userProducer,
true,
$type
);
} }


public function unsubscribeUserNewsletter(User $user, string $type): bool public function unsubscribeUserNewsletter(User $user, string $type): bool
{ {
$userProducer = $this->userProducerRepository->findOneUserProducer($user); $userProducer = $this->userProducerRepository->findOneUserProducer($user);
if($userProducer) { if($userProducer) {
if($type == Email::TYPE_NEWSLETTER) {
return $this->userProducerBuilder->updateUserProducerNewsletter($userProducer, false);
}
elseif($type == Email::TYPE_ORDER_TAKING) {
return $this->userProducerBuilder->updateUserProducerNewsletterOrderTaking($userProducer, false);
}
return $this->userProducerBuilder->updateUserProducerNewsletterByType(
$userProducer,
false,
$type
);
} }


return false; return false;

+ 13
- 0
domain/User/UserProducer/UserProducerBuilder.php View File

namespace domain\User\UserProducer; namespace domain\User\UserProducer;


use common\helpers\MeanPayment; use common\helpers\MeanPayment;
use domain\Communication\Email\Email;
use domain\Order\Order\Order; use domain\Order\Order\Order;
use domain\Order\Order\OrderRepository; use domain\Order\Order\OrderRepository;
use domain\Order\Order\OrderSolver; use domain\Order\Order\OrderSolver;
return $this->update($userProducer); return $this->update($userProducer);
} }


public function updateUserProducerNewsletterByType(UserProducer $userProducer, bool $newsletter, string $type)
{
if($type == Email::TYPE_NEWSLETTER) {
return $this->updateUserProducerNewsletter($userProducer, $newsletter);
}
elseif($type == Email::TYPE_ORDER_TAKING) {
return $this->updateUserProducerNewsletterOrderTaking($userProducer, $newsletter);
}

return false;
}

public function updateUserProducerNewsletter(UserProducer $userProducer, bool $newsletter) public function updateUserProducerNewsletter(UserProducer $userProducer, bool $newsletter)
{ {
$userProducer->newsletter = $newsletter; $userProducer->newsletter = $newsletter;

+ 34
- 5
producer/views/newsletter/index.php View File

*/ */


use domain\User\User\UserModule; use domain\User\User\UserModule;
use lo\widgets\Toggle;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html; use yii\helpers\Html;


$userModule = UserModule::getInstance(); $userModule = UserModule::getInstance();
$producer = $this->context->getProducerCurrent(); $producer = $this->context->getProducerCurrent();
$this->setTitle("Infolettre");
$this->setTitle("Infolettres");


if($userModule->isUserSubscribedNewsletter($user)) {
/*if($userModule->isUserSubscribedNewsletter($user)) {
$this->addButton( $this->addButton(
[ [
'label' => '<i class="bi bi-x-circle"></i> Me désinscrire', 'label' => '<i class="bi bi-x-circle"></i> Me désinscrire',
'class' => 'btn btn-primary' 'class' => 'btn btn-primary'
] ]
); );
}

}*/


?> ?>
<div class="newsletter-index"> <div class="newsletter-index">
<?php if($producer->option_newsletter_description): ?> <?php if($producer->option_newsletter_description): ?>
<?= nl2br(Html::encode($producer->option_newsletter_description)); ?> <?= nl2br(Html::encode($producer->option_newsletter_description)); ?>
<?php else: ?> <?php else: ?>
L'infolettre vous permet de recevoir les emails de prise de commande et les actualités de ce producteur.
Les infolettres vous permettent de recevoir les actualités et les emails de prise de commande de ce producteur.
<?php endif; ?> <?php endif; ?>
</div> </div>
<!--
<?php if($userModule->isUserSubscribedNewsletter($user)): ?> <?php if($userModule->isUserSubscribedNewsletter($user)): ?>
<div class="alert alert-success"> <div class="alert alert-success">
<i class="bi bi-megaphone"></i> <i class="bi bi-megaphone"></i>
Vous n'êtes pas inscrit à l'infolettre <strong><?= Html::encode($producer->name) ?></strong>. Vous n'êtes pas inscrit à l'infolettre <strong><?= Html::encode($producer->name) ?></strong>.
</div> </div>
<?php endif; ?> <?php endif; ?>
-->

<?php $form = ActiveForm::begin(['id' => 'newsletter-form', 'enableClientValidation' => false,]); ?>
<?= $form->field($user, 'newsletter')->widget(Toggle::class,
[
'options' => [
'data-id' => $user->id,
'data-on' => 'Activé',
'data-off' => 'Désactivé'
],
])
->label('Actualités');
?>
<?= $form->field($user, 'newsletter_order_taking')->widget(Toggle::class,
[
'options' => [
'data-id' => $user->id,
'data-on' => 'Activé',
'data-off' => 'Désactivé'
],
])
->label('Emails de prise de commande');
?>
<div class="form-group form-buttons">
<?= Html::submitButton('Enregistrer', ['class' => 'btn btn-primary', 'name' => 'newsletter-button']) ?>
</div>
<?php ActiveForm::end(); ?>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<div class="alert alert-dark"> <div class="alert alert-dark">

Loading…
Cancel
Save