ソースを参照

[producer] Correction bug UserProducer non initialisé

dev
コミット
4f3daa9a9b
2個のファイルの変更14行の追加10行の削除
  1. +2
    -2
      common/models/Producer.php
  2. +12
    -8
      producer/controllers/ProducerBaseController.php

+ 2
- 2
common/models/Producer.php ファイルの表示

@@ -366,7 +366,7 @@ class Producer extends ActiveRecordCommon
* @param integer $id_producer
* @return UserProducer
*/
public static function addUser($idUser, $idProducer)
public static function addUser($idUser, $idProducer, $bookmark = 1)
{
$userProducer = UserProducer::searchOne([
'user_producer.id_user' => $idUser,
@@ -379,7 +379,7 @@ class Producer extends ActiveRecordCommon
$newUserProducer->id_user = $idUser;
$newUserProducer->credit = 0;
$newUserProducer->active = 1;
$newUserProducer->bookmark = 1;
$newUserProducer->bookmark = (int) $bookmark ;
$newUserProducer->save();
} else {
if (!$userProducer->active) {

+ 12
- 8
producer/controllers/ProducerBaseController.php ファイルの表示

@@ -58,9 +58,15 @@ class ProducerBaseController extends CommonController
public function beforeAction($event)
{
$producer = $this->getProducer() ;
$userProducer = UserProducer::find()
->where([
'id_user' => User::getCurrentId(),
'id_producer' => $producer->id
])
->one() ;
/*
* Producteur protègé par un code
*/
@@ -73,18 +79,12 @@ class ProducerBaseController extends CommonController
}
// si l'utilisateur est connecté et qu'il n'a pas encore saisi de code
else {
$userProducer = UserProducer::find()
->where([
'id_user' => User::getCurrentId(),
'id_producer' => $producer->id
])
->one() ;
if(!$userProducer || ($userProducer && !$userProducer->active)) {
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-code','id' => $producer->id])) ;
}
}
}
/*
* Producteur hors ligne
*/
@@ -92,6 +92,10 @@ class ProducerBaseController extends CommonController
$this->redirect(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/producer-offline','id' => $producer->id])) ;
}
if(!$userProducer) {
Producer::addUser(User::getCurrentId(), $producer->id, 0) ;
}
return parent::beforeAction($event);
}

読み込み中…
キャンセル
保存