Merge branch 'ticket-14525-parrain' into develop

This commit is contained in:
Michael RICOIS 2017-11-03 10:29:59 +01:00
commit 6adcecc54b
4 changed files with 169 additions and 16 deletions

View File

@ -407,10 +407,11 @@ class AdminCustomers extends AdminTab
}
else
echo $customer->firstname.' '.$customer->lastname.' '.$this->l('has never contacted you.');
// display hook specified to this page : AdminCustomers
if (($hook = Module::hookExec('adminCustomers', array('id_customer' => $customer->id))) !== false)
echo '<div>'.$hook.'</div>';
if (($hook = Module::hookExec('adminCustomers', array('id_customer'=>$customer->id, 'orders'=>$orders))) !== false) {
echo '<div>'.$hook.'</div>';
}
echo '<div class="clear">&nbsp;</div>';
echo '<h2>'.$this->l('Groups').' ('.sizeof($groups).')</h2>';
@ -656,7 +657,7 @@ class AdminCustomers extends AdminTab
/* Last connections */
$connections = $customer->getLastConnections();
if (sizeof($connections))
if (sizeof($connections))
{
echo '<h2>'.$this->l('Last connections').'</h2>
<table cellspacing="0" cellpadding="0" class="table">

View File

@ -0,0 +1,35 @@
<?php
$useSSL = TRUE;
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');
$id_customer = (int)Tools::getValue('id');
$id_sponsor = (int)Tools::getValue('sponsor', 0);
$token = Tools::getValue('token');
// Display form edit
if ($id_customer !== 0 && Tools::getValue('adtoken') === Tools::encrypt('InviteAdmSponsor'.$id_customer)) {
$sponsor = new Customer($id_sponsor);
$smarty->assign(array(
'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
'token' => $token,
'id_customer' => $id_customer,
'sponsor' => (Validate::isLoadedObject($sponsor)) ? $sponsor : false,
));
echo $smarty->fetch(file_exists(_PS_THEME_DIR_.'modules/invite/ajax_sponsor.tpl') ?
'../../themes/'._THEME_NAME_.'/modules/invite/ajax_sponsor.tpl' :
'ajax_sponsor.tpl', __FILE__);
exit;
}
// Search customer by email
elseif (Tools::getvalue('action') == 'search') {
$q = Tools::getValue('term');
$sql = 'SELECT `id_customer` AS id, CONCAT_WS(" ", `lastname`, `firstname`, `email`) AS value
FROM `'._DB_PREFIX_.'customer` WHERE `email` LIKE "'.$q.'%"';
$result = Db::getInstance()->executeS($sql);
echo Tools::jsonEncode($result);
exit;
}

View File

@ -0,0 +1,25 @@
<fieldset>
<legend>Rechercher par adresse email</legend>
<form name="sponsor" method="post"
action="./index.php?tab=AdminCustomers&id_customer={$id_customer}&viewcustomer&token={$token}">
{if $sponsor !== false}<span>Email du parrrain actuel: {$sponsor->email}</span><br/>{/if}
<input type="text" name="sponsor" value="" style="width: 800px"/>
<input type="hidden" name="id_sponsor" value="{if $sponsor}{$sponsor->id}{/if}"/>
<input type="submit" name="submitAddSponsor" value="Enregistrer"/>
</form>
</fieldset>
{literal}
<link type="text/css" rel="stylesheet" href="../css/jquery-ui-1.8.10.custom.css"/>
<script type="text/javascript" src="{/literal}{$base_dir}{literal}/js/jquery/jquery-ui.min.js"></script>
<script type="text/javascript" src="{/literal}{$base_dir}{literal}/js/jquery/jquery-ui-1.8.10.custom.min.js"></script>
<script type="text/javascript">
$('input[name=sponsor]').autocomplete({
source: '../modules/invite/ajax_sponsor.php?action=search',
minLength: 3,
select: function(e, ui) {
$('input[name=id_sponsor]').val(ui.item.id);
}
});
</script>
{/literal}

View File

@ -1222,8 +1222,10 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor=
return $this->display(__FILE__, 'authentication.tpl');
}
public function hookPreProcess($params) {
public function hookPreProcess($params)
{
global $cookie;
if(Configuration::get('INVITE_CREDIT_ENABLE') == 1 && $cookie->isLogged()) {
global $smarty, $page_name, $cart;
$smarty->assign('customer_credit', $this->_get_credit((int) $cookie->id_customer, FALSE, FALSE, 'frontoffice'));
@ -1256,17 +1258,70 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor=
}
}
public function hookAdminCustomers($params) {
public function hookAdminCustomers($params)
{
global $cookie;
$orders = isset($params['orders']) ? $params['orders'] : array();
$customer = new Customer((int) $params['id_customer']);
if (!Validate::isLoadedObject($customer))
die (Tools::displayError('Incorrect object Customer.'));
$result = '';
// Add / Modify a sponsor
if (Tools::getIsset('submitAddSponsor')) {
$id_sponsor = Tools::getValue('id_sponsor');
if (empty($id_sponsor)) {
// Do nothing
} else {
if (count($orders) < 2) {
$sponsor = Db::getInstance()->getRow('SELECT id_sponsor FROM `'._DB_PREFIX_.'invite`
WHERE `id_customer`='.$customer->id);
if ($sponsor['id_sponsor'] == $id_sponsor) {
$error_edit = $this->l('Le client est déjà liée à ce parrain');
}
else {
// Add
if ($sponsor === false) {
$result = Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'invite`
VALUES (
DEFAULT,
'.$id_sponsor.',
"'.pSQL($customer->email).'",
"'.pSQL($customer->lastname).'",
"'.pSQL($customer->firstname).'",
'.$customer->id.',
0,
0,
0,
0,
NOW(),
NOW(),
0
)');
}
// Replace
else {
$result = Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'invite` SET `id_sponsor`='.$id_sponsor.
' WHERE `id_customer`='.$customer->id);
}
if (count($orders) == 1 && $result) {
$sponsorCustomer = new Customer($id_sponsor);
$this->_make_rewards($sponsorCustomer->id);
}
}
}
else {
$error_edit = $this->l('Le client a déjà passé plus d\'une commande');
}
}
}
if(Configuration::get('INVITE_CREDIT_ENABLE') == 1) {
if (Configuration::get('INVITE_CREDIT_ENABLE') == 1) {
$credit = $this->_get_credit($customer->id, FALSE, FALSE, 'info');
$result .= '
@ -1287,16 +1342,43 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor=
$invitelink = $link->getPageLink('authentication.php', TRUE).'?create_account=1&sponsor='.urlencode($cipherTool->encrypt('1|'.$customer->email.'|'));
}
$sponsor_edit = '';
if (count($orders) < 2) {
if ($sponsor) {
$sponsor_edit = '<button onclick="var btn = $(this); btn.attr(\'disabled\', \'disabled\'); $.ajax({
url: \''.__PS_BASE_URI__.'modules/invite/ajax_sponsor.php?id='.$customer->id.
'&sponsor='.$sponsor['id_customer'].'&token='.Tools::getAdminTokenLite('AdminCustomers').
'&adtoken='.Tools::encrypt('InviteAdmSponsor'.$customer->id).'\',
success: function(response) {
btn.replaceWith(response)
}
});" class="button">'.$this->l('Click here to replace sponsor').'</button>';
} else {
$sponsor_edit = '<button onclick="var btn = $(this); btn.attr(\'disabled\', \'disabled\'); $.ajax({
url: \''.__PS_BASE_URI__.'modules/invite/ajax_sponsor.php?id='.$customer->id.
'&pending=1&token='.Tools::getAdminTokenLite('AdminCustomers').'&adtoken='.Tools::encrypt('InviteAdmSponsor'.$customer->id).'\',
success: function(response) {
btn.replaceWith(response)
}
});" class="button">'.$this->l('Click here to add a sponsor').'</button>';
}
}
$result .= '
<div class="clear">&nbsp;</div>
<h2>'.$this->l('Referral program').'</h2>
<h3>'.$this->l('Invite link:').'</h3>
<input type="text" style="width: 800px" onclick="$(this).select();" value="'.$invitelink.'" />
<br /><br /><br />
<h3>'.($sponsor? $this->l('Customer\'s sponsor:').' <a href="index.php?tab=AdminCustomers&id_customer='.(int) $sponsor['id_customer'].'&viewcustomer&token='.Tools::getAdminToken('AdminCustomers'.(int) Tab::getIdFromClassName('AdminCustomers').(int) $cookie->id_employee).'">'.$sponsor['firstname'].' '.$sponsor['lastname'].'</a>': $this->l('No one has sponsored this customer.')).'</h3>
'.(empty($error_edit) ? '' : $error_edit).'
<br /><br /><br />
<h3>'.($sponsor?
$this->l('Customer\'s sponsor:').' <a href="index.php?tab=AdminCustomers&id_customer='.(int) $sponsor['id_customer'].'&viewcustomer&token='.Tools::getAdminToken('AdminCustomers'.(int) Tab::getIdFromClassName('AdminCustomers').(int) $cookie->id_employee).'">'.$sponsor['firstname'].' '.$sponsor['lastname'].'</a>' :
$this->l('No one has sponsored this customer.')).
'</h3>
<br/>'.$sponsor_edit.'<br /><br /><br />
<br />
<h3>'.$this->l('Customer\'s pending friends:').'</h3>
<h3>'.$this->l('Customer\'s pending friends:').'</h3>
<button onclick="var btn = $(this); btn.attr(\'disabled\', \'disabled\'); $.ajax({
url: \''.__PS_BASE_URI__.'modules/invite/ajax_friends.php?id='.$customer->id.'&pending=1&adtoken='.Tools::encrypt('InviteAdmFriendsPending'.$customer->id).'\',
success: function(response) {
@ -1567,10 +1649,12 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor=
}
}
private function _make_rewards($customer, $sponsored=FALSE) {
private function _make_rewards($customer, $sponsored=FALSE)
{
global $cookie;
$reward_type = Configuration::get('INVITE_REWARD_SPONSOR'.($sponsored? 'ED': '').'_TYPE');
// Credit
if($reward_type == 1) {
$groups = $customer->getGroups();
$value = 0;
@ -1613,7 +1697,9 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor=
'credit' => $value,
));
}
} elseif($reward_type == 2) {
}
// Points de fidélité
elseif($reward_type == 2) {
$groups = $customer->getGroups();
$value = 0;
foreach($groups as $group) {
@ -1657,7 +1743,9 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor=
'value' => $value,
));
}
} elseif($reward_type == 3) {
}
// Bon de réduction (%)
elseif($reward_type == 3) {
$groups = $customer->getGroups();
$value = 0;
foreach($groups as $group) {
@ -1688,7 +1776,9 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor=
'discount_value' => $discount->value.'%',
));
}
} elseif($reward_type == 4) {
}
// Bon de réduction (valeur)
elseif($reward_type == 4) {
$groups = $customer->getGroups();
$value = 0;
foreach($groups as $group) {
@ -1721,7 +1811,9 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor=
'discount_value' => $discount->value.$currency->sign,
));
}
} elseif($reward_type == 5) {
}
// Bon de réduction (frais de port gratuit)
elseif($reward_type == 5) {
$discount = $this->_register_discount(array(
'discount_type' => 3,
'id_customer' => $customer->id,