Ver código fonte

Gestion slug producer + lien UserProducer

dev
Guillaume Bourgeois 5 anos atrás
pai
commit
5fcff79e89
6 arquivos alterados com 24 adições e 12 exclusões
  1. +1
    -1
      common/helpers/Url.php
  2. +1
    -1
      frontend/controllers/SiteController.php
  3. +0
    -1
      frontend/models/ProducerCodeForm.php
  4. +20
    -6
      frontend/models/SignupForm.php
  5. +1
    -2
      frontend/views/layouts/main.php
  6. +1
    -1
      frontend/views/site/producer_code.php

+ 1
- 1
common/helpers/Url.php Ver arquivo

@@ -143,6 +143,6 @@ class Url
public static function slugify($string)
{
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '', $string)));
}
}

+ 1
- 1
frontend/controllers/SiteController.php Ver arquivo

@@ -360,7 +360,7 @@ class SiteController extends FrontendController
*/
public function actionProducerCode($id)
{
$producer = Producer::searchOne($id);
$producer = Producer::findOne($id);
if(!$producer) {
throw new \yii\web\HttpException(404, 'Producteur introuvable');

+ 0
- 1
frontend/models/ProducerCodeForm.php Ver arquivo

@@ -77,7 +77,6 @@ class ProducerCodeForm extends Model
['code', function($attribute, $params) {
$code = $this->$attribute;
$producer = Producer::findOne($this->id_producer);

if ($producer && strtolower(trim($code)) != strtolower(trim($producer->code))) {
$this->addError($attribute, 'Code incorrect');
}

+ 20
- 6
frontend/models/SignupForm.php Ver arquivo

@@ -233,7 +233,17 @@ class SignupForm extends Model
$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) ;

$cptSlug = 0 ;
do {
$slug = \common\helpers\Url::slugify($this->name_producer) ;
if($cptSlug) {
$slug .= $cptSlug ;
}
$producer->slug = $slug ;
$cptSlug ++ ;
} while(Producer::findOne(['slug' => $producer->slug])) ;

// génération d'un code
do {
@@ -259,6 +269,11 @@ class SignupForm extends Model
->setFrom([Yii::$app->params['adminEmail'] => 'distrib'])
->setSubject('[distrib] Nouveau producteur')
->send();
$idProducer = $producer->id ;
}
else {
$idProducer = $this->id_producer ;
}

$user->setPassword($this->password);
@@ -266,13 +281,12 @@ class SignupForm extends Model
if ($user->save()) {

// on ajoute l'établissement sélectionnée par l'user en favoris
if ($this->option_user_producer == 'user' && $this->id_producer) {
$producer = Producer::find()->where(['id' => $this->id_producer])->one();
$producer = Producer::find()->where(['id' => $idProducer])->one();

if ($producer) {
Producer::addUser($user->id, $this->id_producer) ;
if ($producer) {
Producer::addUser($user->id, $idProducer) ;

if($this->option_user_producer == 'user') {
// envoi d'un email à l'utilisateur
Yii::$app->mailer->compose(
[

+ 1
- 2
frontend/views/layouts/main.php Ver arquivo

@@ -118,7 +118,7 @@ if(!Yii::$app->user->isGuest && Yii::$app->user->identity->id_producer > 0) {
'options' => ['id' => 'li-producteurs']
],
[
'label' => '<span class="glyphicon glyphicon-flag"></span> Le Chat des Noisettes',
'label' => '<span class="glyphicon glyphicon-flag"></span> '.($producer ? Html::encode($producer->name) : ''),
'url' => '#',
'items' => [
[
@@ -177,7 +177,6 @@ if(!Yii::$app->user->isGuest && Yii::$app->user->identity->id_producer > 0) {
->where([
'user_producer.id_user' => User::getCurrentId(),
'user_producer.bookmark' => 1,
'producer.active' => 1
])
->all() ;
?>

+ 1
- 1
frontend/views/site/producer_code.php Ver arquivo

@@ -45,7 +45,7 @@ $this->title = 'Producteur '.Html::encode($producer->name) ;
<h1 class="title-system-order"><?= Html::encode($producer->name) ?></h1>
<p class="info"><span class="alert alert-warning">Ce producteur est protègé par un code d'accès.</span></p>
<?php $form = ActiveForm::begin(['id' => 'producer-code','enableClientValidation'=> false]); ?>
<?= $form->field($modelProducerCode, 'code',[
<?= $form->field($producerCodeForm, 'code',[
'inputTemplate' => '<div class="input-group"><span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>{input}</div>',
])
->label('Code du producteur')

Carregando…
Cancelar
Salvar