Add condition following number of orders

This commit is contained in:
Michael RICOIS 2017-10-31 16:45:07 +01:00
parent 7bd7624200
commit bee38c462b
2 changed files with 54 additions and 40 deletions

View File

@ -409,8 +409,9 @@ class AdminCustomers extends AdminTab
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

@ -1262,6 +1262,7 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor=
{
global $cookie;
$orders = isset($params['orders']) ? $params['orders'] : array();
$customer = new Customer((int) $params['id_customer']);
if (!Validate::isLoadedObject($customer))
@ -1275,37 +1276,47 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor=
if (empty($id_sponsor)) {
// Do nothing
} else {
$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 possède déjà ce parrain');
}
else {
// Add
if ($sponsor === false) {
Db::getInstance()->ExecuteS('
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
)');
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');
}
// Replace
else {
Db::getInstance()->ExecuteS('UPDATE `'._DB_PREFIX_.'invite` SET `id_sponsor`='.$id_sponsor.
' WHERE `id_customer`='.$customer->id);
}
// 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');
}
}
}
@ -1331,23 +1342,25 @@ 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.'|'));
}
if ($sponsor) {
$sponsor_edit = '<button onclick="var btn = $(this); btn.attr(\'disabled\', \'disabled\'); $.ajax({
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).'\',
'&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({
});" 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>';
});" class="button">'.$this->l('Click here to add a sponsor').'</button>';
}
}
$result .= '