Browse Source

[Administration et espace producteur] Newsletter : gestion inscription / désinscription #158

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
2b17b28a4f
9 changed files with 47 additions and 17 deletions
  1. +4
    -4
      common/logic/Producer/Producer/Service/ProducerBuilder.php
  2. +6
    -4
      common/logic/User/User/Service/NewsletterUtils.php
  3. +7
    -0
      common/logic/User/UserProducer/Model/UserProducer.php
  4. +7
    -6
      common/logic/User/UserProducer/Service/UserProducerBuilder.php
  5. +4
    -2
      frontend/forms/SignupForm.php
  6. +1
    -0
      frontend/views/site/producer.php
  7. +3
    -1
      frontend/views/site/signup.php
  8. +14
    -0
      frontend/web/js/frontend.js
  9. +1
    -0
      producer/views/layouts/main.php

+ 4
- 4
common/logic/Producer/Producer/Service/ProducerBuilder.php View File

/** /**
* Lie un utilisateur à un producteur. * Lie un utilisateur à un producteur.
*/ */
public function addUser(User $user, Producer $producer, int $bookmark = 1): UserProducer
public function addUser(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true): UserProducer
{ {
$userProducer = $this->userProducerBuilder->createUserProducerIfNotExist($user, $producer, $bookmark);
$userProducer = $this->userProducerBuilder->createUserProducerIfNotExist($user, $producer, $bookmark, $newsletter);


if (!$userProducer->getActive()) { if (!$userProducer->getActive()) {
$userProducer->setActive(1);
$userProducer->setActive(true);
} }


$this->saveUpdate($userProducer);
$this->update($userProducer);


return $userProducer; return $userProducer;
} }

+ 6
- 4
common/logic/User/User/Service/NewsletterUtils.php View File

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


public function isUserSubscribedNewsletter(User $user): bool
public function isUserSubscribedNewsletter(User $user = null): bool
{ {
$userProducer = $this->userProducerRepository->findOneUserProducer($user);
if($userProducer && $userProducer->newsletter) {
return true;
if($user) {
$userProducer = $this->userProducerRepository->findOneUserProducer($user);
if($userProducer && $userProducer->newsletter) {
return true;
}
} }


return false; return false;

+ 7
- 0
common/logic/User/UserProducer/Model/UserProducer.php View File

return $this; return $this;
} }


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

return $this;
}

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

+ 7
- 6
common/logic/User/UserProducer/Service/UserProducerBuilder.php View File

$this->orderSolver = $this->loadService(OrderSolver::class); $this->orderSolver = $this->loadService(OrderSolver::class);
} }


public function instanciateUserProducer(User $user, Producer $producer, int $bookmark = 1)
public function instanciateUserProducer(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true)
{ {
$userProducer = new UserProducer(); $userProducer = new UserProducer();


$userProducer->populateUser($user); $userProducer->populateUser($user);
$userProducer->populateproducer($producer); $userProducer->populateproducer($producer);
$userProducer->setCredit(0); $userProducer->setCredit(0);
$userProducer->setActive(1);
$userProducer->setActive(true);
$userProducer->setBookmark($bookmark); $userProducer->setBookmark($bookmark);
$userProducer->setNewsletter($newsletter);


return $userProducer; return $userProducer;
} }


public function createUserProducer(User $user, Producer $producer, int $bookmark = 1): UserProducer
public function createUserProducer(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true): UserProducer
{ {
$userProducer = $this->instanciateUserProducer($user, $producer, $bookmark);
$userProducer = $this->instanciateUserProducer($user, $producer, $bookmark, $newsletter);
$this->create($userProducer); $this->create($userProducer);
return $userProducer; return $userProducer;
} }


public function createUserProducerIfNotExist(User $user, Producer $producer, int $bookmark = 1): UserProducer
public function createUserProducerIfNotExist(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true): UserProducer
{ {
return $this->userProducerRepository->findOneUserProducer($user) return $this->userProducerRepository->findOneUserProducer($user)
?? $this->createUserProducer($user, $producer, $bookmark);
?? $this->createUserProducer($user, $producer, $bookmark, $newsletter);
} }


public function updateCredit(CreditHistory $creditHistory): void public function updateCredit(CreditHistory $creditHistory): void

+ 4
- 2
frontend/forms/SignupForm.php View File

public $id_tax_rate_default; public $id_tax_rate_default;
public $verifyCode; public $verifyCode;
public $is_test; public $is_test;
public $newsletter = true;


/** /**
* @inheritdoc * @inheritdoc
[['name', 'lastname', 'phone', 'option_user_producer'], 'string', 'min' => 2, 'max' => 255], [['name', 'lastname', 'phone', 'option_user_producer'], 'string', 'min' => 2, 'max' => 255],
['password', 'required', 'message' => 'Champs obligatoire'], ['password', 'required', 'message' => 'Champs obligatoire'],
['password', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'], ['password', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'],
['is_producer', 'boolean'],
[['is_producer', 'newsletter'], 'boolean'],
['cgv', 'boolean'], ['cgv', 'boolean'],
['cgv', function ($attribute, $params) { ['cgv', function ($attribute, $params) {
$cgv = $this->$attribute; $cgv = $this->$attribute;
// 'free_price' => 'Prix libre', // 'free_price' => 'Prix libre',
'id_tax_rate_default' => 'TVA par défaut', 'id_tax_rate_default' => 'TVA par défaut',
'verifyCode' => 'Code de vérification', 'verifyCode' => 'Code de vérification',
'newsletter' => "S'abonner au bulletin d'information de ce producteur"
]; ];
} }




\Yii::$app->logic->setProducerContext($producer); \Yii::$app->logic->setProducerContext($producer);


$producerManager->addUser($user, $producer);
$producerManager->addUser($user, $producer, true, $this->newsletter);
$userManager->sendEmailSignup($user, $producer); $userManager->sendEmailSignup($user, $producer);


return $user; return $user;

+ 1
- 0
frontend/views/site/producer.php View File

<?= $form->field($signupForm, 'lastname') ?> <?= $form->field($signupForm, 'lastname') ?>
<?= $form->field($signupForm, 'name') ?> <?= $form->field($signupForm, 'name') ?>
<?= $form->field($signupForm, 'phone') ?> <?= $form->field($signupForm, 'phone') ?>
<?= $form->field($signupForm, 'newsletter')->checkbox() ?>
<?php if(strlen($producer->code)): ?> <?php if(strlen($producer->code)): ?>
<?= $form->field($signupForm, 'code',[ <?= $form->field($signupForm, 'code',[
'inputTemplate' => '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>{input}</div>', 'inputTemplate' => '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>{input}</div>',

+ 3
- 1
frontend/views/site/signup.php View File

<?= $form->field($model, 'cgv')->checkbox()->label('J\'accepte les <button type="button" class="btn btn-xs btn-default btn-modal-cgv" data-toggle="modal" data-target="#modal-cgv">conditions générales de service</button> et les <button type="button" class="btn btn-xs btn-default btn-modal-prices" data-toggle="modal" data-target="#modal-prices">conditions tarifaires</button>.') ?> <?= $form->field($model, 'cgv')->checkbox()->label('J\'accepte les <button type="button" class="btn btn-xs btn-default btn-modal-cgv" data-toggle="modal" data-target="#modal-cgv">conditions générales de service</button> et les <button type="button" class="btn btn-xs btn-default btn-modal-prices" data-toggle="modal" data-target="#modal-prices">conditions tarifaires</button>.') ?>
</div> </div>
<div id="fields-user"> <div id="fields-user">
<?= $form->field($model, 'id_producer')->dropDownList($dataProducers, ['prompt' => '--','encode' => false,'options' => $optionsProducers]) ?>
<?= $form->field($model, 'id_producer')
->dropDownList($dataProducers, ['prompt' => '--','encode' => false,'options' => $optionsProducers]) ?>
<?= $form->field($model, 'newsletter')->checkbox() ?>
<div id="bloc-code-acces"> <div id="bloc-code-acces">
<?= $form->field($model, 'code',[ <?= $form->field($model, 'code',[
'inputTemplate' => '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>{input}</div>', 'inputTemplate' => '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>{input}</div>',

+ 14
- 0
frontend/web/js/frontend.js View File

}); });


opendistrib_signup_code_producer(); opendistrib_signup_code_producer();
opendistrib_signup_newsletter();
$('#signupform-id_producer').change(function () { $('#signupform-id_producer').change(function () {
opendistrib_signup_code_producer(); opendistrib_signup_code_producer();
opendistrib_signup_newsletter();
}); });


// modals // modals
} }
} }


function opendistrib_signup_newsletter() {
if($('#signupform-id_producer').length) {
var $fieldNewsletter = $('.field-signupform-newsletter');
if($('#signupform-id_producer').val()) {
$fieldNewsletter.show();
}
else {
$fieldNewsletter.hide();
}
}
}




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

[ [
'label' => '<span class="glyphicon glyphicon-bullhorn"></span> Bulletin d\'information <span class="label label-'.($isUserSubscribedNewsletter ? 'success' : 'danger').'">'.($isUserSubscribedNewsletter ? 'Oui' : 'Non').'</span>', 'label' => '<span class="glyphicon glyphicon-bullhorn"></span> Bulletin d\'information <span class="label label-'.($isUserSubscribedNewsletter ? 'success' : 'danger').'">'.($isUserSubscribedNewsletter ? 'Oui' : 'Non').'</span>',
'url' => $this->getUrlManagerProducer()->createUrl(['newsletter/index']), 'url' => $this->getUrlManagerProducer()->createUrl(['newsletter/index']),
'visible' => !Yii::$app->user->isGuest,
'active' => $this->getControllerAction() == 'newsletter/index', 'active' => $this->getControllerAction() == 'newsletter/index',
], ],
[ [

Loading…
Cancel
Save