Ver código fonte

Utilisateurs : accès exclusif à certains points de vente

feature/rotating_product
Guillaume Bourgeois 5 meses atrás
pai
commit
530e79b0df
7 arquivos alterados com 105 adições e 15 exclusões
  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 Ver arquivo

@@ -159,6 +159,7 @@ class UserController extends BackendController
);
$userCreate->points_sale = $model->points_sale;
$userCreate->user_groups = $model->user_groups;
$userCreate->exclusive_access_selected_points_sale = $model->exclusive_access_selected_points_sale;

$this->processLinkPointSale($userCreate);
$this->processLinkUserGroup($userCreate);
@@ -220,6 +221,7 @@ class UserController extends BackendController
$model->newsletter = $userBelongToProducer->newsletter;
$model->trust_alert = $userBelongToProducer->trust_alert;
$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()) {

@@ -420,6 +422,11 @@ class UserController extends BackendController
}
}
}

// 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 Ver arquivo

@@ -111,18 +111,35 @@ $distributionModule = DistributionModule::getInstance();
</h3>
</div>
<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>
<?php endif; ?>

+ 26
- 0
console/migrations/m240626_133528_add_column_user_exclusive_access_selected_points_sale.php Ver arquivo

@@ -0,0 +1,26 @@
<?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 Ver arquivo

@@ -80,6 +80,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
var $send_mail_welcome;
var $trust_alert;
var $trust_alert_comment;
var $exclusive_access_selected_points_sale;

/**
* @inheritdoc
@@ -108,7 +109,7 @@ class User extends ActiveRecordCommon implements IdentityInterface
[['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday',
'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday',
'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', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false],
[['email', 'email_sending_invoicing_documents'], 'email', 'message' => 'Cette adresse email n\'est pas valide'],
@@ -159,7 +160,8 @@ class User extends ActiveRecordCommon implements IdentityInterface
'trust_alert_comment' => 'Commentaire',
'newsletter_souke' => "S'abonner à l'infolettre de Souke",
'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 Ver arquivo

@@ -63,7 +63,7 @@ class UserProducer extends ActiveRecordCommon
return [
[['id_user', 'id_producer'], 'required'],
[['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'],
[['trust_alert_comment'], 'string']
];
@@ -83,6 +83,7 @@ class UserProducer extends ActiveRecordCommon
'product_price_percent' => 'Prix produits : pourcentage',
'trust_alert' => 'Alert confiance',
'trust_alert_comment' => 'Commentaire',
'exclusive_access_selected_points_sale' => "Accès exclusif aux points de vente sélectionnés"
];
}

@@ -196,4 +197,15 @@ class UserProducer extends ActiveRecordCommon

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 Ver arquivo

@@ -10,4 +10,23 @@ class UserProducerSolver extends AbstractSolver
{
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 Ver arquivo

@@ -821,6 +821,7 @@ class OrderController extends ProducerBaseController
$orderModule = $this->getOrderModule();

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

if ($distribution) {
@@ -915,6 +916,12 @@ class OrderController extends ProducerBaseController
}
}

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

return $pointsSaleArray;
}


Carregando…
Cancelar
Salvar