Explorar el Código

Merge branch 'feature/automatic_email' into develop

feature/rotating_product
Guillaume Bourgeois hace 5 meses
padre
commit
5b823710a2
Se han modificado 26 ficheros con 340 adiciones y 90 borrados
  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 Ver fichero

@@ -41,6 +41,7 @@ namespace backend\controllers;
use backend\models\MailForm;
use common\helpers\GlobalParam;
use domain\Communication\Email\ContactListResolver;
use domain\Communication\Email\Email;
use domain\Communication\Email\EmailGenerator;
use domain\PointSale\PointSale\PointSale;
use kartik\mpdf\Pdf;
@@ -84,8 +85,9 @@ class CommunicateController extends BackendController
$sectionInactiveUsers = 0,
$usersPointSaleLink = 0,
$usersPointSaleHasOrder = 0,
$idDistribution = 0)
{
$idDistribution = 0,
$newsletterType = null
) {
$emailModule = $this->getEmailModule();

$mailForm = new MailForm();
@@ -101,6 +103,7 @@ class CommunicateController extends BackendController

$usersArray = $emailModule->getContactListResolver()->search(
$this->getProducerCurrent(),
$newsletterType,
$distribution,
$pointSale,
$usersPointSaleLink,
@@ -121,7 +124,7 @@ class CommunicateController extends BackendController
$email = $emailModule->getGenerator()->createEmail(
$mailForm->subject,
$mailForm->message,
$mailForm->integrate_product_list,
(bool) $mailForm->integrate_product_list,
$this->getProducerCurrent(),
$distribution
);
@@ -154,6 +157,7 @@ class CommunicateController extends BackendController
'sectionInactiveUsers' => $sectionInactiveUsers,
'usersPointSaleLink' => $usersPointSaleLink,
'usersPointSaleHasOrder' => $usersPointSaleHasOrder,
'newsletterType' => $newsletterType,
]);
}


+ 6
- 5
backend/controllers/UserController.php Ver fichero

@@ -219,6 +219,7 @@ class UserController extends BackendController
$userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]);
if ($userBelongToProducer) {
$model->newsletter = $userBelongToProducer->newsletter;
$model->newsletter_order_taking = $userBelongToProducer->newsletter_order_taking;
$model->trust_alert = $userBelongToProducer->trust_alert;
$model->trust_alert_comment = $userBelongToProducer->trust_alert_comment;
$model->exclusive_access_selected_points_sale = $userBelongToProducer->exclusive_access_selected_points_sale;
@@ -237,11 +238,11 @@ class UserController extends BackendController
//$this->processProductPricePercent($model);

// 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
$userBelongToProducer->trust_alert = $model->trust_alert;

+ 49
- 32
backend/views/communicate/email.php Ver fichero

@@ -36,6 +36,7 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

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

@@ -60,51 +61,67 @@ $this->render('@backend/views/user/_menu_filter.php',[

?>

<div id="">
<div class="communication-email row">
<div class="col-md-8">
<div class="panel panel-default">
<div id="panel-mail-form" class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Envoyer un email</h3>
</div>
<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>
<?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 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>
<?php endif; ?>
</div>
<div class="clr"></div>
</div>

+ 9
- 0
backend/views/user/_form.php Ver fichero

@@ -191,6 +191,15 @@ $distributionModule = DistributionModule::getInstance();
],
]
); ?>
<?= $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)): ?>
<?= $form->field($model, 'newsletter_souke')->widget(Toggle::class,
[

+ 1
- 1
backend/views/user/index.php Ver fichero

@@ -188,7 +188,7 @@ $this->render('_menu_filter', [
1 => 'Oui'
],
'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-danger">Non</span>';

+ 11
- 1
backend/views/user/view.php Ver fichero

@@ -38,6 +38,7 @@ termes.

use common\helpers\GlobalParam;
use common\helpers\Price;
use domain\Communication\Email\Email;
use domain\Order\Order\OrderModule;
use domain\Subscription\Subscription\SubscriptionModule;
use domain\User\User\UserModule;
@@ -122,12 +123,21 @@ $this->addBreadcrumb('Récapitulatif') ;
<li class="list-group-item">
<strong>Infolettre</strong>
<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' ?>">
<?= $isUserSubscribedNewsletter ? 'Oui' : 'Non' ?>
</span>
</span>
</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)): ?>
<li class="list-group-item">
<strong>Infolettre Souke</strong>

+ 10
- 0
backend/web/css/screen.css Ver fichero

@@ -3340,6 +3340,16 @@ termes.
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)


+ 13
- 0
backend/web/sass/communication/_email.scss Ver fichero

@@ -0,0 +1,13 @@


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

+ 1
- 0
backend/web/sass/screen.scss Ver fichero

@@ -1556,4 +1556,5 @@ a.btn, button.btn {
@import "setting/_form.scss";
@import "dashboard-admin/_index.scss" ;
@import "automatic-email/_form.scss" ;
@import "communication/_email.scss" ;
@import "_responsive.scss" ;

+ 2
- 1
console/commands/AutomaticEmailController.php Ver fichero

@@ -3,6 +3,7 @@
namespace console\commands;

use domain\Communication\AutomaticEmail\AutomaticEmailModule;
use domain\Communication\Email\Email;
use domain\Communication\Email\EmailModule;
use domain\Producer\Producer\ProducerModule;
use yii\console\Controller;
@@ -24,7 +25,7 @@ class AutomaticEmailController extends Controller
$distribution = $automaticEmailModule->getResolver()->getMatchedDistribution($automaticEmail);
if($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);
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 Ver fichero

@@ -0,0 +1,27 @@
<?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 Ver fichero

@@ -20,6 +20,7 @@ class ContactListResolver extends AbstractResolver

public function search(
Producer $producer,
string $newsletterType = null,
Distribution $distribution = null,
PointSale $pointSale = null,
bool $usersPointSaleLink = false,
@@ -45,6 +46,7 @@ class ContactListResolver extends AbstractResolver
'id_point_sale' => $pointSaleDistribution->id_point_sale,
'users_point_sale_link' => $usersPointSaleLink,
'users_point_sale_has_order' => $usersPointSaleHasOrder,
'newsletter_type' => $newsletterType,
'newsletter' => true
])->all();

@@ -62,6 +64,7 @@ class ContactListResolver extends AbstractResolver
'users_point_sale_has_order' => $usersPointSaleHasOrder,
'subscribers' => $isSubscriber,
'inactive' => $isInactive,
'newsletter_type' => $newsletterType,
'newsletter' => true
])->all();
}

+ 3
- 0
domain/Communication/Email/Email.php Ver fichero

@@ -4,6 +4,9 @@ namespace domain\Communication\Email;

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

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

+ 39
- 6
domain/User/User/NewsletterManager.php Ver fichero

@@ -2,6 +2,7 @@

namespace domain\User\User;

use domain\Communication\Email\Email;
use domain\User\UserProducer\UserProducerBuilder;
use domain\User\UserProducer\UserProducerRepository;
use domain\_\AbstractService;
@@ -18,11 +19,12 @@ class NewsletterManager extends AbstractService implements ManagerInterface
$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) {
$userProducer = $this->userProducerRepository->findOneUserProducer($user);
if($userProducer && $userProducer->newsletter) {
$fieldNewsletter = ($type == Email::TYPE_NEWSLETTER) ? 'newsletter' : 'newsletter_order_taking';
if($userProducer && $userProducer->$fieldNewsletter) {
return true;
}
}
@@ -30,17 +32,48 @@ class NewsletterManager extends AbstractService implements ManagerInterface
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());
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);
if($userProducer) {
return $this->userProducerBuilder->updateUserProducerNewsletter($userProducer, false);
return $this->userProducerBuilder->updateUserProducerNewsletterByType(
$userProducer,
false,
$type
);
}

return false;

+ 3
- 1
domain/User/User/User.php Ver fichero

@@ -77,6 +77,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
var $one_name;
var $product_price_percent;
var $newsletter;
var $newsletter_order_taking;
var $send_mail_welcome;
var $trust_alert;
var $trust_alert_comment;
@@ -108,7 +109,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
return [
[['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday',
'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'],
[['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person', 'evoliz_code', 'trust_alert_comment', 'note_emails'], 'string'],
['lastname', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false],
@@ -153,6 +154,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
'user_groups' => "Groupes d'utilisateurs",
'evoliz_code' => 'Code client Evoliz',
'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",
'send_mail_welcome' => "Envoyer un email de bienvenue",
'email_sending_invoicing_documents' => 'Email facturation',

+ 3
- 1
domain/User/User/UserRepository.php Ver fichero

@@ -3,6 +3,7 @@
namespace domain\User\User;

use common\helpers\GlobalParam;
use domain\Communication\Email\Email;
use domain\PointSale\PointSale\PointSale;
use domain\Producer\Producer\Producer;
use domain\User\UserProducer\UserProducerRepository;
@@ -102,7 +103,8 @@ class UserRepository extends AbstractRepository
->from('user');

$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']]);

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

+ 6
- 3
domain/User/User/UserSearch.php Ver fichero

@@ -151,9 +151,12 @@ class UserSearch extends User
}

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)) {

+ 18
- 1
domain/User/UserProducer/UserProducer.php Ver fichero

@@ -63,7 +63,7 @@ class UserProducer extends ActiveRecordCommon
return [
[['id_user', 'id_producer'], 'required'],
[['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'],
[['trust_alert_comment'], 'string']
];
@@ -155,6 +155,11 @@ class UserProducer extends ActiveRecordCommon
return $this;
}

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

public function setNewsletter(bool $newsletter): self
{
$this->newsletter = $newsletter;
@@ -162,6 +167,18 @@ class UserProducer extends ActiveRecordCommon
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
{
return $this->credit;

+ 20
- 0
domain/User/UserProducer/UserProducerBuilder.php Ver fichero

@@ -3,6 +3,7 @@
namespace domain\User\UserProducer;

use common\helpers\MeanPayment;
use domain\Communication\Email\Email;
use domain\Order\Order\Order;
use domain\Order\Order\OrderRepository;
use domain\Order\Order\OrderSolver;
@@ -46,6 +47,7 @@ class UserProducerBuilder extends AbstractBuilder
$userProducer->setActive(true);
$userProducer->setBookmark($bookmark);
$userProducer->setNewsletter($newsletter);
$userProducer->setNewsletterOrderTaking($newsletter);

return $userProducer;
}
@@ -188,9 +190,27 @@ class UserProducerBuilder extends AbstractBuilder
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)
{
$userProducer->newsletter = $newsletter;
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 Ver fichero

@@ -38,6 +38,7 @@

namespace producer\controllers;

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

class NewsletterController extends ProducerBaseController
@@ -49,12 +50,27 @@ class NewsletterController extends ProducerBaseController

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

if(!$user) {
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', [
'user' => $this->getUserCurrent(),
'user' => $user,
'producer' => $this->getProducerCurrent()
]);
}

+ 1
- 1
producer/views/layouts/main.php Ver fichero

@@ -220,7 +220,7 @@ $mainColor = $producer->option_main_color ?: '#ee6f42' ;
->count();
$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']);

echo Nav::widget([

+ 30
- 32
producer/views/newsletter/index.php Ver fichero

@@ -37,31 +37,13 @@ termes.
*/

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

$userModule = UserModule::getInstance();
$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">
@@ -73,20 +55,36 @@ else {
<?php if($producer->option_newsletter_description): ?>
<?= nl2br(Html::encode($producer->option_newsletter_description)); ?>
<?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; ?>
</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>
<?php endif; ?>
<?php ActiveForm::end(); ?>
</div>
<div class="col-md-4">
<div class="alert alert-dark">

+ 24
- 0
producer/web/css/screen.css Ver fichero

@@ -1952,6 +1952,30 @@ termes.
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)


+ 7
- 0
producer/web/js/producer.js Ver fichero

@@ -78,8 +78,15 @@ $(document).ready(function () {
opendistrib_datepicker();
opendistrib_fix_width_sidebar();
opendistrib_products();
opendistrib_newsletter();
});

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

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

+ 28
- 0
producer/web/sass/newsletter/_index.scss Ver fichero

@@ -0,0 +1,28 @@


.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 Ver fichero

@@ -56,4 +56,5 @@ $color-text: black;
@import "credit/_history.scss";
@import "subscription/_index.scss";
@import "subscription/_form.scss";
@import "newsletter/_index.scss";
@import "_responsive.scss";

Cargando…
Cancelar
Guardar