Преглед на файлове

Emails automatiques

feature/rotating_product
Guillaume Bourgeois преди 4 месеца
родител
ревизия
7e82ee95d7
променени са 8 файла, в които са добавени 108 реда и са изтрити 11 реда
  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 Целия файл

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

+ 9
- 0
backend/views/user/_form.php Целия файл

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

+ 27
- 0
console/migrations/m240701_064424_add_column_user_producer_newsletter_order_taking.php Целия файл

@@ -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/Email.php Целия файл

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

+ 35
- 4
domain/User/User/NewsletterManager.php Целия файл

@@ -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;
@@ -30,17 +31,47 @@ class NewsletterManager extends AbstractService implements ManagerInterface
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());
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);
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;

+ 3
- 1
domain/User/User/User.php Целия файл

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

+ 18
- 1
domain/User/UserProducer/UserProducer.php Целия файл

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

+ 7
- 0
domain/User/UserProducer/UserProducerBuilder.php Целия файл

@@ -46,6 +46,7 @@ class UserProducerBuilder extends AbstractBuilder
$userProducer->setActive(true);
$userProducer->setBookmark($bookmark);
$userProducer->setNewsletter($newsletter);
$userProducer->setNewsletterOrderTaking($newsletter);

return $userProducer;
}
@@ -193,4 +194,10 @@ class UserProducerBuilder extends AbstractBuilder
$userProducer->newsletter = $newsletter;
return $this->update($userProducer);
}

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

Loading…
Отказ
Запис