Example #1
0
 /**
  * Hook called when order status changed
  * register a discount for sponsor and send him an e-mail
  */
 public function hookUpdateOrderStatus($params)
 {
     if (!Validate::isLoadedObject($params['newOrderStatus'])) {
         die($this->l('Missing parameters'));
     }
     $orderState = $params['newOrderStatus'];
     $order = new Order((int) $params['id_order']);
     if ($order and !Validate::isLoadedObject($order)) {
         die($this->l('Incorrect Order object.'));
     }
     include_once dirname(__FILE__) . '/ReferralProgramModule.php';
     $customer = new Customer((int) $order->id_customer);
     $stats = $customer->getStats();
     $nbOrdersCustomer = (int) $stats['nb_orders'] + 1;
     // hack to count current order
     $referralprogram = new ReferralProgramModule(ReferralProgramModule::isSponsorised((int) $customer->id, true));
     if (!Validate::isLoadedObject($referralprogram)) {
         return false;
     }
     $sponsor = new Customer((int) $referralprogram->id_sponsor);
     if ((int) $orderState->logable and $nbOrdersCustomer >= (int) $this->_configuration['REFERRAL_ORDER_QUANTITY'] and $referralprogram->registerDiscountForSponsor((int) $order->id_currency)) {
         $cartRule = new CartRule((int) $referralprogram->id_cart_rule_sponsor);
         $currency = new Currency((int) $order->id_currency);
         $discount_display = ReferralProgram::displayDiscount($cartRule->reduction_percent ? $cartRule->reduction_percent : $cartRule->reduction_amount, $cartRule->reduction_percent ? 1 : 2, $currency);
         $data = array('{sponsored_firstname}' => $customer->firstname, '{sponsored_lastname}' => $customer->lastname, '{discount_display}' => $discount_display, '{discount_name}' => $cartRule->code);
         Mail::Send((int) $order->id_lang, 'referralprogram-congratulations', Mail::l('Congratulations!', (int) $order->id_lang), $data, $sponsor->email, $sponsor->firstname . ' ' . $sponsor->lastname, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/mails/');
         return true;
     }
     return false;
 }
    }
}
// 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) $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;
Example #3
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');
 }
Example #4
0
 /**
  * Hook called when order status changed
  * register a discount for sponsor and send him an e-mail
  */
 public function hookUpdateOrderStatus($params)
 {
     if (!Validate::isLoadedObject($params['newOrderStatus'])) {
         die(Tools::displayError('Some parameters are missing.'));
     }
     $orderState = $params['newOrderStatus'];
     $order = new Order(intval($params['id_order']));
     if ($order and !Validate::isLoadedObject($order)) {
         die(Tools::displayError('Incorrect object Order.'));
     }
     $customer = new Customer($order->id_customer);
     $stats = $customer->getStats();
     $nbOrdersCustomer = intval($stats['nb_orders']) + 1;
     // hack to count current order
     $referralprogram = new ReferralProgramModule(ReferralProgramModule::isSponsorised(intval($customer->id), true));
     if (!Validate::isLoadedObject($referralprogram)) {
         return false;
     }
     $sponsor = new Customer($referralprogram->id_sponsor);
     if (intval($orderState->logable) and $nbOrdersCustomer >= intval($this->_configuration['REFERRAL_ORDER_QUANTITY'])) {
         if ($referralprogram->registerDiscountForSponsor()) {
             $discount = new Discount($referralprogram->id_discount_sponsor);
             $currency = new Currency($order->id_currency);
             $discount_display = $discount->display($discount->value, $discount->id_discount_type, $currency);
             $data = array('{sponsored_firstname}' => $customer->firstname, '{sponsored_lastname}' => $customer->lastname, '{discount_display}' => $discount_display, '{discount_name}' => $discount->name);
             Mail::Send(intval($order->id_lang), 'referralprogram-congratulations', $this->l('Congratulations!'), $data, $sponsor->email, $sponsor->firstname . ' ' . $sponsor->lastname, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/mails/');
             return true;
         }
     }
     return false;
 }