From bee38c462b2f61b5f181650302f1ea62b05392b4 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Tue, 31 Oct 2017 16:45:07 +0100 Subject: [PATCH] Add condition following number of orders --- adm/tabs/AdminCustomers.php | 7 +-- modules/invite/invite.php | 87 +++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/adm/tabs/AdminCustomers.php b/adm/tabs/AdminCustomers.php index cfe855e4..e95a0cba 100755 --- a/adm/tabs/AdminCustomers.php +++ b/adm/tabs/AdminCustomers.php @@ -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 '
'.$hook.'
'; + if (($hook = Module::hookExec('adminCustomers', array('id_customer'=>$customer->id, 'orders'=>$orders))) !== false) { + echo '
'.$hook.'
'; + } echo '
 
'; echo '

'.$this->l('Groups').' ('.sizeof($groups).')

'; @@ -656,7 +657,7 @@ class AdminCustomers extends AdminTab /* Last connections */ $connections = $customer->getLastConnections(); - if (sizeof($connections)) + if (sizeof($connections)) { echo '

'.$this->l('Last connections').'

diff --git a/modules/invite/invite.php b/modules/invite/invite.php index 3e8cfce7..b50570e2 100644 --- a/modules/invite/invite.php +++ b/modules/invite/invite.php @@ -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 = ''; - } else { - $sponsor_edit = ''; + } else { + $sponsor_edit = ''; + });" class="button">'.$this->l('Click here to add a sponsor').''; + } } $result .= '