Пример #1
0
    /**
     * Hook display in tab AdminCustomers on BO
     * Data table with all sponsors informations for a customer
     */
    public function hookAdminCustomers($params)
    {
        include_once dirname(__FILE__) . '/ReferralProgramModule.php';
        $customer = new Customer((int) $params['id_customer']);
        if (!Validate::isLoadedObject($customer)) {
            die($this->l('Incorrect Customer object.'));
        }
        $friends = ReferralProgramModule::getSponsorFriend((int) $customer->id);
        if ($id_referralprogram = ReferralProgramModule::isSponsorised((int) $customer->id, true)) {
            $referralprogram = new ReferralProgramModule((int) $id_referralprogram);
            $sponsor = new Customer((int) $referralprogram->id_sponsor);
        }
        $html = '
		<div class="clear">&nbsp;</div>
		<h2>' . $this->l('Referral program') . ' (' . count($friends) . ')</h2>
		<h3>' . (isset($sponsor) ? $this->l('Customer\'s sponsor:') . ' <a href="index.php?tab=AdminCustomers&id_customer=' . (int) $sponsor->id . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id) . '">' . $sponsor->firstname . ' ' . $sponsor->lastname . '</a>' : $this->l('No one has sponsored this customer.')) . '</h3>';
        if ($friends and sizeof($friends)) {
            $html .= '<h3>' . sizeof($friends) . ' ' . (sizeof($friends) > 1 ? $this->l('Sponsored customers:') : $this->l('Sponsored customer:')) . '</h3>';
            $html .= '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th class="center">' . $this->l('ID') . '</th>
					<th class="center">' . $this->l('Name') . '</th>
					<th class="center">' . $this->l('Email') . '</th>
					<th class="center">' . $this->l('Registration date') . '</th>
					<th class="center">' . $this->l('Customers sponsored by this friend') . '</th>
					<th class="center">' . $this->l('Placed orders') . '</th>
					<th class="center">' . $this->l('Customer account created') . '</th>
				</tr>';
            foreach ($friends as $key => $friend) {
                $orders = Order::getCustomerOrders($friend['id_customer']);
                $html .= '
					<tr ' . ($key++ % 2 ? 'class="alt_row"' : '') . ' ' . ((int) $friend['id_customer'] ? 'style="cursor: pointer" onclick="document.location = \'?tab=AdminCustomers&id_customer=' . $friend['id_customer'] . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id) . '\'"' : '') . '>
						<td class="center">' . ((int) $friend['id_customer'] ? $friend['id_customer'] : '--') . '</td>
						<td>' . $friend['firstname'] . ' ' . $friend['lastname'] . '</td>
						<td>' . $friend['email'] . '</td>
						<td>' . Tools::displayDate($friend['date_add'], $this->context->language->id, true) . '</td>
						<td align="right">' . sizeof(ReferralProgramModule::getSponsorFriend($friend['id_customer'])) . '</td>
						<td align="right">' . ($orders ? sizeof($orders) : 0) . '</td>
						<td align="center">' . ((int) $friend['id_customer'] ? '<img src="' . _PS_ADMIN_IMG_ . 'enabled.gif" />' : '<img src="' . _PS_ADMIN_IMG_ . 'disabled.gif" />') . '</td>
					</tr>';
            }
            $html .= '
				</table>';
        } else {
            $html .= sprintf($this->l('%1$s %2$s has not sponsored any friends yet.'), $customer->firstname, $customer->lastname);
        }
        return $html . '<br/><br/>';
    }
Пример #2
0
 /**
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     // get discount value (ready to display)
     $discount_type = (int) Configuration::get('REFERRAL_DISCOUNT_TYPE');
     if ($discount_type == 1) {
         $discount = Discount::display((double) Configuration::get('REFERRAL_PERCENTAGE'), $discount_type, new Currency($this->context->currency->id));
     } else {
         $discount = Discount::display((double) Configuration::get('REFERRAL_DISCOUNT_VALUE_' . (int) $this->context->currency->id), $discount_type, new Currency($this->context->currency->id));
     }
     $activeTab = 'sponsor';
     $error = false;
     // Mailing invitation to friend sponsor
     $invitation_sent = false;
     $nbInvitation = 0;
     if (Tools::isSubmit('submitSponsorFriends') and Tools::getValue('friendsEmail') and sizeof($friendsEmail = Tools::getValue('friendsEmail')) >= 1) {
         $activeTab = 'sponsor';
         if (!Tools::getValue('conditionsValided')) {
             $error = 'conditions not valided';
         } else {
             $friendsLastName = Tools::getValue('friendsLastName');
             $friendsFirstName = Tools::getValue('friendsFirstName');
             $mails_exists = array();
             foreach ($friendsEmail as $key => $friendEmail) {
                 $friendEmail = strval($friendEmail);
                 $friendLastName = strval($friendsLastName[$key]);
                 $friendFirstName = strval($friendsFirstName[$key]);
                 if (empty($friendEmail) and empty($friendLastName) and empty($friendFirstName)) {
                     continue;
                 } elseif (empty($friendEmail) or !Validate::isEmail($friendEmail)) {
                     $error = 'email invalid';
                 } elseif (empty($friendFirstName) or empty($friendLastName) or !Validate::isName($friendLastName) or !Validate::isName($friendFirstName)) {
                     $error = 'name invalid';
                 } elseif (ReferralProgramModule::isEmailExists($friendEmail) or Customer::customerExists($friendEmail)) {
                     $mails_exists[] = $friendEmail;
                 } else {
                     $referralprogram = new ReferralProgramModule();
                     $referralprogram->id_sponsor = (int) $this->context->customer->id;
                     $referralprogram->firstname = $friendFirstName;
                     $referralprogram->lastname = $friendLastName;
                     $referralprogram->email = $friendEmail;
                     if (!$referralprogram->validateFields(false)) {
                         $error = 'name invalid';
                     } else {
                         if ($referralprogram->save()) {
                             if (Configuration::get('PS_CIPHER_ALGORITHM')) {
                                 $cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_);
                             } else {
                                 $cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
                             }
                             $vars = array('{email}' => strval($this->context->customer->email), '{lastname}' => strval($this->context->customer->lastname), '{firstname}' => strval($this->context->customer->firstname), '{email_friend}' => $friendEmail, '{lastname_friend}' => $friendLastName, '{firstname_friend}' => $friendFirstName, '{link}' => Context::getContext()->link->getPageLink('authentication', true, Context::getContext()->language->id, 'create_account=1&sponsor=' . urlencode($cipherTool->encrypt($referralprogram->id . '|' . $referralprogram->email . '|')), false), '{discount}' => $discount);
                             Mail::Send((int) $this->context->language->id, 'referralprogram-invitation', Mail::l('Referral Program', (int) $this->context->language->id), $vars, $friendEmail, $friendFirstName . ' ' . $friendLastName, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/../../mails/');
                             $invitation_sent = true;
                             $nbInvitation++;
                             $activeTab = 'pending';
                         } else {
                             $error = 'cannot add friends';
                         }
                     }
                 }
                 if ($error) {
                     break;
                 }
             }
             if ($nbInvitation > 0) {
                 unset($_POST);
             }
             //Not to stop the sending of e-mails in case of doubloon
             if (sizeof($mails_exists)) {
                 $error = 'email exists';
             }
         }
     }
     // Mailing revive
     $revive_sent = false;
     $nbRevive = 0;
     if (Tools::isSubmit('revive')) {
         $activeTab = 'pending';
         if (Tools::getValue('friendChecked') and sizeof($friendsChecked = Tools::getValue('friendChecked')) >= 1) {
             foreach ($friendsChecked as $key => $friendChecked) {
                 if (ReferralProgramModule::isSponsorFriend((int) $this->context->customer->id, (int) $friendChecked)) {
                     if (Configuration::get('PS_CIPHER_ALGORITHM')) {
                         $cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_);
                     } else {
                         $cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
                     }
                     $referralprogram = new ReferralProgramModule((int) $key);
                     $vars = array('{email}' => $this->context->customer->email, '{lastname}' => $this->context->customer->lastname, '{firstname}' => $this->context->customer->firstname, '{email_friend}' => $referralprogram->email, '{lastname_friend}' => $referralprogram->lastname, '{firstname_friend}' => $referralprogram->firstname, '{link}' => Context::getContext()->link->getPageLink('authentication', true, Context::getContext()->language->id, 'create_account=1&sponsor=' . urlencode($cipherTool->encrypt($referralprogram->id . '|' . $referralprogram->email . '|')), false), '{discount}' => $discount);
                     $referralprogram->save();
                     Mail::Send((int) $this->context->language->id, 'referralprogram-invitation', Mail::l('Referral Program', (int) $this->context->language->id), $vars, $referralprogram->email, $referralprogram->firstname . ' ' . $referralprogram->lastname, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/../../mails/');
                     $revive_sent = true;
                     $nbRevive++;
                 }
             }
         } else {
             $error = 'no revive checked';
         }
     }
     $customer = new Customer((int) $this->context->customer->id);
     $stats = $customer->getStats();
     $orderQuantity = (int) Configuration::get('REFERRAL_ORDER_QUANTITY');
     $canSendInvitations = false;
     if ((int) $stats['nb_orders'] >= $orderQuantity) {
         $canSendInvitations = true;
     }
     // Smarty display
     $this->context->smarty->assign(array('activeTab' => $activeTab, 'discount' => $discount, 'orderQuantity' => $orderQuantity, 'canSendInvitations' => $canSendInvitations, 'nbFriends' => (int) Configuration::get('REFERRAL_NB_FRIENDS'), 'error' => $error, 'invitation_sent' => $invitation_sent, 'nbInvitation' => $nbInvitation, 'pendingFriends' => ReferralProgramModule::getSponsorFriend((int) $this->context->customer->id, 'pending'), 'revive_sent' => $revive_sent, 'nbRevive' => $nbRevive, 'subscribeFriends' => ReferralProgramModule::getSponsorFriend((int) $this->context->customer->id, 'subscribed'), 'mails_exists' => isset($mails_exists) ? $mails_exists : array()));
     $this->setTemplate('program.tpl');
 }
Пример #3
0
    /**
     * Hook display in tab AdminCustomers on BO
     * Data table with all sponsors informations for a customer
     */
    public function hookAdminCustomers($params)
    {
        $customer = new Customer(intval($params['id_customer']));
        if (!Validate::isLoadedObject($customer)) {
            die(Tools::displayError('Incorrect object Customer.'));
        }
        global $cookie;
        $friends = ReferralProgramModule::getSponsorFriend($customer->id);
        if ($id_referralprogram = ReferralProgramModule::isSponsorised(intval($customer->id), true)) {
            $referralprogram = new ReferralProgramModule($id_referralprogram);
            $sponsor = new Customer($referralprogram->id_sponsor);
        }
        $html = '<h2>' . $this->l('Referral program') . '</h2>';
        // link to the detail of the sponsor
        $html .= '<h3>' . (isset($sponsor) ? $this->l('Customer\'s sponsor:') . ' <a href="index.php?tab=AdminCustomers&id_customer=' . $sponsor->id . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . intval(Tab::getIdFromClassName('AdminCustomers')) . intval($cookie->id_employee)) . '">' . $sponsor->firstname . ' ' . $sponsor->lastname . '</a>' : $this->l('No one has sponsored this customer.')) . '</h3>';
        if ($friends and sizeof($friends)) {
            $html .= '<h3>' . sizeof($friends) . ' ' . (sizeof($friends) > 1 ? $this->l('sponsored customers:') : $this->l('sponsored customer:')) . '</h3>';
            $html .= '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th class="center">' . $this->l('ID') . '</th>
					<th class="center">' . $this->l('Name') . '</th>
					<th class="center">' . $this->l('Email') . '</th>
					<th class="center">' . $this->l('Registration date') . '</th>
					<th class="center">' . $this->l('Sponsored customers') . '</th>
					<th class="center">' . $this->l('Placed orders') . '</th>
					<th class="center">' . $this->l('Inscribed') . '</th>
				</tr>';
            foreach ($friends as $key => $friend) {
                $orders = Order::getCustomerOrders($friend['id_customer']);
                $html .= '
				<tr ' . ($key++ % 2 ? 'class="alt_row"' : '') . ' ' . (intval($friend['id_customer']) ? 'style="cursor: pointer" onclick="document.location = \'?tab=AdminCustomers&id_customer=' . $friend['id_customer'] . '&viewcustomer&token=' . Tools::getAdminToken('AdminCustomers' . intval(Tab::getIdFromClassName('AdminCustomers')) . intval($cookie->id_employee)) . '\'"' : '') . '>
					<td class="center">' . (intval($friend['id_customer']) ? $friend['id_customer'] : '--') . '</td>
					<td>' . $friend['firstname'] . ' ' . $friend['lastname'] . '</td>
					<td>' . $friend['email'] . '</td>
					<td>' . Tools::displayDate($friend['date_add'], intval($cookie->id_lang), true) . '</td>
					<td align="right">' . sizeof(ReferralProgramModule::getSponsorFriend($friend['id_customer'])) . '</td>
					<td align="right">' . ($orders ? sizeof($orders) : 0) . '</td>
					<td align="center">' . (intval($friend['id_customer']) ? '<img src="' . _PS_ADMIN_IMG_ . 'enabled.gif" />' : '<img src="' . _PS_ADMIN_IMG_ . 'disabled.gif" />') . '</td>
				</tr>';
            }
            $html .= '
				</table>';
        } else {
            $html .= $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has not sponsored any friends yet.');
        }
        return $html . '<br/><br/>';
    }
    if (Tools::getValue('friendChecked') and sizeof($friendsChecked = Tools::getValue('friendChecked')) >= 1) {
        foreach ($friendsChecked as $key => $friendChecked) {
            if (ReferralProgramModule::isSponsorFriend((int) $cookie->id_customer, (int) $friendChecked)) {
                if (Configuration::get('PS_CIPHER_ALGORITHM')) {
                    $cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_);
                } else {
                    $cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
                }
                $referralprogram = new ReferralProgramModule((int) $key);
                $vars = array('{email}' => $cookie->email, '{lastname}' => $cookie->customer_lastname, '{firstname}' => $cookie->customer_firstname, '{email_friend}' => $referralprogram->email, '{lastname_friend}' => $referralprogram->lastname, '{firstname_friend}' => $referralprogram->firstname, '{link}' => 'authentication.php?create_account=1&sponsor=' . base64_encode($cipherTool->encrypt($referralprogram->id . '|' . $referralprogram->email . '|')), '{discount}' => $discount);
                $referralprogram->save();
                Mail::Send((int) $cookie->id_lang, 'referralprogram-invitation', Mail::l('Referral Program'), $vars, $referralprogram->email, $referralprogram->firstname . ' ' . $referralprogram->lastname, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/mails/');
                $revive_sent = true;
                $nbRevive++;
            }
        }
    } else {
        $error = 'no revive checked';
    }
}
$customer = new Customer((int) $cookie->id_customer);
$stats = $customer->getStats();
$orderQuantity = (int) Configuration::get('REFERRAL_ORDER_QUANTITY');
$canSendInvitations = false;
if ((int) $stats['nb_orders'] >= $orderQuantity) {
    $canSendInvitations = true;
}
// Smarty display
$smarty->assign(array('activeTab' => $activeTab, 'discount' => $discount, 'orderQuantity' => $orderQuantity, 'canSendInvitations' => $canSendInvitations, 'nbFriends' => (int) Configuration::get('REFERRAL_NB_FRIENDS'), 'error' => $error, 'invitation_sent' => $invitation_sent, 'nbInvitation' => $nbInvitation, 'pendingFriends' => ReferralProgramModule::getSponsorFriend((int) $cookie->id_customer, 'pending'), 'revive_sent' => $revive_sent, 'nbRevive' => $nbRevive, 'subscribeFriends' => ReferralProgramModule::getSponsorFriend((int) $cookie->id_customer, 'subscribed'), 'mails_exists' => isset($mails_exists) ? $mails_exists : array()));
echo Module::display(dirname(__FILE__) . '/referralprogram.php', 'referralprogram-program.tpl');
include dirname(__FILE__) . '/../../footer.php';
 /**
  * Hook display in tab AdminCustomers on BO
  * Data table with all sponsors informations for a customer
  */
 public function hookAdminCustomers($params)
 {
     include_once dirname(__FILE__) . '/ReferralProgramModule.php';
     $customer = new Customer((int) $params['id_customer']);
     $sponsor = null;
     if (!Validate::isLoadedObject($customer)) {
         die($this->l('Incorrect Customer object.'));
     }
     $friends = ReferralProgramModule::getSponsorFriend((int) $customer->id);
     if ($id_referralprogram = ReferralProgramModule::isSponsorised((int) $customer->id, true)) {
         $referralprogram = new ReferralProgramModule((int) $id_referralprogram);
         $sponsor = new Customer((int) $referralprogram->id_sponsor);
     }
     foreach ($friends as $key => &$friend) {
         $friend['orders_count'] = sizeof(Order::getCustomerOrders($friend['id_customer']));
         $friend['date_add'] = Tools::displayDate($friend['date_add'], null, true);
         $friend['sponsored_friend_count'] = sizeof(ReferralProgramModule::getSponsorFriend($friend['id_customer']));
     }
     $this->smarty->assign(array('friends' => $friends, 'sponsor' => $sponsor, 'customer' => $customer, 'admin_image_dir' => _PS_ADMIN_IMG_, 'token' => Tools::getAdminToken('AdminCustomers' . (int) Tab::getIdFromClassName('AdminCustomers') . (int) $this->context->employee->id)));
     if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) {
         return $this->display(__FILE__, 'hook_customers_16.tpl');
     } else {
         return $this->display(__FILE__, 'hook_customers.tpl');
     }
 }