Browse Source

Emails automatiques

feature/rotating_product
Guillaume Bourgeois 4 months ago
parent
commit
7e82ee95d7
8 changed files with 108 additions and 11 deletions
  1. +6
    -5
      backend/controllers/UserController.php
  2. +9
    -0
      backend/views/user/_form.php
  3. +27
    -0
      console/migrations/m240701_064424_add_column_user_producer_newsletter_order_taking.php
  4. +3
    -0
      domain/Communication/Email/Email.php
  5. +35
    -4
      domain/User/User/NewsletterManager.php
  6. +3
    -1
      domain/User/User/User.php
  7. +18
    -1
      domain/User/UserProducer/UserProducer.php
  8. +7
    -0
      domain/User/UserProducer/UserProducerBuilder.php

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

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

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

+ 35
- 4
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;
return false; return false;
} }


public function subscribeUserNewsletter(User $user): bool
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) {

}
else {

}
}

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

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;
} }


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);
if($type == Email::TYPE_NEWSLETTER) {
return $this->userProducerBuilder->updateUserProducerNewsletter($userProducer, false);
}
elseif($type == Email::TYPE_ORDER_TAKING) {
return $this->userProducerBuilder->updateUserProducerNewsletterOrderTaking($userProducer, false);
}
} }


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',

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

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

$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;
} }
$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);
}
} }

Loading…
Cancel
Save