From 7bd76242003a3f1f6a8e367315116ae673a41da0 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Tue, 31 Oct 2017 12:24:29 +0100 Subject: [PATCH 1/5] Add sponsor from backoffice --- adm/tabs/AdminCustomers.php | 2 +- modules/invite/ajax_sponsor.php | 35 +++++++++++ modules/invite/ajax_sponsor.tpl | 25 ++++++++ modules/invite/invite.php | 102 ++++++++++++++++++++++++++++---- 4 files changed, 151 insertions(+), 13 deletions(-) create mode 100644 modules/invite/ajax_sponsor.php create mode 100644 modules/invite/ajax_sponsor.tpl diff --git a/adm/tabs/AdminCustomers.php b/adm/tabs/AdminCustomers.php index 618a3753..cfe855e4 100755 --- a/adm/tabs/AdminCustomers.php +++ b/adm/tabs/AdminCustomers.php @@ -407,7 +407,7 @@ 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 '
'.$hook.'
'; diff --git a/modules/invite/ajax_sponsor.php b/modules/invite/ajax_sponsor.php new file mode 100644 index 00000000..b095b6b4 --- /dev/null +++ b/modules/invite/ajax_sponsor.php @@ -0,0 +1,35 @@ +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; +} \ No newline at end of file diff --git a/modules/invite/ajax_sponsor.tpl b/modules/invite/ajax_sponsor.tpl new file mode 100644 index 00000000..1fb2674c --- /dev/null +++ b/modules/invite/ajax_sponsor.tpl @@ -0,0 +1,25 @@ +
+Rechercher par adresse email +
+{if $sponsor !== false}Email du parrrain actuel: {$sponsor->email}
{/if} + + + +
+
+ +{literal} + + + + +{/literal} \ No newline at end of file diff --git a/modules/invite/invite.php b/modules/invite/invite.php index 5d9fc082..3e8cfce7 100644 --- a/modules/invite/invite.php +++ b/modules/invite/invite.php @@ -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,59 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor= } } - public function hookAdminCustomers($params) { + public function hookAdminCustomers($params) + { global $cookie; - + $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 { + $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 + )'); + } + // Replace + else { + Db::getInstance()->ExecuteS('UPDATE `'._DB_PREFIX_.'invite` SET `id_sponsor`='.$id_sponsor. + ' WHERE `id_customer`='.$customer->id); + } + } + } + } - 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 +1331,40 @@ 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 = ''; + } + $result .= '
 

'.$this->l('Referral program').'

'.$this->l('Invite link:').'




- -

'.($sponsor? $this->l('Customer\'s sponsor:').' '.$sponsor['firstname'].' '.$sponsor['lastname'].'': $this->l('No one has sponsored this customer.')).'

+ '.(empty($error_edit) ? '' : $error_edit).' +


+

'.($sponsor? + $this->l('Customer\'s sponsor:').' '.$sponsor['firstname'].' '.$sponsor['lastname'].'' : + $this->l('No one has sponsored this customer.')). + '

+
'.$sponsor_edit.'



-

'.$this->l('Customer\'s pending friends:').'

+

'.$this->l('Customer\'s pending friends:').'