Browse Source

[Administration] Utilisateurs > création : possibilité de choisir d'envoyer ou non l'email de bienvenue #1368

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
bd3a55c577
5 changed files with 55 additions and 25 deletions
  1. +3
    -2
      backend/controllers/UserController.php
  2. +3
    -0
      backend/views/user/_form.php
  3. +40
    -20
      backend/web/js/backend.js
  4. +4
    -1
      common/logic/User/User/Model/User.php
  5. +5
    -2
      common/logic/User/User/Service/UserBuilder.php

+ 3
- 2
backend/controllers/UserController.php View File

$model->phone, $model->phone,
$model->address, $model->address,
$model->newsletter, $model->newsletter,
Password::generate()
Password::generate(),
$model->send_mail_welcome
); );


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


// on envoie le mail de bienvenue si le mail vient d'être défini // on envoie le mail de bienvenue si le mail vient d'être défini
if (!strlen($previousMail) && strlen($model->email)) {
if (!strlen($previousMail) && strlen($model->email) && $model->send_mail_welcome) {
$password = Password::generate(); $password = Password::generate();
$userModule->setPassword($model, $password); $userModule->setPassword($model, $password);
$model->username = $model->email; $model->username = $model->email;

+ 3
- 0
backend/views/user/_form.php View File

<?= $form->field($model, 'name')->textInput() ?> <?= $form->field($model, 'name')->textInput() ?>
<?= $form->field($model, 'phone')->textInput() ?> <?= $form->field($model, 'phone')->textInput() ?>
<?= $form->field($model, 'email')->textInput() ?> <?= $form->field($model, 'email')->textInput() ?>
<?php if(!$model->email): ?>
<?= $form->field($model, 'send_mail_welcome')->checkbox() ?>
<?php endif; ?>
<?= $form->field($model, 'address')->textarea() ?> <?= $form->field($model, 'address')->textarea() ?>


<?php if ($producerModule->getSolver()->getConfig('option_export_evoliz')): ?> <?php if ($producerModule->getSolver()->getConfig('option_export_evoliz')): ?>

+ 40
- 20
backend/web/js/backend.js View File

opendistrib_dropdown_producers(); opendistrib_dropdown_producers();
opendistrib_gridview_pagesize(); opendistrib_gridview_pagesize();
opendistrib_producers_admin(); opendistrib_producers_admin();
opendistrib_user_form();
}); });


var UrlManager = { var UrlManager = {
} }
}; };


function opendistrib_user_form() {
var $fieldUserEmail = $('#app-user-form .field-user-email input');
var $fieldSendMailWelcome = $('#app-user-form .field-user-send_mail_welcome');

opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome);
$fieldUserEmail.keyup(function () {
opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome);
});
}

function opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome) {
var val = $fieldUserEmail.val();

if (val.length > 0) {
$fieldSendMailWelcome.show();
}
else {
$fieldSendMailWelcome.hide();
}
}

function opendistrib_producers_admin() { function opendistrib_producers_admin() {
$('.producer-admin-index .btn-alwaysdata, .producer-admin-index .btn-dolibarr').click(function() {
$('.producer-admin-index .btn-alwaysdata, .producer-admin-index .btn-dolibarr').click(function () {
var $button = $(this); var $button = $(this);
$button.attr('disabled', 'disabled'); $button.attr('disabled', 'disabled');
axios.get($button.attr('href'), {}) axios.get($button.attr('href'), {})
} }


function opendistrib_gridview_pagesize() { function opendistrib_gridview_pagesize() {
$('.gridview-pagesize select').change(function() {
$('.gridview-pagesize select').change(function () {
$(this).parent().parent().submit(); $(this).parent().parent().submit();
}); });
} }


function opendistrib_dropdown_producers() { function opendistrib_dropdown_producers() {


$('.producer-menu .dropdown-toggle').click(function() {
$('.producer-menu .dropdown-toggle').click(function () {
$('.producer-menu .search-producer').focus(); $('.producer-menu .search-producer').focus();
}); });


$('.producer-menu .search-producer').keyup(function() {
$('.producer-menu .search-producer').keyup(function () {
var $alertNoResults = $('.producer-menu .li-alert-no-results'); var $alertNoResults = $('.producer-menu .li-alert-no-results');
var searchWords = $(this).val().toLowerCase(); var searchWords = $(this).val().toLowerCase();
var count = 0; var count = 0;


if(searchWords && searchWords.length > 0) {
$('.producer-menu li.producer').each(function() {
if($(this).find('a').text().toLowerCase().indexOf(searchWords) >= 0 || !searchWords) {
if (searchWords && searchWords.length > 0) {
$('.producer-menu li.producer').each(function () {
if ($(this).find('a').text().toLowerCase().indexOf(searchWords) >= 0 || !searchWords) {
$(this).show(); $(this).show();
count ++;
}
else {
count++;
} else {
$(this).hide(); $(this).hide();
} }
}); });


if(count) {
if (count) {
$alertNoResults.hide(); $alertNoResults.hide();
}
else {
} else {
$alertNoResults.show(); $alertNoResults.show();
} }
}
else {
} else {
$alertNoResults.hide(); $alertNoResults.hide();
$('.producer-menu li.producer').show(); $('.producer-menu li.producer').show();
} }
}); });


$('#link-display-producers-offline').click(function() {
$('#link-display-producers-offline').click(function () {
$(this).hide(); $(this).hide();
$('.producer-menu .offline').show(); $('.producer-menu .offline').show();
return false; return false;
} }


function opendistrib_product_index() { function opendistrib_product_index() {
$('body.product-index .toggle input').change(function() {
$('body.product-index .toggle input').change(function () {
var id = $(this).data('id'); var id = $(this).data('id');
var checked = $(this).prop('checked'); var checked = $(this).prop('checked');
$.get(UrlManager.getBaseUrl() + 'product/ajax-toggle-status', { $.get(UrlManager.getBaseUrl() + 'product/ajax-toggle-status', {
taxRateSelected = 0; taxRateSelected = 0;
} }


if($('#product-price').length) {
if ($('#product-price').length) {
var price = $('#product-price').val().replace(',', '.'); var price = $('#product-price').val().replace(',', '.');
if (price) { if (price) {
$('#product-price-with-tax').val(getPriceWithTax(price, taxRateSelected)); $('#product-price-with-tax').val(getPriceWithTax(price, taxRateSelected));
opendistrib_product_prices_event_price_with_tax(); opendistrib_product_prices_event_price_with_tax();
$('#productprice-price').change(opendistrib_product_prices_event_price_with_tax); $('#productprice-price').change(opendistrib_product_prices_event_price_with_tax);
$('#productprice-price-with-tax').change(opendistrib_product_prices_event_price); $('#productprice-price-with-tax').change(opendistrib_product_prices_event_price);
$('#reduction-increase-percent').change(function() {
$('#reduction-increase-percent').change(function () {
opendistrib_product_prices_event_reduction_increase(); opendistrib_product_prices_event_reduction_increase();
}); });
} }
opendistrib_product_prices_update_reduction_increase(); opendistrib_product_prices_update_reduction_increase();
} }
} }

function opendistrib_product_prices_update_reduction_increase() { function opendistrib_product_prices_update_reduction_increase() {
var productPriceBase = $('#reduction-increase-percent').data('price-base'); var productPriceBase = $('#reduction-increase-percent').data('price-base');
var productPriceSpecific = $('#productprice-price').val().replace(',', '.'); var productPriceSpecific = $('#productprice-price').val().replace(',', '.');
function opendistrib_product_prices_event_reduction_increase() { function opendistrib_product_prices_event_reduction_increase() {
var productPriceBase = $('#reduction-increase-percent').data('price-base'); var productPriceBase = $('#reduction-increase-percent').data('price-base');
var reductionIncreasePercent = $('#reduction-increase-percent').val(); var reductionIncreasePercent = $('#reduction-increase-percent').val();
if(reductionIncreasePercent) {
if (reductionIncreasePercent) {
var newPrice = productPriceBase + productPriceBase * (reductionIncreasePercent / 100); var newPrice = productPriceBase + productPriceBase * (reductionIncreasePercent / 100);
$('#productprice-price').val(parseFloat(newPrice).toFixed(5)); $('#productprice-price').val(parseFloat(newPrice).toFixed(5));
opendistrib_product_prices_event_price_with_tax(); opendistrib_product_prices_event_price_with_tax();

+ 4
- 1
common/logic/User/User/Model/User.php View File

var $one_name; var $one_name;
var $product_price_percent; var $product_price_percent;
var $newsletter; var $newsletter;
var $send_mail_welcome;


/** /**
* @inheritdoc * @inheritdoc
return [ return [
[['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'], 'boolean'],
'mail_distribution_sunday', 'is_main_contact', 'newsletter', 'exclude_export_shopping_cart_labels',
'send_mail_welcome'], 'boolean'],
[['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person', 'evoliz_code'], 'string'], [['lastname', 'name', 'phone', 'address', 'type', 'name_legal_person', 'evoliz_code'], 'string'],
['lastname', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false], ['lastname', 'verifyOneName', 'skipOnError' => false, 'skipOnEmpty' => false],
['email', 'email', 'message' => 'Cette adresse email n\'est pas valide'], ['email', 'email', 'message' => 'Cette adresse email n\'est pas valide'],
'evoliz_code' => 'Code client Evoliz', 'evoliz_code' => 'Code client Evoliz',
'newsletter' => "Inscrit au bulletin d'information", 'newsletter' => "Inscrit au bulletin d'information",
'exclude_export_shopping_cart_labels' => "Exclure de l'export d'étiquettes", 'exclude_export_shopping_cart_labels' => "Exclure de l'export d'étiquettes",
'send_mail_welcome' => "Envoyer un email de bienvenue"
]; ];
} }



+ 5
- 2
common/logic/User/User/Service/UserBuilder.php View File

string $phone = null, string $phone = null,
string $address = null, string $address = null,
bool $newsletter = true, bool $newsletter = true,
string $password = null
string $password = null,
bool $sendMailWelcome = true
): User ): User
{ {
$userExist = null; $userExist = null;
); );
$this->create($user); $this->create($user);


$this->userNotifier->sendMailWelcome($user, $password);
if($sendMailWelcome) {
$this->userNotifier->sendMailWelcome($user, $password);
}
} }


$user->triggerEvent( $user->triggerEvent(

Loading…
Cancel
Save