Explorar el Código

Adaptations frontend/site/signup

dev
Guillaume Bourgeois hace 5 años
padre
commit
78bfb0943f
Se han modificado 14 ficheros con 118 adiciones y 117 borrados
  1. +1
    -2
      backend/controllers/OrderController.php
  2. +1
    -1
      backend/web/js/lechatdesnoisettes.js
  3. +3
    -1
      common/components/ActiveRecordCommon.php
  4. +1
    -1
      common/helpers/Departments.php
  5. +1
    -1
      common/mail/new-producer-html.php
  6. +1
    -1
      common/mail/new-producer-text.php
  7. +4
    -4
      common/mail/signup-html.php
  8. +4
    -4
      common/mail/signup-text.php
  9. +2
    -2
      common/models/Producer.php
  10. +2
    -2
      frontend/controllers/SiteController.php
  11. +81
    -82
      frontend/models/SignupForm.php
  12. +4
    -4
      frontend/views/site/signup.php
  13. +6
    -6
      frontend/web/js/boulange.js
  14. +7
    -6
      producer/web/js/boulange.js

+ 1
- 2
backend/controllers/OrderController.php Ver fichero

@@ -43,7 +43,6 @@ use common\models\ProductOrder ;
use common\models\Product ;
use common\models\User ;
use common\models\ProductDistribution ;
use common\models\Product ;

class OrderController extends BackendController
{
@@ -691,7 +690,7 @@ class OrderController extends BackendController
/**
* Génère le contenu nécessaire aux exports au format CSV.
*
* @see CommandeController::actionDownload()
* @see OrderController::actionDownload()
* @param string $date
* @param array $produits
* @param array $points_vente

+ 1
- 1
backend/web/js/lechatdesnoisettes.js Ver fichero

@@ -748,7 +748,7 @@ function chat_calendar() {
dayClick: function(date, jsEvent, view) {
var url = $(location).attr('href') ;
var tab_url = url.split('?') ;
$(location).attr('href',tab_url[0]+'?r=commande/index&date='+date.format());
$(location).attr('href',tab_url[0]+'?r=order/index&date='+date.format());
},
eventRender: function (event, element) {
var dataToFind = moment(event.start).format('YYYY-MM-DD');

+ 3
- 1
common/components/ActiveRecordCommon.php Ver fichero

@@ -70,7 +70,9 @@ class ActiveRecordCommon extends \yii\db\ActiveRecord
$pk = $class::primaryKey() ;
$pk = $class::tableName().'.'.$pk[0] ;
if (!isset($params[$options['attribute_id_producer']]) && !Yii::$app->user->isGuest) {
if (isset($options['attribute_id_producer']) && strlen($options['attribute_id_producer'])
&& !isset($params[$options['attribute_id_producer']]) && !Yii::$app->user->isGuest)
{
$params[$options['attribute_id_producer']] = Producer::getId();
}

common/helpers/Departements.php → common/helpers/Departments.php Ver fichero

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

namespace common\helpers;

class Departements {
class Departments {

public static function get()
{

common/mail/new-boulanger-html.php → common/mail/new-producer-html.php Ver fichero

@@ -40,6 +40,6 @@ use yii\helpers\Html;

?>

<p>Un nouveau producteur vient de s'inscrire : <strong><?= Html::encode($etablissement->nom) ?></strong>.</p>
<p>Un nouveau producteur vient de s'inscrire : <strong><?= Html::encode($producer->name) ?></strong>.</p>



common/mail/new-boulanger-text.php → common/mail/new-producer-text.php Ver fichero

@@ -38,4 +38,4 @@ termes.

?>

Un nouveau producteur vient de s'inscrire : <?= $etablissement->nom; ?>.
Un nouveau producteur vient de s'inscrire : <?= $producer->name; ?>.

+ 4
- 4
common/mail/signup-html.php Ver fichero

@@ -42,7 +42,7 @@ use common\helpers\Url ;

?>

<p>Bonjour <?= Html::encode($user->prenom) ?>,</p>
<p>Bonjour <?= Html::encode($user->name) ?>,</p>

<p>Votre inscription sur <strong>La boîte à pain</strong> a bien été prise en compte.</p>

@@ -50,11 +50,11 @@ use common\helpers\Url ;
<strong><?= Html::encode($user->email) ?></strong></p>

<?php if($user->status == User::STATUS_PRODUCER): ?>
<p>Vous pouvez dès maintenant vous connecter à votre <a href="<?= Url::backend(); ?>">Espace boulanger</a> pour mettre
<p>Vous pouvez dès maintenant vous connecter à votre <a href="<?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?>">Espace producteur</a> pour mettre
en place votre système de réservation.</p>
<?php else: ?>
<?php if(!is_null($etablissement)): ?>
<p>Vous pouvez maintenant <a href="<?= Url::frontend().'index.php?r=commande/create&id_etablissement='.$etablissement->id ?>">passer commande</a> chez votre producteur <strong><?= Html::encode($etablissement->nom); ?></strong>.</p>
<?php if(!is_null($producer)): ?>
<p>Vous pouvez maintenant <a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]); ?>">passer commande</a> chez votre producteur <strong><?= Html::encode($producer->name); ?></strong>.</p>
<?php else: ?>
<p>Vous pouvez maintenant passer commande chez votre producteur.</p>
<?php endif; ?>

+ 4
- 4
common/mail/signup-text.php Ver fichero

@@ -50,11 +50,11 @@ Voici votre identifiant de connexion :

<?php if($user->status == User::STATUS_PRODUCER): ?>
Vous pouvez dès maintenant vous connecter à votre Espace boulanger pour mettre en place votre système de réservation :
<?= Url::backend(); ?>
<?= Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']); ?>
<?php else: ?>
<?php if(!is_null($etablissement)): ?>
Vous pouvez maintenant passer commande chez votre producteur "<?= $etablissement->nom ?>" :
<?= Url::frontend().'index.php?r=commande/create&id_etablissement='.$etablissement->id ?>
<?php if(!is_null($producer)): ?>
Vous pouvez maintenant passer commande chez votre producteur "<?= $producer->name ?>" :
<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]) ; ?>
<?php else: ?>
Vous pouvez maintenant passer commande chez votre producteur.
<?php endif; ?>

+ 2
- 2
common/models/Producer.php Ver fichero

@@ -167,12 +167,12 @@ class Producer extends ActiveRecordCommon
['orderby' => 'postcode, city ASC']
) ;
$departments = Departmments::get();
$departments = Departments::get();
$dataProducers = [];
$optionsProducers = [];
foreach ($producers as $p) {
if (!key_exists('d' . substr($p->postcode, 0, 2), $dataProducers)) {
$dataProducers['d' . substr($p->postcode, 0, 2)] = '<strong>' . $departments[substr($e->postcode, 0, 2)] . '</strong>';
$dataProducers['d' . substr($p->postcode, 0, 2)] = '<strong>' . $departments[substr($p->postcode, 0, 2)] . '</strong>';
$optionsProducers['d' . substr($p->postcode, 0, 2)] = ['disabled' => true];
}


+ 2
- 2
frontend/controllers/SiteController.php Ver fichero

@@ -179,7 +179,7 @@ class SiteController extends FrontendController
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return Yii::$app->getResponse()->redirect(['commande/index']);
return Yii::$app->getResponse()->redirect(['order/index']);
}

$model = new LoginForm();
@@ -243,7 +243,7 @@ class SiteController extends FrontendController
if ($model->load(Yii::$app->request->post())) {
if ($user = $model->signup()) {
if (Yii::$app->getUser()->login($user)) {
$this->redirect(['commande/index']);
$this->redirect(['site/index']);
}
}
}

+ 81
- 82
frontend/models/SignupForm.php Ver fichero

@@ -40,9 +40,9 @@ namespace frontend\models;

use Yii;
use common\models\User;
use common\models\Etablissement;
use common\models\Producer;
use yii\base\Model;
use common\models\UserEtablissement;
use common\models\UserProducer;
use common\helpers\Password;

/**
@@ -59,15 +59,15 @@ class SignupForm extends Model
public $phone;
public $is_producer;
public $siret;
public $nom_magasin;
public $code_postal;
public $ville;
public $id_etablissement;
public $option_client_boulanger;
public $name_producer;
public $postcode;
public $city;
public $id_producer;
public $option_user_producer;
public $cgv;
public $code;
public $type;
public $prix_libre ;
public $free_price ;

/**
* @inheritdoc
@@ -79,46 +79,46 @@ class SignupForm extends Model
['email', 'required', 'message' => 'Champs obligatoire'],
['email', 'email'],
['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'Cet email est déjà utilisé'],
[['nom', 'prenom', 'telephone'], 'required', 'message' => 'Champs obligatoire'],
[['nom', 'prenom', 'telephone', 'option_client_boulanger'], 'string', 'min' => 2, 'max' => 255],
[['name', 'lastname', 'phone'], 'required', 'message' => 'Champs obligatoire'],
[['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_boulanger', 'boolean'],
['is_producer', 'boolean'],
['cgv', 'boolean'],
['cgv', function($attribute, $params) {
$cgv = $this->$attribute;

if ($this->option_client_boulanger == 'boulanger' && !$cgv) {
if ($this->option_user_producer == 'producer' && !$cgv) {
$this->addError($attribute, 'Vous devez accepter les conditions générales de vente pour vous inscrire.');
}
}],
['code_postal', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
return $model->option_client_boulanger == 'boulanger';
['postcode', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
return $model->option_user_producer == 'producer';
}, 'whenClient' => "function (attribute, value) {
return $('#option-boulanger').prop('checked') ;
return $('#option-producer').prop('checked') ;
}"],
['ville', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
return $model->option_client_boulanger == 'boulanger';
['city', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
return $model->option_user_producer == 'producer';
}, 'whenClient' => "function (attribute, value) {
return $('#option-boulanger').prop('checked') ;
return $('#option-producer').prop('checked') ;
}"],
['nom_magasin', 'string'],
['nom_magasin', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
return $model->option_client_boulanger == 'boulanger';
['name_producer', 'string'],
['name_producer', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
return $model->option_user_producer == 'producer';
}, 'whenClient' => "function (attribute, value) {
return $('#option-boulanger').prop('checked') ;
return $('#option-producer').prop('checked') ;
}"],
['type', 'string'],
['type', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
return $model->option_client_boulanger == 'boulanger';
return $model->option_user_producer == 'producer';
}, 'whenClient' => "function (attribute, value) {
return $('#option-boulanger').prop('checked') ;
return $('#option-producer').prop('checked') ;
}"],
['siret', 'string'],
['siret', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
return $model->option_client_boulanger == 'boulanger';
return $model->option_user_producer == 'producer';
}, 'whenClient' => "function (attribute, value) {
return $('#option-boulanger').prop('checked') ;
return $('#option-producer').prop('checked') ;
}"],
['siret', function($attribute, $params) {

@@ -154,32 +154,32 @@ class SignupForm extends Model
if (($sum % 10) != 0)
$this->addError($attribute, 'Numéro SIRET invalide');
}],
['id_etablissement', 'integer'],
['id_etablissement', function($attribute, $params) {
if ($this->id_etablissement) {
$etablissement = Etablissement::findOne($this->id_etablissement);
if (!$etablissement) {
['id_producer', 'integer'],
['id_producer', function($attribute, $params) {
if ($this->id_producer) {
$producer = Producer::findOne($this->id_producer);
if (!$producer) {
$this->addError($attribute, 'Ce producteur n\'existe pas.');
}
}
}],
['code', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) {
$etablissement = Etablissement::findOne($this->id_etablissement);
if ($etablissement) {
return strlen($etablissement->code);
$producer = Producer::findOne($this->id_producer);
if ($producer) {
return strlen($producer->code);
} else {
return false;
}
}],
['code', function($attribute, $params) {
$code = $this->$attribute;
$etablissement = Etablissement::findOne($this->id_etablissement);
$producer = Producer::findOne($this->id_producer);

if ($etablissement && strtolower(trim($code)) != strtolower(trim($etablissement->code))) {
if ($producer && strtolower(trim($code)) != strtolower(trim($producer->code))) {
$this->addError($attribute, 'Code incorrect');
}
}],
['prix_libre', 'number'],
['free_price', 'number'],
];
}
@@ -190,16 +190,17 @@ class SignupForm extends Model
'username' => 'Identifiant',
'password' => 'Mot de passe',
'rememberMe' => 'Se souvenir de moi',
'prenom' => 'Prénom',
'telephone' => 'Téléphone',
'is_boulanger' => "Je suis professionnel et souhaite mettre en place un système de réservation dans mon établissement",
'nom_magasin' => 'Nom de l\'établissement',
'name' => 'Prénom',
'lastname' => 'Nom',
'phone' => 'Téléphone',
'is_producer' => "Je suis professionnel et souhaite mettre en place un système de réservation dans mon établissement",
'name_producer' => 'Nom du producteur',
'siret' => 'Numéro SIRET',
'code_postal' => 'Code postal',
'ville' => 'Commune',
'id_etablissement' => 'Producteur',
'type' => 'Type d\'établissement',
'prix_libre' => 'Prix libre'
'postcode' => 'Code postal',
'city' => 'Commune',
'id_producer' => 'Producteur',
'type' => 'Type de producteur',
'free_price' => 'Prix libre'
];
}

@@ -214,44 +215,42 @@ class SignupForm extends Model
$user = new User();
$user->username = $this->email;
$user->email = $this->email;
$user->nom = $this->nom;
$user->prenom = $this->prenom;
$user->telephone = $this->telephone;
$user->confiance = 1;
$user->name = $this->name;
$user->lastname = $this->lastname;
$user->phone = $this->phone;

if ($this->option_client_boulanger == 'boulanger') {
if ($this->option_user_producer == 'producer') {
// etablissement
$etablissement = new Etablissement;
$etablissement->nom = $this->nom_magasin;
$etablissement->type = $this->type;
$etablissement->siret = $this->siret;
$etablissement->code_postal = $this->code_postal;
$etablissement->ville = $this->ville;
$etablissement->heure_limite_commande = 20;
$etablissement->delai_commande = 1;
$etablissement->gratuit = 1;
$etablissement->prix_libre = (float) abs($this->prix_libre);
$etablissement->slug = \common\helpers\Url::slugify($this->nom_magasin) ;
$producer = new Producer;
$producer->name = $this->name_producer;
$producer->type = $this->type;
$producer->siret = $this->siret;
$producer->postcode = $this->postcode;
$producer->city = $this->city;
$producer->order_deadline = 20;
$producer->order_delay = 1;
$producer->free_price = (float) abs($this->free_price);
$producer->slug = \common\helpers\Url::slugify($this->name_producer) ;

// génération d'un code
do {
$code = Password::generate();
$etablissement->code = $code;
} while (Etablissement::findOne(['code' => $code]));
$producer->code = $code;
} while (Producer::findOne(['code' => $code]));

$etablissement->save();
$producer->save();

// user
$user->id_etablissement = $etablissement->id;
$user->id_producer = $producer->id;
$user->status = User::STATUS_PRODUCER;

// envoi d'un email à l'administrateur pour le prévenir
Yii::$app->mailer->compose(
[
'html' => 'new-boulanger-html',
'text' => 'new-boulanger-text'
'html' => 'new-producer-html',
'text' => 'new-producer-text'
], [
'etablissement' => $etablissement
'producer' => $producer
])
->setTo(Yii::$app->params['adminEmail'])
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain'])
@@ -264,11 +263,11 @@ class SignupForm extends Model
if ($user->save()) {

// on ajoute l'établissement sélectionnée par l'user en favoris
if ($this->option_client_boulanger == 'client') {
if ($this->id_etablissement) {
$etablissement = Etablissement::find()->where(['id' => $this->id_etablissement])->one();
if ($etablissement) {
Etablissement::addUser($user->id, $this->id_etablissement) ;
if ($this->option_user_producer == 'producer') {
if ($this->id_producer) {
$producer = Producer::find()->where(['id' => $this->id_producer])->one();
if ($producer) {
Producer::addUser($user->id, $this->id_producer) ;

// envoi d'un email à l'utilisateur
Yii::$app->mailer->compose(
@@ -278,7 +277,7 @@ class SignupForm extends Model
],
[
'user' => $user,
'etablissement' => $etablissement
'producer' => $producer
])
->setTo($user->email)
->setFrom([Yii::$app->params['adminEmail'] => 'La boîte à pain'])
@@ -288,13 +287,13 @@ class SignupForm extends Model
}
}

if ($this->option_client_boulanger == 'boulanger') {
$etab_user = new UserEtablissement;
$etab_user->id_etablissement = $etablissement->id;
$etab_user->id_user = $user->id;
$etab_user->credit = 0;
$etab_user->actif = 1;
$etab_user->save();
if ($this->option_user_producer == 'producer') {
$userProducer = new UserProducer;
$userProducer->id_producer = $producer->id;
$userProducer->id_user = $user->id;
$userProducer->credit = 0;
$userProducer->active = 1;
$userProducer->save();
}

return $user;

+ 4
- 4
frontend/views/site/signup.php Ver fichero

@@ -73,8 +73,8 @@ $this->params['breadcrumbs'][] = $this->title;
</label>
</div>

<div id="champs-boulanger">
<?= $form->field($model, 'name') ?>
<div id="fields-producer">
<?= $form->field($model, 'name_producer') ?>
<?= $form->field($model, 'type')->textInput(['placeholder' => 'Boulangerie, brasserie, ferme ...']); ?>
<?= $form->field($model, 'siret') ?>
<?= $form->field($model, 'postcode') ?>
@@ -84,9 +84,9 @@ $this->params['breadcrumbs'][] = $this->title;
])
->label('Prix libre HT / mois')
->hint('Laissez ce champs vide si vous souhaitez dans un premier temps simplement tester la plateforme. Une fois l\'outil mis en place dans votre structure, vous pourrez modifier ce coût dans la section "Mon abonnement" de votre panneau d\'administration.') ; ?>
<?= $form->field($model, 'cgv')->checkbox()->label('J\'accepte les <a class="btn btn-xs btn-default" data-toggle="modal" data-target="#modal-cgv" href="javascript:void(0);">conditions générales de service</a> et les <a class="btn btn-xs btn-default" data-toggle="modal" data-target="#modal-tarifs" href="javascript:void(0);">conditions tarifaires</a> (prix libre).') ?>
<?= $form->field($model, 'cgv')->checkbox()->label('J\'accepte les <a class="btn btn-xs btn-default" data-toggle="modal" data-target="#modal-cgv" href="javascript:void(0);">conditions générales de service</a> et les <a class="btn btn-xs btn-default" data-toggle="modal" data-target="#modal-prices" href="javascript:void(0);">conditions tarifaires</a> (prix libre).') ?>
</div>
<div id="champs-user">
<div id="fields-user">
<?= $form->field($model, 'id_producer')->dropDownList($dataProducers, ['prompt' => '--','encode' => false,'options' => $optionsProducers]) ?>
<div id="bloc-code-acces">
<?= $form->field($model, 'code',[

+ 6
- 6
frontend/web/js/boulange.js Ver fichero

@@ -86,7 +86,7 @@ function boulange_signup()
if($('#form-signup').size())
{
boulange_signup_champs_boulanger() ;
$('#option-client, #option-boulanger').change(function() {
$('#option-user, #option-producer').change(function() {
boulange_signup_champs_boulanger() ;
}) ;
}
@@ -94,14 +94,14 @@ function boulange_signup()

function boulange_signup_champs_boulanger()
{
if($('#option-boulanger').prop('checked'))
if($('#option-producer').prop('checked'))
{
$('#champs-boulanger').fadeIn() ;
$('#champs-client').hide() ;
$('#fields-producer').fadeIn() ;
$('#fields-user').hide() ;
}
else {
$('#champs-boulanger').hide() ;
$('#champs-client').fadeIn() ;
$('#fields-producer').hide() ;
$('#fields-user').fadeIn() ;
}
}


+ 7
- 6
producer/web/js/boulange.js Ver fichero

@@ -86,7 +86,7 @@ function boulange_signup()
if($('#form-signup').size())
{
boulange_signup_champs_boulanger() ;
$('#option-client, #option-boulanger').change(function() {
$('#option-user, #option-producer').change(function() {
boulange_signup_champs_boulanger() ;
}) ;
}
@@ -94,14 +94,15 @@ function boulange_signup()

function boulange_signup_champs_boulanger()
{
if($('#option-boulanger').prop('checked'))
if($('#option-producer').prop('checked'))
{
$('#champs-boulanger').fadeIn() ;
$('#champs-client').hide() ;
$('#fields-producer').fadeIn() ;
$('#fields-user').hide() ;
}
else {
$('#champs-boulanger').hide() ;
$('#champs-client').fadeIn() ;
$('#fields-producer').hide() ;
$('#fields-user').fadeIn() ;
}
}


Cargando…
Cancelar
Guardar