Browse Source

Utilisateurs : accès exclusif à certains points de vente

feature/rotating_product
Guillaume Bourgeois 4 months ago
parent
commit
530e79b0df
7 changed files with 105 additions and 15 deletions
  1. +7
    -0
      backend/controllers/UserController.php
  2. +29
    -12
      backend/views/user/_form.php
  3. +26
    -0
      console/migrations/m240626_133528_add_column_user_exclusive_access_selected_points_sale.php
  4. +4
    -2
      domain/User/User/User.php
  5. +13
    -1
      domain/User/UserProducer/UserProducer.php
  6. +19
    -0
      domain/User/UserProducer/UserProducerSolver.php
  7. +7
    -0
      producer/controllers/OrderController.php

+ 7
- 0
backend/controllers/UserController.php View File

); );
$userCreate->points_sale = $model->points_sale; $userCreate->points_sale = $model->points_sale;
$userCreate->user_groups = $model->user_groups; $userCreate->user_groups = $model->user_groups;
$userCreate->exclusive_access_selected_points_sale = $model->exclusive_access_selected_points_sale;


$this->processLinkPointSale($userCreate); $this->processLinkPointSale($userCreate);
$this->processLinkUserGroup($userCreate); $this->processLinkUserGroup($userCreate);
$model->newsletter = $userBelongToProducer->newsletter; $model->newsletter = $userBelongToProducer->newsletter;
$model->trust_alert = $userBelongToProducer->trust_alert; $model->trust_alert = $userBelongToProducer->trust_alert;
$model->trust_alert_comment = $userBelongToProducer->trust_alert_comment; $model->trust_alert_comment = $userBelongToProducer->trust_alert_comment;
$model->exclusive_access_selected_points_sale = $userBelongToProducer->exclusive_access_selected_points_sale;


if ($model->load(\Yii::$app->request->post()) && $model->save()) { if ($model->load(\Yii::$app->request->post()) && $model->save()) {


} }
} }
} }

// Accès exclusif aux points de vente sélectionnés
$userProducer = UserProducer::findOne(['id_user' => $modelUser->id, 'id_producer' => GlobalParam::getCurrentProducerId()]);
$userProducer->setExclusiveAccessSelectedPointsSale($modelUser->exclusive_access_selected_points_sale);
$userProducer->save();
} }


/** /**

+ 29
- 12
backend/views/user/_form.php View File

</h3> </h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<?= $form->field($model, 'points_sale')->checkboxlist(
ArrayHelper::map($pointsSaleArray, 'id', function ($pointSale) use ($model) {
$commentUserPointSale = isset($pointSale->userPointSale[0]) ? $pointSale->userPointSale[0]->comment : '';
$html = Html::encode($pointSale->name);
if ($pointSale->restricted_access) {
$html .= '<input type="text" placeholder="Commentaire" class="form-control" name="User[comment_point_sale_' . $pointSale->id . ']" value="' . (($model->id) ? Html::encode($commentUserPointSale) : '') . '" />';
}
return $html;
}), [
'encode' => false
]);
?>
<div class="row">
<div class="col-md-8">
<?= $form->field($model, 'points_sale')->checkboxlist(
ArrayHelper::map($pointsSaleArray, 'id', function ($pointSale) use ($model) {
$commentUserPointSale = isset($pointSale->userPointSale[0]) ? $pointSale->userPointSale[0]->comment : '';
$html = Html::encode($pointSale->name);
if ($pointSale->restricted_access) {
$html .= '<input type="text" placeholder="Commentaire" class="form-control" name="User[comment_point_sale_' . $pointSale->id . ']" value="' . (($model->id) ? Html::encode($commentUserPointSale) : '') . '" />';
}
return $html;
}), [
'encode' => false
]);
?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'exclusive_access_selected_points_sale')->widget(Toggle::class,
[
'options' => [
'data-id' => $model->id,
'data-on' => 'Oui',
'data-off' => 'Non',
'data-onstyle' => 'success',
'data-offstyle' => 'default',
],
]
); ?>
</div>
</div>
</div> </div>
</div> </div>
<?php endif; ?> <?php endif; ?>

+ 26
- 0
console/migrations/m240626_133528_add_column_user_exclusive_access_selected_points_sale.php View File

<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m240626_133528_add_column_user_exclusive_access_selected_points_sale
*/
class m240626_133528_add_column_user_exclusive_access_selected_points_sale extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('user_producer', 'exclusive_access_selected_points_sale', Schema::TYPE_BOOLEAN);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('user_producer', 'exclusive_access_selected_points_sale');
}
}

+ 4
- 2
domain/User/User/User.php View File

var $send_mail_welcome; var $send_mail_welcome;
var $trust_alert; var $trust_alert;
var $trust_alert_comment; var $trust_alert_comment;
var $exclusive_access_selected_points_sale;


/** /**
* @inheritdoc * @inheritdoc
[['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday', [['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday',
'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday', 'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday',
'mail_distribution_sunday', 'is_main_contact', 'newsletter', 'exclude_export_shopping_cart_labels', 'mail_distribution_sunday', 'is_main_contact', 'newsletter', 'exclude_export_shopping_cart_labels',
'send_mail_welcome', 'trust_alert', 'newsletter_souke', 'problem_receiving_emails'], 'boolean'],
'send_mail_welcome', 'trust_alert', 'newsletter_souke', 'problem_receiving_emails', 'exclusive_access_selected_points_sale'], 'boolean'],
[['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person', 'evoliz_code', 'trust_alert_comment', 'note_emails'], 'string'], [['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person', 'evoliz_code', 'trust_alert_comment', 'note_emails'], 'string'],
['lastname', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false], ['lastname', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false],
[['email', 'email_sending_invoicing_documents'], 'email', 'message' => 'Cette adresse email n\'est pas valide'], [['email', 'email_sending_invoicing_documents'], 'email', 'message' => 'Cette adresse email n\'est pas valide'],
'trust_alert_comment' => 'Commentaire', 'trust_alert_comment' => 'Commentaire',
'newsletter_souke' => "S'abonner à l'infolettre de Souke", 'newsletter_souke' => "S'abonner à l'infolettre de Souke",
'problem_receiving_emails' => "Rencontre des problèmes pour recevoir les emails", 'problem_receiving_emails' => "Rencontre des problèmes pour recevoir les emails",
'note_emails' => "Note emails"
'note_emails' => "Note emails",
'exclusive_access_selected_points_sale' => "Accès exclusif aux points de vente sélectionnés"
]; ];
} }



+ 13
- 1
domain/User/UserProducer/UserProducer.php View File

return [ return [
[['id_user', 'id_producer'], 'required'], [['id_user', 'id_producer'], 'required'],
[['id_user', 'id_producer', 'product_price_percent'], 'integer'], [['id_user', 'id_producer', 'product_price_percent'], 'integer'],
[['active', 'bookmark', 'credit_active', 'newsletter', 'trust_alert'], 'boolean'],
[['active', 'bookmark', 'credit_active', 'newsletter', 'trust_alert', 'exclusive_access_selected_points_sale'], 'boolean'],
[['credit', 'product_price_percent'], 'double'], [['credit', 'product_price_percent'], 'double'],
[['trust_alert_comment'], 'string'] [['trust_alert_comment'], 'string']
]; ];
'product_price_percent' => 'Prix produits : pourcentage', 'product_price_percent' => 'Prix produits : pourcentage',
'trust_alert' => 'Alert confiance', 'trust_alert' => 'Alert confiance',
'trust_alert_comment' => 'Commentaire', 'trust_alert_comment' => 'Commentaire',
'exclusive_access_selected_points_sale' => "Accès exclusif aux points de vente sélectionnés"
]; ];
} }




return $this; return $this;
} }

public function getExclusiveAccessSelectedPointsSale(): ?bool
{
return $this->exclusive_access_selected_points_sale;
}

public function setExclusiveAccessSelectedPointsSale(?bool $exclusiveAccessSelectedPointsSale): self
{
$this->exclusive_access_selected_points_sale = $exclusiveAccessSelectedPointsSale;
return $this;
}
} }

+ 19
- 0
domain/User/UserProducer/UserProducerSolver.php View File

{ {
return $userProducer->credit < 0 || $userProducer->credit > 0; return $userProducer->credit < 0 || $userProducer->credit > 0;
} }

public function filterUserPointsSaleByExclusiveAccess(UserProducer $userProducer, array $pointsSaleArray = []): array
{
if(!$userProducer->getExclusiveAccessSelectedPointsSale()) {
return $pointsSaleArray;
}

$filteredPointsSaleArray = [];
foreach($pointsSaleArray as $pointSale) {
$idPointSale = is_array($pointSale) ? $pointSale['id'] : $pointSale->id;
foreach($userProducer->user->userPointSale as $userPointSale) {
if($idPointSale == $userPointSale->pointSale->id) {
$filteredPointsSaleArray[] = $pointSale;
}
}
}

return $filteredPointsSaleArray;
}
} }

+ 7
- 0
producer/controllers/OrderController.php View File

$orderModule = $this->getOrderModule(); $orderModule = $this->getOrderModule();


$user = GlobalParam::getCurrentUser(); $user = GlobalParam::getCurrentUser();
$userProducer = $this->getUserProducerModule()->getRepository()->findOneUserProducer($user);
$pointsSaleArray = PointSale::find(); $pointsSaleArray = PointSale::find();


if ($distribution) { if ($distribution) {
} }
} }


// Filtre par accès exclusif aux points de vente
$pointsSaleArray = $this->getUserProducerModule()->getSolver()->filterUserPointsSaleByExclusiveAccess(
$userProducer,
$pointsSaleArray
);

return $pointsSaleArray; return $pointsSaleArray;
} }



Loading…
Cancel
Save