Selaa lähdekoodia

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

feature/souke
Guillaume Bourgeois 1 vuosi sitten
vanhempi
commit
2b17b28a4f
9 muutettua tiedostoa jossa 47 lisäystä ja 17 poistoa
  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 Näytä tiedosto

@@ -64,15 +64,15 @@ class ProducerBuilder extends AbstractBuilder
/**
* 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()) {
$userProducer->setActive(1);
$userProducer->setActive(true);
}

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

return $userProducer;
}

+ 6
- 4
common/logic/User/User/Service/NewsletterUtils.php Näytä tiedosto

@@ -19,11 +19,13 @@ class NewsletterUtils extends AbstractService implements UtilsInterface
$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;

+ 7
- 0
common/logic/User/UserProducer/Model/UserProducer.php Näytä tiedosto

@@ -152,6 +152,13 @@ class UserProducer extends ActiveRecordCommon
return $this;
}

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

return $this;
}

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

+ 7
- 6
common/logic/User/UserProducer/Service/UserProducerBuilder.php Näytä tiedosto

@@ -32,30 +32,31 @@ class UserProducerBuilder extends AbstractBuilder
$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->populateUser($user);
$userProducer->populateproducer($producer);
$userProducer->setCredit(0);
$userProducer->setActive(1);
$userProducer->setActive(true);
$userProducer->setBookmark($bookmark);
$userProducer->setNewsletter($newsletter);

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);
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)
?? $this->createUserProducer($user, $producer, $bookmark);
?? $this->createUserProducer($user, $producer, $bookmark, $newsletter);
}

public function updateCredit(CreditHistory $creditHistory): void

+ 4
- 2
frontend/forms/SignupForm.php Näytä tiedosto

@@ -70,6 +70,7 @@ class SignupForm extends Model
public $id_tax_rate_default;
public $verifyCode;
public $is_test;
public $newsletter = true;

/**
* @inheritdoc
@@ -96,7 +97,7 @@ class SignupForm extends Model
[['name', 'lastname', 'phone', 'option_user_producer'], 'string', 'min' => 2, 'max' => 255],
['password', 'required', 'message' => 'Champs obligatoire'],
['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', function ($attribute, $params) {
$cgv = $this->$attribute;
@@ -222,6 +223,7 @@ class SignupForm extends Model
// 'free_price' => 'Prix libre',
'id_tax_rate_default' => 'TVA par défaut',
'verifyCode' => 'Code de vérification',
'newsletter' => "S'abonner au bulletin d'information de ce producteur"
];
}

@@ -253,7 +255,7 @@ class SignupForm extends Model

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

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

return $user;

+ 1
- 0
frontend/views/site/producer.php Näytä tiedosto

@@ -100,6 +100,7 @@ $this->setMeta('description', 'Veuillez vous connecter pour réserver les produi
<?= $form->field($signupForm, 'lastname') ?>
<?= $form->field($signupForm, 'name') ?>
<?= $form->field($signupForm, 'phone') ?>
<?= $form->field($signupForm, 'newsletter')->checkbox() ?>
<?php if(strlen($producer->code)): ?>
<?= $form->field($signupForm, 'code',[
'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 Näytä tiedosto

@@ -87,7 +87,9 @@ $this->params['breadcrumbs'][] = $this->title;
<?= $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 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">
<?= $form->field($model, 'code',[
'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 Näytä tiedosto

@@ -197,8 +197,10 @@ function opendistrib_signup() {
});

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

// modals
@@ -231,4 +233,16 @@ function opendistrib_signup_code_producer() {
}
}

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 Näytä tiedosto

@@ -172,6 +172,7 @@ if (!Yii::$app->user->isGuest) {
[
'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']),
'visible' => !Yii::$app->user->isGuest,
'active' => $this->getControllerAction() == 'newsletter/index',
],
[

Loading…
Peruuta
Tallenna