Browse Source

Merge branch 'feature/automatic_email' into develop

feature/rotating_product
Guillaume Bourgeois 4 months ago
parent
commit
5b823710a2
26 changed files with 340 additions and 90 deletions
  1. +7
    -3
      backend/controllers/CommunicateController.php
  2. +6
    -5
      backend/controllers/UserController.php
  3. +49
    -32
      backend/views/communicate/email.php
  4. +9
    -0
      backend/views/user/_form.php
  5. +1
    -1
      backend/views/user/index.php
  6. +11
    -1
      backend/views/user/view.php
  7. +10
    -0
      backend/web/css/screen.css
  8. +13
    -0
      backend/web/sass/communication/_email.scss
  9. +1
    -0
      backend/web/sass/screen.scss
  10. +2
    -1
      console/commands/AutomaticEmailController.php
  11. +27
    -0
      console/migrations/m240701_064424_add_column_user_producer_newsletter_order_taking.php
  12. +3
    -0
      domain/Communication/Email/ContactListResolver.php
  13. +3
    -0
      domain/Communication/Email/Email.php
  14. +39
    -6
      domain/User/User/NewsletterManager.php
  15. +3
    -1
      domain/User/User/User.php
  16. +3
    -1
      domain/User/User/UserRepository.php
  17. +6
    -3
      domain/User/User/UserSearch.php
  18. +18
    -1
      domain/User/UserProducer/UserProducer.php
  19. +20
    -0
      domain/User/UserProducer/UserProducerBuilder.php
  20. +18
    -2
      producer/controllers/NewsletterController.php
  21. +1
    -1
      producer/views/layouts/main.php
  22. +30
    -32
      producer/views/newsletter/index.php
  23. +24
    -0
      producer/web/css/screen.css
  24. +7
    -0
      producer/web/js/producer.js
  25. +28
    -0
      producer/web/sass/newsletter/_index.scss
  26. +1
    -0
      producer/web/sass/screen.scss

+ 7
- 3
backend/controllers/CommunicateController.php View File

use backend\models\MailForm; use backend\models\MailForm;
use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use domain\Communication\Email\ContactListResolver; use domain\Communication\Email\ContactListResolver;
use domain\Communication\Email\Email;
use domain\Communication\Email\EmailGenerator; use domain\Communication\Email\EmailGenerator;
use domain\PointSale\PointSale\PointSale; use domain\PointSale\PointSale\PointSale;
use kartik\mpdf\Pdf; use kartik\mpdf\Pdf;
$sectionInactiveUsers = 0, $sectionInactiveUsers = 0,
$usersPointSaleLink = 0, $usersPointSaleLink = 0,
$usersPointSaleHasOrder = 0, $usersPointSaleHasOrder = 0,
$idDistribution = 0)
{
$idDistribution = 0,
$newsletterType = null
) {
$emailModule = $this->getEmailModule(); $emailModule = $this->getEmailModule();


$mailForm = new MailForm(); $mailForm = new MailForm();


$usersArray = $emailModule->getContactListResolver()->search( $usersArray = $emailModule->getContactListResolver()->search(
$this->getProducerCurrent(), $this->getProducerCurrent(),
$newsletterType,
$distribution, $distribution,
$pointSale, $pointSale,
$usersPointSaleLink, $usersPointSaleLink,
$email = $emailModule->getGenerator()->createEmail( $email = $emailModule->getGenerator()->createEmail(
$mailForm->subject, $mailForm->subject,
$mailForm->message, $mailForm->message,
$mailForm->integrate_product_list,
(bool) $mailForm->integrate_product_list,
$this->getProducerCurrent(), $this->getProducerCurrent(),
$distribution $distribution
); );
'sectionInactiveUsers' => $sectionInactiveUsers, 'sectionInactiveUsers' => $sectionInactiveUsers,
'usersPointSaleLink' => $usersPointSaleLink, 'usersPointSaleLink' => $usersPointSaleLink,
'usersPointSaleHasOrder' => $usersPointSaleHasOrder, 'usersPointSaleHasOrder' => $usersPointSaleHasOrder,
'newsletterType' => $newsletterType,
]); ]);
} }



+ 6
- 5
backend/controllers/UserController.php View File

$userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); $userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]);
if ($userBelongToProducer) { if ($userBelongToProducer) {
$model->newsletter = $userBelongToProducer->newsletter; $model->newsletter = $userBelongToProducer->newsletter;
$model->newsletter_order_taking = $userBelongToProducer->newsletter_order_taking;
$model->trust_alert = $userBelongToProducer->trust_alert; $model->trust_alert = $userBelongToProducer->trust_alert;
$model->trust_alert_comment = $userBelongToProducer->trust_alert_comment; $model->trust_alert_comment = $userBelongToProducer->trust_alert_comment;
$model->exclusive_access_selected_points_sale = $userBelongToProducer->exclusive_access_selected_points_sale; $model->exclusive_access_selected_points_sale = $userBelongToProducer->exclusive_access_selected_points_sale;
//$this->processProductPricePercent($model); //$this->processProductPricePercent($model);


// Newsletter // Newsletter
if ($model->newsletter) {
$userModule->getNewsletterManager()->subscribeUserNewsletter($model);
} else {
$userModule->getNewsletterManager()->unsubscribeUserNewsletter($model);
}
$userModule->getNewsletterManager()->manageUserNewsletter(
$model,
$model->newsletter,
$model->newsletter_order_taking
);


// Alerte confiance // Alerte confiance
$userBelongToProducer->trust_alert = $model->trust_alert; $userBelongToProducer->trust_alert = $model->trust_alert;

+ 49
- 32
backend/views/communicate/email.php View File

termes. termes.
*/ */


use domain\Communication\Email\Email;
use yii\helpers\Html ; use yii\helpers\Html ;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;




?> ?>


<div id="">
<div class="communication-email row">
<div class="col-md-8"> <div class="col-md-8">
<div class="panel panel-default">
<div id="panel-mail-form" class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">Envoyer un email</h3> <h3 class="panel-title">Envoyer un email</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($mailForm, 'id_distribution')->dropDownList($incomingDistributionsDatesArray)
->hint("Sélectionnez une distribution pour ajouter automatiquement au message un lien vers la prise de commande de cette distribution"); ?>
<?= $form->field($mailForm, 'integrate_product_list')->checkbox() ; ?>
<?= $form->field($mailForm, 'subject')->textInput() ; ?>
<?php //$form->field($mailForm, 'message')->textarea(['rows' => '15']) ; ?>
<?= $form->field($mailForm, 'message')->widget(letyii\tinymce\Tinymce::class, [
'configs' => [
'plugins' => Yii::$app->parameterBag->get('tinyMcePlugins')
],
]); ?>
<div class="form-group form-buttons">
<?= Html::submitButton( 'Envoyer', ['class' => 'btn btn-primary']) ?>
<div class="newsletter-type">
<strong>Type d'email</strong>
<div>
<?php $linkParamsArray = ['idPointSale' => $idPointSaleActive, 'idDistribution' => $idDistributionActive, 'usersPointSaleLink' => $usersPointSaleLink, 'usersPointSaleHasOrder' => $usersPointSaleHasOrder, 'sectionSubscribers' => $sectionSubscribers, 'sectionInactiveUsers' => $sectionInactiveUsers]; ?>
<a class="btn <?= ($newsletterType == Email::TYPE_ORDER_TAKING) ? 'btn-primary' : 'btn-default'; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email', 'newsletterType' => Email::TYPE_ORDER_TAKING] + $linkParamsArray) ?>">Prise de commande</a>
<a class="btn <?= ($newsletterType == Email::TYPE_NEWSLETTER) ? 'btn-primary' : 'btn-default'; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email', 'newsletterType' => Email::TYPE_NEWSLETTER] + $linkParamsArray) ?>">Actualité</a>
</div>
</div> </div>
<?php ActiveForm::end(); ?>

<?php if($newsletterType): ?>
<?php $form = ActiveForm::begin(['enableClientValidation' => false]); ?>
<?php if($newsletterType == Email::TYPE_ORDER_TAKING): ?>
<?= $form->field($mailForm, 'id_distribution')->dropDownList($incomingDistributionsDatesArray)
->hint("Sélectionnez une distribution pour ajouter automatiquement au message un lien vers la prise de commande de cette distribution"); ?>
<?php endif; ?>
<?= $form->field($mailForm, 'subject')->textInput() ; ?>
<?= $form->field($mailForm, 'message')->widget(letyii\tinymce\Tinymce::class, [
'configs' => [
'plugins' => Yii::$app->parameterBag->get('tinyMcePlugins')
],
]); ?>
<?php if($newsletterType == Email::TYPE_ORDER_TAKING): ?>
<?= $form->field($mailForm, 'integrate_product_list')->checkbox() ; ?>
<?php endif; ?>
<div class="form-group form-buttons">
<?= Html::submitButton( 'Envoyer', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
<?php endif; ?>
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Liste des emails <span class="label label-default"><?= count($usersArray); ?></span>
</h3>
</div>
<div class="panel-body">
<?php if($newsletterType): ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Liste des emails <span class="label label-default"><?= count($usersArray); ?></span>
</h3>
</div>
<div class="panel-body">


<?php if($idPointSaleActive): ?>
<a class="btn btn-xs <?php if($usersPointSaleLink): ?>btn-primary<?php else: ?>btn-default<?php endif; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email','idPointSale' => $idPointSaleActive, 'idDistribution' => $idDistributionActive, 'usersPointSaleLink' => 1]); ?>">Liés au point de vente</a>
<a class="btn btn-xs <?php if($usersPointSaleHasOrder): ?>btn-primary<?php else: ?>btn-default<?php endif; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email','idPointSale' => $idPointSaleActive, 'idDistribution' => $idDistributionActive, 'usersPointSaleHasOrder' => 1]); ?>">Déjà commandés dans ce point de vente</a>
<br /><br />
<?php endif; ?>
<?php if($idPointSaleActive): ?>
<a class="btn btn-xs <?php if($usersPointSaleLink): ?>btn-primary<?php else: ?>btn-default<?php endif; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email','idPointSale' => $idPointSaleActive, 'idDistribution' => $idDistributionActive, 'usersPointSaleLink' => 1, 'newsletterType' => $newsletterType]); ?>">Liés au point de vente</a>
<a class="btn btn-xs <?php if($usersPointSaleHasOrder): ?>btn-primary<?php else: ?>btn-default<?php endif; ?>" href="<?= Yii::$app->urlManager->createUrl(['communicate/email','idPointSale' => $idPointSaleActive, 'idDistribution' => $idDistributionActive, 'usersPointSaleHasOrder' => 1, 'newsletterType' => $newsletterType]); ?>">Déjà commandés dans ce point de vente</a>
<br /><br />
<?php endif; ?>


<?= implode(', ', array_map(function($user) {
return $user['email'];
}, $usersArray)); ?>
<?= implode(', ', array_map(function($user) {
return $user['email'];
}, $usersArray)); ?>
</div>
</div> </div>
</div>
<?php endif; ?>
</div> </div>
<div class="clr"></div> <div class="clr"></div>
</div> </div>

+ 9
- 0
backend/views/user/_form.php View File

], ],
] ]
); ?> ); ?>
<?= $form->field($model, 'newsletter_order_taking')->widget(Toggle::class,
[
'options' => [
'data-id' => $model->id,
'data-on' => 'Oui',
'data-off' => 'Non',
],
]
); ?>
<?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?> <?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?>
<?= $form->field($model, 'newsletter_souke')->widget(Toggle::class, <?= $form->field($model, 'newsletter_souke')->widget(Toggle::class,
[ [

+ 1
- 1
backend/views/user/index.php View File

1 => 'Oui' 1 => 'Oui'
], ],
'value' => function ($user) use ($userModule) { 'value' => function ($user) use ($userModule) {
if($userModule->isUserSubscribedNewsletter($user)) {
if($userModule->getNewsletterManager()->isUserSubscribedOneNewsletter($user)) {
return '<span class="label label-success">Oui</span>'; return '<span class="label label-success">Oui</span>';
} }
return '<span class="label label-danger">Non</span>'; return '<span class="label label-danger">Non</span>';

+ 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>

+ 10
- 0
backend/web/css/screen.css View File

display: block; display: block;
} }


/* line 5, ../sass/communication/_email.scss */
.communication-email #panel-mail-form .newsletter-type {
margin-bottom: 20px;
}
/* line 7, ../sass/communication/_email.scss */
.communication-email #panel-mail-form .newsletter-type strong {
display: block;
margin-bottom: 5px;
}

/** /**
Copyright Souke (2018) Copyright Souke (2018)



+ 13
- 0
backend/web/sass/communication/_email.scss View File



.communication-email {
#panel-mail-form {
.newsletter-type {
margin-bottom: 20px;
strong {
display: block;
margin-bottom: 5px;
}
}
}
}

+ 1
- 0
backend/web/sass/screen.scss View File

@import "setting/_form.scss"; @import "setting/_form.scss";
@import "dashboard-admin/_index.scss" ; @import "dashboard-admin/_index.scss" ;
@import "automatic-email/_form.scss" ; @import "automatic-email/_form.scss" ;
@import "communication/_email.scss" ;
@import "_responsive.scss" ; @import "_responsive.scss" ;

+ 2
- 1
console/commands/AutomaticEmailController.php View File

namespace console\commands; namespace console\commands;


use domain\Communication\AutomaticEmail\AutomaticEmailModule; use domain\Communication\AutomaticEmail\AutomaticEmailModule;
use domain\Communication\Email\Email;
use domain\Communication\Email\EmailModule; use domain\Communication\Email\EmailModule;
use domain\Producer\Producer\ProducerModule; use domain\Producer\Producer\ProducerModule;
use yii\console\Controller; use yii\console\Controller;
$distribution = $automaticEmailModule->getResolver()->getMatchedDistribution($automaticEmail); $distribution = $automaticEmailModule->getResolver()->getMatchedDistribution($automaticEmail);
if($distribution) { if($distribution) {
$email = $automaticEmailModule->getManager()->createEmailFromAutomaticEmail($automaticEmail, $distribution); $email = $automaticEmailModule->getManager()->createEmailFromAutomaticEmail($automaticEmail, $distribution);
$usersArray = $emailModule->getContactListResolver()->search($producer, $distribution);
$usersArray = $emailModule->getContactListResolver()->search($producer, Email::TYPE_ORDER_TAKING, $distribution);
$emailModule->getBulkMailer()->sendEmail($email, $usersArray); $emailModule->getBulkMailer()->sendEmail($email, $usersArray);
echo 'Email automatique "'.$automaticEmail->getSubject().'" envoyé à '.count($usersArray)." utilisateur(s)\n"; echo 'Email automatique "'.$automaticEmail->getSubject().'" envoyé à '.count($usersArray)." utilisateur(s)\n";
} }

+ 27
- 0
console/migrations/m240701_064424_add_column_user_producer_newsletter_order_taking.php View File

<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m240701_064424_add_column_user_producer_newsletter_order_taking
*/
class m240701_064424_add_column_user_producer_newsletter_order_taking extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('user_producer', 'newsletter_order_taking', Schema::TYPE_BOOLEAN);
$this->execute('UPDATE user_producer SET newsletter_order_taking = newsletter;');
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('user_producer', 'newsletter_order_taking');
}
}

+ 3
- 0
domain/Communication/Email/ContactListResolver.php View File



public function search( public function search(
Producer $producer, Producer $producer,
string $newsletterType = null,
Distribution $distribution = null, Distribution $distribution = null,
PointSale $pointSale = null, PointSale $pointSale = null,
bool $usersPointSaleLink = false, bool $usersPointSaleLink = false,
'id_point_sale' => $pointSaleDistribution->id_point_sale, 'id_point_sale' => $pointSaleDistribution->id_point_sale,
'users_point_sale_link' => $usersPointSaleLink, 'users_point_sale_link' => $usersPointSaleLink,
'users_point_sale_has_order' => $usersPointSaleHasOrder, 'users_point_sale_has_order' => $usersPointSaleHasOrder,
'newsletter_type' => $newsletterType,
'newsletter' => true 'newsletter' => true
])->all(); ])->all();


'users_point_sale_has_order' => $usersPointSaleHasOrder, 'users_point_sale_has_order' => $usersPointSaleHasOrder,
'subscribers' => $isSubscriber, 'subscribers' => $isSubscriber,
'inactive' => $isInactive, 'inactive' => $isInactive,
'newsletter_type' => $newsletterType,
'newsletter' => true 'newsletter' => true
])->all(); ])->all();
} }

+ 3
- 0
domain/Communication/Email/Email.php View File



class Email class Email
{ {
const TYPE_NEWSLETTER = 'newsletter';
const TYPE_ORDER_TAKING = 'newsletter-order-taking';

protected string $fromName; protected string $fromName;
protected string $fromEmail; protected string $fromEmail;
protected string $subject; protected string $subject;

+ 39
- 6
domain/User/User/NewsletterManager.php View File



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


use domain\Communication\Email\Email;
use domain\User\UserProducer\UserProducerBuilder; use domain\User\UserProducer\UserProducerBuilder;
use domain\User\UserProducer\UserProducerRepository; use domain\User\UserProducer\UserProducerRepository;
use domain\_\AbstractService; use domain\_\AbstractService;
$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;
} }
} }
return false; return false;
} }


public function subscribeUserNewsletter(User $user): bool
public function isUserSubscribedOneNewsletter(User $user): bool
{
return $this->isUserSubscribedNewsletter($user, Email::TYPE_NEWSLETTER)
|| $this->isUserSubscribedNewsletter($user, Email::TYPE_ORDER_TAKING);
}

public function manageUserNewsletter(User $user, ?bool $newsletter, ?bool $newsletterOrderTaking)
{
if($newsletter) {
$this->subscribeUserNewsletter($user, Email::TYPE_NEWSLETTER);
}
else {
$this->unsubscribeUserNewsletter($user, Email::TYPE_NEWSLETTER);
}

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

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


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


return false; return false;

+ 3
- 1
domain/User/User/User.php View File

var $one_name; var $one_name;
var $product_price_percent; var $product_price_percent;
var $newsletter; var $newsletter;
var $newsletter_order_taking;
var $send_mail_welcome; var $send_mail_welcome;
var $trust_alert; var $trust_alert;
var $trust_alert_comment; var $trust_alert_comment;
return [ return [
[['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday', [['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday',
'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday', 'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday',
'mail_distribution_sunday', 'is_main_contact', 'newsletter', 'exclude_export_shopping_cart_labels',
'mail_distribution_sunday', 'is_main_contact', 'newsletter', 'newsletter_order_taking', 'exclude_export_shopping_cart_labels',
'send_mail_welcome', 'trust_alert', 'newsletter_souke', 'problem_receiving_emails', 'exclusive_access_selected_points_sale'], 'boolean'], 'send_mail_welcome', 'trust_alert', 'newsletter_souke', 'problem_receiving_emails', 'exclusive_access_selected_points_sale'], 'boolean'],
[['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person', 'evoliz_code', 'trust_alert_comment', 'note_emails'], 'string'], [['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person', 'evoliz_code', 'trust_alert_comment', 'note_emails'], 'string'],
['lastname', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false], ['lastname', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false],
'user_groups' => "Groupes d'utilisateurs", 'user_groups' => "Groupes d'utilisateurs",
'evoliz_code' => 'Code client Evoliz', 'evoliz_code' => 'Code client Evoliz',
'newsletter' => "Inscrit à l'infolettre", 'newsletter' => "Inscrit à l'infolettre",
"newsletter_order_taking" => "Inscrit aux emails de prise de commande",
'exclude_export_shopping_cart_labels' => "Exclure de l'export d'étiquettes", 'exclude_export_shopping_cart_labels' => "Exclure de l'export d'étiquettes",
'send_mail_welcome' => "Envoyer un email de bienvenue", 'send_mail_welcome' => "Envoyer un email de bienvenue",
'email_sending_invoicing_documents' => 'Email facturation', 'email_sending_invoicing_documents' => 'Email facturation',

+ 3
- 1
domain/User/User/UserRepository.php View File

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


use common\helpers\GlobalParam; use common\helpers\GlobalParam;
use domain\Communication\Email\Email;
use domain\PointSale\PointSale\PointSale; use domain\PointSale\PointSale\PointSale;
use domain\Producer\Producer\Producer; use domain\Producer\Producer\Producer;
use domain\User\UserProducer\UserProducerRepository; use domain\User\UserProducer\UserProducerRepository;
->from('user'); ->from('user');


$active = (isset($params['inactive']) && $params['inactive']) ? 0 : 1; $active = (isset($params['inactive']) && $params['inactive']) ? 0 : 1;
$filterNewsletter = (isset($params['newsletter']) && $params['newsletter']) ? 'AND user_producer.newsletter = 1' : '';
$fieldNewsletter = (isset($params['newsletter_type']) && $params['newsletter_type'] == Email::TYPE_ORDER_TAKING) ? 'newsletter_order_taking' : 'newsletter';;
$filterNewsletter = (isset($params['newsletter']) && $params['newsletter']) ? 'AND user_producer.'.$fieldNewsletter.' = 1' : '';
$query->innerJoin('user_producer', 'user.id = user_producer.id_user AND user_producer.active = ' . $active . ' '.$filterNewsletter.' AND user_producer.id_producer = :id_producer', [':id_producer' => $params['id_producer']]); $query->innerJoin('user_producer', 'user.id = user_producer.id_user AND user_producer.active = ' . $active . ' '.$filterNewsletter.' AND user_producer.id_producer = :id_producer', [':id_producer' => $params['id_producer']]);


if (isset($params['id_point_sale']) && $params['id_point_sale']) { if (isset($params['id_point_sale']) && $params['id_point_sale']) {

+ 6
- 3
domain/User/User/UserSearch.php View File

} }


if (isset($this->newsletter) && is_numeric($this->newsletter)) { if (isset($this->newsletter) && is_numeric($this->newsletter)) {
$query->andWhere([
'user_producer.newsletter' => $this->newsletter
]);
if($this->newsletter) {
$query->andWhere('user_producer.newsletter = 1 OR user_producer.newsletter_order_taking = 1');
}
else {
$query->andWhere('(user_producer.newsletter = 0 OR user_producer.newsletter IS NULL) AND (user_producer.newsletter_order_taking = 0 OR user_producer.newsletter_order_taking IS NULL)');
}
} }


if (isset($this->id_user_user_group) && is_numeric($this->id_user_user_group)) { if (isset($this->id_user_user_group) && is_numeric($this->id_user_user_group)) {

+ 18
- 1
domain/User/UserProducer/UserProducer.php View File

return [ return [
[['id_user', 'id_producer'], 'required'], [['id_user', 'id_producer'], 'required'],
[['id_user', 'id_producer', 'product_price_percent'], 'integer'], [['id_user', 'id_producer', 'product_price_percent'], 'integer'],
[['active', 'bookmark', 'credit_active', 'newsletter', 'trust_alert', 'exclusive_access_selected_points_sale'], 'boolean'],
[['active', 'bookmark', 'credit_active', 'newsletter', 'newsletter_order_taking', 'trust_alert', 'exclusive_access_selected_points_sale'], 'boolean'],
[['credit', 'product_price_percent'], 'double'], [['credit', 'product_price_percent'], 'double'],
[['trust_alert_comment'], 'string'] [['trust_alert_comment'], 'string']
]; ];
return $this; return $this;
} }


public function getNewsletter(): ?bool
{
return $this->newsletter;
}

public function setNewsletter(bool $newsletter): self public function setNewsletter(bool $newsletter): self
{ {
$this->newsletter = $newsletter; $this->newsletter = $newsletter;
return $this; return $this;
} }


public function getNewsletterOrderTaking(): ?bool
{
return $this->newsletter_order_taking;
}

public function setNewsletterOrderTaking(bool $newsletterOrderTaking): self
{
$this->newsletter_order_taking = $newsletterOrderTaking;

return $this;
}

public function getCredit(): float public function getCredit(): float
{ {
return $this->credit; return $this->credit;

+ 20
- 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;
$userProducer->setActive(true); $userProducer->setActive(true);
$userProducer->setBookmark($bookmark); $userProducer->setBookmark($bookmark);
$userProducer->setNewsletter($newsletter); $userProducer->setNewsletter($newsletter);
$userProducer->setNewsletterOrderTaking($newsletter);


return $userProducer; return $userProducer;
} }
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;
return $this->update($userProducer); return $this->update($userProducer);
} }

public function updateUserProducerNewsletterOrderTaking(UserProducer $userProducer, bool $newsletterOrderTaking)
{
$userProducer->newsletter_order_taking = $newsletterOrderTaking;
return $this->update($userProducer);
}
} }

+ 18
- 2
producer/controllers/NewsletterController.php View File



namespace producer\controllers; namespace producer\controllers;


use domain\Communication\Email\Email;
use yii\filters\AccessControl; use yii\filters\AccessControl;


class NewsletterController extends ProducerBaseController class NewsletterController extends ProducerBaseController


public function actionIndex() public function actionIndex()
{ {
if(!$this->getUserCurrent()) {
$userModule = $this->getUserModule();
$user = $this->getUserCurrent();

if(!$user) {
return $this->redirectProducerLoginFrontend('index'); return $this->redirectProducerLoginFrontend('index');
} }


$user->newsletter = $userModule->getNewsletterManager()->isUserSubscribedNewsletter($user, Email::TYPE_NEWSLETTER);
$user->newsletter_order_taking = $userModule->getNewsletterManager()->isUserSubscribedNewsletter($user, Email::TYPE_ORDER_TAKING);

if($user->load(\Yii::$app->request->post()) && $user->validate()) {
$userModule->getNewsletterManager()->manageUserNewsletter(
$user,
$user->newsletter,
$user->newsletter_order_taking
);
$this->setFlash('success', 'Vos changements ont bien été pris en compte.');
}

return $this->render('index', [ return $this->render('index', [
'user' => $this->getUserCurrent(),
'user' => $user,
'producer' => $this->getProducerCurrent() 'producer' => $this->getProducerCurrent()
]); ]);
} }

+ 1
- 1
producer/views/layouts/main.php View File

->count(); ->count();
$labelOrders = $countOrders > 0 ? 'success' : 'default'; $labelOrders = $countOrders > 0 ? 'success' : 'default';


$isUserSubscribedNewsletter = $userModule->isUserSubscribedNewsletter($userCurrent);
$isUserSubscribedNewsletter = $userModule->getNewsletterManager()->isUserSubscribedOneNewsletter($userCurrent);
$isHome = in_array($this->getControllerAction(), ['site/index', 'site/products', 'site/points-sale']); $isHome = in_array($this->getControllerAction(), ['site/index', 'site/products', 'site/points-sale']);


echo Nav::widget([ echo Nav::widget([

+ 30
- 32
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");

if($userModule->isUserSubscribedNewsletter($user)) {
$this->addButton(
[
'label' => '<i class="bi bi-x-circle"></i> Me désinscrire',
'url' => 'newsletter/unsubscribe',
'class' => 'btn btn-secondary'
]
);
}
else {
$this->addButton(
[
'label' => '<i class="bi bi-megaphone"></i> M\'inscrire',
'url' => 'newsletter/subscribe',
'class' => 'btn btn-primary'
]
);
}

$this->setTitle("Infolettres");


?> ?>
<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)): ?>
<div class="alert alert-success">
<i class="bi bi-megaphone"></i>
Vous êtes inscrit à l'infolettre <strong><?= Html::encode($producer->name) ?></strong>.
</div>
<?php else: ?>
<div class="alert alert-danger">
<i class="bi bi-x-circle"></i>
Vous n'êtes pas inscrit à l'infolettre <strong><?= Html::encode($producer->name) ?></strong>.

<?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');
?>
<div class="clr"></div>
<?= $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> </div>
<?php endif; ?>
<?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">

+ 24
- 0
producer/web/css/screen.css View File

display: inline-block; display: inline-block;
} }


/* line 5, ../sass/newsletter/_index.scss */
.newsletter-index #newsletter-form .form-group {
margin-bottom: 25px;
}
/* line 8, ../sass/newsletter/_index.scss */
.newsletter-index #newsletter-form .form-group .toggle {
float: left;
width: 150px !important;
}
/* line 13, ../sass/newsletter/_index.scss */
.newsletter-index #newsletter-form .form-group label {
display: inline-block;
font-weight: bold;
margin-left: 20px;
}
/* line 18, ../sass/newsletter/_index.scss */
.newsletter-index #newsletter-form .form-group label.control-label {
margin-top: 10px;
}
/* line 23, ../sass/newsletter/_index.scss */
.newsletter-index #newsletter-form .form-group.form-buttons {
display: none;
}

/** /**
Copyright Souke (2018) Copyright Souke (2018)



+ 7
- 0
producer/web/js/producer.js View File

opendistrib_datepicker(); opendistrib_datepicker();
opendistrib_fix_width_sidebar(); opendistrib_fix_width_sidebar();
opendistrib_products(); opendistrib_products();
opendistrib_newsletter();
}); });


function opendistrib_newsletter() {
$('#newsletter-form input').change(function() {
$('#newsletter-form').submit();
});
}

function opendistrib_products() { function opendistrib_products() {
$('.product-name-description-block .show-more-link').unbind('click').click(function() { $('.product-name-description-block .show-more-link').unbind('click').click(function() {
$(this).hide(); $(this).hide();

+ 28
- 0
producer/web/sass/newsletter/_index.scss View File



.newsletter-index {
#newsletter-form {
.form-group {
margin-bottom: 25px;

.toggle {
float: left;
width: 150px !important;
}

label {
display: inline-block;
font-weight: bold;
margin-left: 20px;

&.control-label {
margin-top: 10px;
}
}

&.form-buttons {
display: none;
}
}
}
}

+ 1
- 0
producer/web/sass/screen.scss View File

@import "credit/_history.scss"; @import "credit/_history.scss";
@import "subscription/_index.scss"; @import "subscription/_index.scss";
@import "subscription/_form.scss"; @import "subscription/_form.scss";
@import "newsletter/_index.scss";
@import "_responsive.scss"; @import "_responsive.scss";

Loading…
Cancel
Save