本文整理汇总了PHP中Customer::customerExists方法的典型用法代码示例。如果您正苦于以下问题:PHP Customer::customerExists方法的具体用法?PHP Customer::customerExists怎么用?PHP Customer::customerExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Customer
的用法示例。
在下文中一共展示了Customer::customerExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initContent
/**
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();
if ($this->context->customer->isLogged()) {
Tools::redirect('index.php?controller=my-account');
}
$fb_connect_appid = Configuration::get('FB_CONNECT_APPID');
$fb_connect_appkey = Configuration::get('FB_CONNECT_APPKEY');
$this->redirect_uri = $this->context->link->getModuleLink('fbconnect_psb', 'registration', array('done' => 1), TRUE, $this->context->language->id);
require_once _PS_ROOT_DIR_ . '/modules/fbconnect_psb/fb_sdk/facebook.php';
$facebook = new Facebook(array('appId' => $fb_connect_appid, 'secret' => $fb_connect_appkey));
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$fb_user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
//die('Error: '.$e);
error_log($e);
$user = null;
}
} else {
// Get new Access tokens
Tools::redirect($facebook->getLoginUrl(array('scope' => 'email')));
}
// if user's FB account is linked than log the user in
if (isset($fb_user_profile['id'])) {
$sql = 'SELECT `id_customer`
FROM `' . _DB_PREFIX_ . 'customer_profile_connect`
WHERE `facebook_id` = \'' . (int) $fb_user_profile['id'] . '\'' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER);
if (Db::getInstance()->getValue($sql)) {
Tools::redirect($this->context->link->getModuleLink('fbconnect_psb', 'login', array(), TRUE, $this->context->language->id));
}
}
if (Tools::getValue('done')) {
$response = $facebook->getSignedRequest($_REQUEST['signed_request']);
$reg_metadata_fields = '[{"name":"name"},{"name":"first_name"},{"name":"last_name"},{"name":"email"},{"name":"password"},{"name":"birthday"},{"name":"gender"}]';
$reg_metadata_fields_clean = preg_replace('/\\s+/', '', $reg_metadata_fields);
$response_metadata_fields_clean = preg_replace('/\\s+/', '', $response['registration_metadata']['fields']);
if (strcmp($reg_metadata_fields_clean, $response_metadata_fields_clean) != 0) {
$this->errors[] = Tools::displayError('registration metadata fields not valid');
}
$response_email = trim($response['registration']['email']);
if (empty($response_email)) {
$this->errors[] = Tools::displayError('An email address required.');
} else {
if (!Validate::isEmail($response_email)) {
$this->errors[] = Tools::displayError('Invalid email address.');
} else {
if (Customer::customerExists($response_email)) {
// Need to clean up the code here most of it is from
// IDFBCon_v.0.2 (Chandra R. Atmaja <chandra.r.atmaja@gmail.com>)
// Someone has already registered with this e-mail address
// This will link the 1st existing email/account on site with Facebook
// and log the user in to the account. Is this safe?
$customer = new Customer();
$authentication = $customer->getByEmail($response['registration']['email']);
// This is done to see if a existing users try's to re-registrar
$sql = 'SELECT `facebook_id`
FROM `' . _DB_PREFIX_ . 'customer_profile_connect`
WHERE `id_customer` = \'' . (int) $customer->id . '\' ' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER);
$customer_fb_id = Db::getInstance()->getValue($sql);
if ($customer_fb_id) {
if ($customer_fb_id == (int) $response['user_id']) {
Tools::redirect($this->context->link->getModuleLink('fbconnect_psb', 'login', array(), false, $this->context->language->id));
} else {
$this->errors[] = Tools::displayError('An error occurred while linking your Facebook account.');
}
} else {
if (Db::getInstance()->insert('customer_profile_connect', array('id_customer' => (int) $customer->id, 'facebook_id' => (int) $response['user_id']))) {
$this->errors[] = Tools::displayError('an error occurred while linking your Facebook account.');
}
$customer->active = 1;
$customer->deleted = 0;
$this->context->cookie->id_customer = intval($customer->id);
$this->context->cookie->customer_lastname = $customer->lastname;
$this->context->cookie->customer_firstname = $customer->firstname;
$this->context->cookie->logged = 1;
$this->context->cookie->passwd = $customer->passwd;
$this->context->cookie->email = $customer->email;
if (Configuration::get('PS_CART_FOLLOWING') and (empty($this->context->cookie->id_cart) or Cart::getNbProducts($this->context->cookie->id_cart) == 0)) {
$this->context->cookie->id_cart = intval(Cart::lastNoneOrderedCart(intval($customer->id)));
}
Module::hookExec('authentication');
if ($back = Tools::getValue('back')) {
Tools::redirect($back);
}
Tools::redirect('index.php?controller=my-account');
}
}
}
//.........这里部分代码省略.........
示例2: postProcess
/**
* Start forms process
* @see FrontController::postProcess()
*/
public function postProcess()
{
$origin_newsletter = (bool) $this->customer->newsletter;
if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days'])) {
$this->customer->birthday = (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
}
if (Tools::isSubmit('submitIdentity')) {
if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) && !(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == '')) {
$this->errors[] = Tools::displayError('Invalid date of birth.');
} else {
$email = trim(Tools::getValue('email'));
$this->customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
if (isset($_POST['old_passwd'])) {
$_POST['old_passwd'] = trim($_POST['old_passwd']);
}
if (!Validate::isEmail($email)) {
$this->errors[] = Tools::displayError('This email address is not valid');
} elseif ($this->customer->email != $email && Customer::customerExists($email, true)) {
$this->errors[] = Tools::displayError('An account using this email address has already been registered.');
} elseif (!isset($_POST['old_passwd']) || empty($_POST['old_passwd']) || Tools::encrypt($_POST['old_passwd']) != $this->context->cookie->passwd) {
$this->errors[] = Tools::displayError('The password you entered is incorrect.');
} elseif ($_POST['passwd'] != $_POST['confirmation']) {
$this->errors[] = Tools::displayError('The password and confirmation do not match.');
} else {
$prev_id_default_group = $this->customer->id_default_group;
// Merge all errors of this file and of the Object Model
$this->errors = array_merge($this->errors, $this->customer->validateController());
}
if (!count($this->errors)) {
$this->customer->id_default_group = (int) $prev_id_default_group;
$this->customer->firstname = Tools::ucfirst(Tools::strtolower($this->customer->firstname));
if (!isset($_POST['newsletter'])) {
$this->customer->newsletter = 0;
} elseif (!$origin_newsletter && isset($_POST['newsletter'])) {
if ($module_newsletter = Module::getInstanceByName('blocknewsletter')) {
if ($module_newsletter->active) {
$module_newsletter->confirmSubscription($this->customer->email);
}
}
}
if (!isset($_POST['optin'])) {
$this->customer->optin = 0;
}
if (Tools::getValue('passwd')) {
$this->context->cookie->passwd = $this->customer->passwd;
}
if ($this->customer->update()) {
$this->context->cookie->customer_lastname = $this->customer->lastname;
$this->context->cookie->customer_firstname = $this->customer->firstname;
$this->context->smarty->assign('confirmation', 1);
} else {
$this->errors[] = Tools::displayError('The information cannot be updated.');
}
}
}
} else {
$_POST = array_map('stripslashes', $this->customer->getFields());
}
return $this->customer;
}
示例3: postProcess
/**
* Start forms process.
*
* @see FrontController::postProcess()
*/
public function postProcess()
{
$order_reference = current(explode('#', Tools::getValue('order_reference')));
$email = Tools::getValue('email');
if (!$email && !$order_reference) {
return;
} elseif (!$email || !$order_reference) {
$this->errors[] = $this->getTranslator()->trans('Please provide the required information', array(), 'Shop.Notifications.Error');
return;
}
$isCustomer = Customer::customerExists($email, false, true);
if ($isCustomer) {
$this->info[] = $this->trans('Please log in to your customer account to view the order', array(), 'Shop.Notifications.Info');
$this->redirectWithNotifications($this->context->link->getPageLink('history'));
} else {
$this->order = Order::getByReferenceAndEmail($order_reference, $email);
if (!Validate::isLoadedObject($this->order)) {
$this->errors[] = $this->getTranslator()->trans('We couldn\'t find your order with the information provided, please try again', array(), 'Shop.Notifications.Error');
}
}
if (Tools::isSubmit('submitTransformGuestToCustomer') && Tools::getValue('password')) {
$customer = new Customer((int) $this->order->id_customer);
$password = Tools::getValue('password');
if (strlen($password) < Validate::PASSWORD_LENGTH) {
$this->errors[] = $this->trans('Your password must be at least %min% characters long.', array('%min%' => Validate::PASSWORD_LENGTH), 'Shop.Forms.Help');
} elseif ($customer->transformToCustomer($this->context->language->id, $password)) {
$this->success[] = $this->trans('Your guest account has been successfully transformed into a customer account. You can now log in as a registered shopper.', array(), 'Shop.Notifications.Success');
} else {
$this->success[] = $this->trans('An unexpected error occurred while creating your account.', array(), 'Shop.Notifications.Error');
}
}
}
示例4: preProcess
public function preProcess()
{
parent::preProcess();
$customer = new Customer((int) self::$cookie->id_customer);
if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days'])) {
$customer->birthday = (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
}
if (Tools::isSubmit('submitIdentity')) {
if (Module::getInstanceByName('blocknewsletter')->active) {
if (!isset($_POST['optin'])) {
$customer->optin = 0;
}
if (!isset($_POST['newsletter'])) {
$customer->newsletter = 0;
}
}
if (!isset($_POST['id_gender'])) {
$_POST['id_gender'] = 9;
}
if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) && !(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == '')) {
$this->errors[] = Tools::displayError('Invalid date of birth');
} else {
$customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
$id_customer_exists = (int) Customer::customerExists(Tools::getValue('email'), true, false);
if ($id_customer_exists && $id_customer_exists != (int) self::$cookie->id_customer) {
$this->errors[] = Tools::displayError('An account is already registered with this e-mail.');
}
$_POST['old_passwd'] = trim($_POST['old_passwd']);
if (empty($_POST['old_passwd']) || Tools::encrypt($_POST['old_passwd']) != self::$cookie->passwd) {
$this->errors[] = Tools::displayError('Your password is incorrect.');
} elseif ($_POST['passwd'] != $_POST['confirmation']) {
$this->errors[] = Tools::displayError('Password and confirmation do not match');
} else {
$prev_id_default_group = $customer->id_default_group;
$this->errors = array_unique(array_merge($this->errors, $customer->validateController(true, true)));
}
if (!count($this->errors)) {
$customer->id_default_group = (int) $prev_id_default_group;
$customer->firstname = Tools::ucfirst(Tools::strtolower($customer->firstname));
if (Tools::getValue('passwd')) {
self::$cookie->passwd = $customer->passwd;
}
if ($customer->update()) {
self::$cookie->customer_lastname = $customer->lastname;
self::$cookie->customer_firstname = $customer->firstname;
self::$smarty->assign('confirmation', 1);
} else {
$this->errors[] = Tools::displayError('Cannot update information');
}
}
}
} else {
$_POST = array_map('stripslashes', $customer->getFields());
}
$birthday = $customer->birthday ? explode('-', $customer->birthday) : array('-', '-', '-');
/* Generate years, months and days */
self::$smarty->assign(array('years' => Tools::dateYears(), 'sl_year' => $birthday[0], 'months' => Tools::dateMonths(), 'sl_month' => $birthday[1], 'days' => Tools::dateDays(), 'sl_day' => $birthday[2], 'errors' => $this->errors));
self::$smarty->assign('newsletter', (int) Module::getInstanceByName('blocknewsletter')->active);
}
示例5: postProcess
/**
* Start forms process
* @see FrontController::postProcess()
*/
public function postProcess()
{
if (Tools::isSubmit('submitGuestTracking') || Tools::isSubmit('submitTransformGuestToCustomer')) {
// These lines are here for retrocompatibility with old theme
$id_order = Tools::getValue('id_order');
$order_collection = array();
if ($id_order) {
if (is_numeric($id_order)) {
$order = new Order((int) $id_order);
if (Validate::isLoadedObject($order)) {
$order_collection = Order::getByReference($order->reference);
}
} else {
$order_collection = Order::getByReference($id_order);
}
}
// Get order reference, ignore package reference (after the #, on the order reference)
$order_reference = current(explode('#', Tools::getValue('order_reference')));
// Ignore $result_number
if (!empty($order_reference)) {
$order_collection = Order::getByReference($order_reference);
}
$email = Tools::getValue('email');
if (empty($order_reference) && empty($id_order)) {
$this->errors[] = Tools::displayError('Please provide your order\'s reference number.');
} elseif (empty($email)) {
$this->errors[] = Tools::displayError('Please provide a valid email address.');
} elseif (!Validate::isEmail($email)) {
$this->errors[] = Tools::displayError('Please provide a valid email address.');
} elseif (!Customer::customerExists($email, false, false)) {
$this->errors[] = Tools::displayError('There is no account associated with this email address.');
} elseif (Customer::customerExists($email, false, true)) {
$this->errors[] = Tools::displayError('This page is for guest accounts only. Since your guest account has already been transformed into a customer account, you can no longer view your order here. Please log in to your customer account to view this order');
$this->context->smarty->assign('show_login_link', true);
} elseif (!count($order_collection)) {
$this->errors[] = Tools::displayError('Invalid order reference');
} elseif (!$order_collection->getFirst()->isAssociatedAtGuest($email)) {
$this->errors[] = Tools::displayError('Invalid order reference');
} else {
$this->assignOrderTracking($order_collection);
if (Tools::isSubmit('submitTransformGuestToCustomer')) {
$customer = new Customer((int) $order->id_customer);
if (!Validate::isLoadedObject($customer)) {
$this->errors[] = Tools::displayError('Invalid customer');
} elseif (!Tools::getValue('password')) {
$this->errors[] = Tools::displayError('Invalid password.');
} elseif (!$customer->transformToCustomer($this->context->language->id, Tools::getValue('password'))) {
// @todo clarify error message
$this->errors[] = Tools::displayError('An error occurred while transforming a guest into a registered customer.');
} else {
$this->context->smarty->assign('transformSuccess', true);
}
}
}
}
}
示例6: preProcess
public function preProcess()
{
global $cookie;
$customer = new Customer((int) self::$cookie->id_customer);
if (Tools::getValue('ref_emails')) {
$emails = Tools::getValue('ref_emails');
$emails = str_replace("\n", "", $emails);
$emails = trim($emails);
$emailList = explode(",", $emails);
$invited = false;
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
$countInvited = 0;
$countInvalid = 0;
$invite_id = time();
$date_invite = date('Y-m-d H:i:s');
$pattern = '/<?([a-z0-9!#$%&\'*+\\/=?^`{}|~_-]+[.a-z0-9!#$%&\'*+\\/=?^`{}|~_-]*@[a-z0-9]+[._a-z0-9-]*\\.[a-z0-9]+)>?$/i';
foreach ($emailList as $email) {
$email = trim($email);
$emailId = '';
$name = '';
//see if it contains the name
if (strpos($email, '<') === false) {
$emailId = $email;
} else {
preg_match($pattern, $email, $matches);
$emailId = $matches[1];
$name = strstr($email, '<', true);
}
$name = trim($name);
$emailId = trim($emailId);
//echo $name . ' : ' . $emailId . '<br />';
if (!Validate::isEmail($emailId) || Customer::customerExists($emailId)) {
++$countInvalid;
continue;
}
//Add referral record for this customer
//$result = $db->getRow("SELECT `id_customer` FROM vb_customer_referrals WHERE email = '".$email."'");
//if(!isset($result['id_customer']))
$db->ExecuteS("INSERT INTO vb_customer_referrals (id_customer, email, date_add, id_invite, name) VALUES (" . $customer->id . ", '" . $emailId . "', '" . $date_invite . "', " . $invite_id . ", '" . $name . "')");
++$countInvited;
}
if ($countInvited) {
Tools::sendSQSInviteMessage($invite_id, $customer->id);
}
self::$smarty->assign('countInvited', $countInvited);
self::$smarty->assign('countInvalid', $countInvalid);
}
$res = Db::getInstance()->ExecuteS("select \n\t\t\t\t\t\t\t\t\t\t\tc.id_customer, \n\t\t\t\t\t\t\t\t\t\t\tconcat(c.firstname, ' ', c.lastname) as 'name', \n\t\t\t\t\t\t\t\t\t\t\tc.email, \n\t\t\t\t\t\t\t\t\t\t\tc.total_delivered,\n\t\t\t\t\t\t\t\t\t\t\tr.date_add\n\t\t\t\t\t\t\t\t\t\t\tfrom ps_customer c \n\t\t\t\t\t\t\t\t\t\t\tleft join vb_customer_referrals r on (c.email = r.email) \n\t\t\t\t\t\t\t\t\t\t\twhere id_referrer = " . self::$cookie->id_customer . "\n\t\t\t\t\t\t\t\t\t\t\tgroup by c.email");
self::$smarty->assign(array('referrals' => $res, 'customer_id' => $customer->id));
$res = Db::getInstance()->getRow("select count(*) as 'invited'\n\t\t\t\t\t\t\t\t\t\t\tfrom vb_customer_referrals\n\t\t\t\t\t\t\t\t\t\t\twhere id_customer = " . self::$cookie->id_customer . "\n\t\t\t\t\t\t\t\t\t\t\tgroup by email");
if ($res && $res['invited'] > 0) {
self::$smarty->assign('referrals_invited', 1);
}
}
示例7: validate
public function validate()
{
$emailField = $this->getField('email');
$id_customer = Customer::customerExists($emailField->getValue(), true, true);
if ($id_customer && $id_customer != $this->getCustomer()->id) {
$emailField->addError(sprintf($this->translator->trans('The email "%s" is already used, please choose another one or sign in', array(), 'Shop.Notifications.Error'), $emailField->getValue()));
}
// birthday is from input type text..., so we need to convert to a valid date
$birthdayField = $this->getField('birthday');
if (!empty($birthdayField)) {
$birthdayValue = $birthdayField->getValue();
if (!empty($birthdayValue)) {
$dateBuilt = DateTime::createFromFormat(Context::getContext()->language->date_format_lite, $birthdayValue);
if (!empty($dateBuilt)) {
$birthdayField->setValue($dateBuilt->format('Y-m-d'));
}
}
}
return parent::validate();
}
示例8: create
private function create(Customer $customer, $clearTextPassword)
{
if (!$clearTextPassword) {
if (!$this->guest_allowed) {
$this->errors['password'][] = $this->translator->trans('Password is required', [], 'Shop.Notifications.Error');
return false;
}
/**
* Warning: this is only safe provided
* that guests cannot log in even with the generated
* password. That's the case at least at the time of writing.
*/
$clearTextPassword = $this->crypto->encrypt(microtime(), _COOKIE_KEY_);
$customer->is_guest = true;
}
$customer->passwd = $this->crypto->encrypt($clearTextPassword, _COOKIE_KEY_);
if (Customer::customerExists($customer->email, false, true)) {
$this->errors['email'][] = $this->translator->trans('An account was already registered with this email address', [], 'Shop.Notifications.Error');
return false;
}
$ok = $customer->save();
if ($ok) {
$this->context->updateCustomer($customer);
$this->context->cart->update();
$this->sendConfirmationMail($customer);
Hook::exec('actionCustomerAccountUpdate', array('customer' => $customer));
}
return $ok;
}
示例9: array
$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) $cookie->id_customer;
$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_);
示例10: elseif
} else {
$ppec->displayPayPalAPIError($ppec->l('Error during the prepration of the express checkout payment'), $ppec->logs);
}
} elseif (!empty($ppec->token) && $ppec->token == Tools::getValue('token') && ($ppec->payer_id = Tools::getValue('PayerID'))) {
// Get payment infos from paypal
$ppec->getExpressCheckout();
if ($ppec->hasSucceedRequest() && !empty($ppec->token)) {
$address = null;
$customer = null;
// Create Customer if not exist with address etc
if ($ppec->getContext()->cookie->logged) {
if (!($id_customer = Paypal::getPayPalCustomerIdByEmail($ppec->result['EMAIL']))) {
PayPal::addPayPalCustomer($ppec->getContext()->customer->id, $ppec->result['EMAIL']);
}
$customer = $ppec->getContext()->customer;
} elseif ($id_customer = Customer::customerExists($ppec->result['EMAIL'], true)) {
$customer = new Customer($id_customer);
} else {
$customer = new Customer();
$customer->email = $ppec->result['EMAIL'];
$customer->lastname = $ppec->result['LASTNAME'];
$customer->firstname = $ppec->result['FIRSTNAME'];
$customer->passwd = Tools::encrypt(Tools::passwdGen());
$customer->add();
PayPal::addPayPalCustomer($customer->id, $ppec->result['EMAIL']);
}
if (!$customer->id) {
$ppec->logs[] = $ppec->l('Cannot create customer');
}
if (!isset($ppec->result['PAYMENTREQUEST_0_SHIPTOSTREET']) || !isset($ppec->result['PAYMENTREQUEST_0_SHIPTOCITY']) || !isset($ppec->result['SHIPTOZIP']) || !isset($ppec->result['COUNTRYCODE'])) {
$ppec->redirectToCheckout($customer, $ppec->type != 'payment_cart');
示例11: postProcess
/**
* Start forms process
* @see FrontController::postProcess()
*/
public function postProcess()
{
$origin_newsletter = (bool) $this->customer->newsletter;
if (Tools::isSubmit('submitIdentity')) {
$email = trim(Tools::getValue('email'));
if (Tools::getValue('months') != '' && Tools::getValue('days') != '' && Tools::getValue('years') != '') {
$this->customer->birthday = (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days');
} elseif (Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == '') {
$this->customer->birthday = null;
} else {
$this->errors[] = Tools::displayError('Invalid date of birth.');
}
if (Tools::getIsset('old_passwd')) {
$old_passwd = trim(Tools::getValue('old_passwd'));
}
if (!Validate::isEmail($email)) {
$this->errors[] = Tools::displayError('This email address is not valid');
} elseif ($this->customer->email != $email && Customer::customerExists($email, true)) {
$this->errors[] = Tools::displayError('An account using this email address has already been registered.');
} elseif (!Tools::getIsset('old_passwd') || Tools::encrypt($old_passwd) != $this->context->cookie->passwd) {
$this->errors[] = Tools::displayError('The password you entered is incorrect.');
} elseif (Tools::getValue('passwd') != Tools::getValue('confirmation')) {
$this->errors[] = Tools::displayError('The password and confirmation do not match.');
} else {
$prev_id_default_group = $this->customer->id_default_group;
// Merge all errors of this file and of the Object Model
$this->errors = array_merge($this->errors, $this->customer->validateController());
}
if (!count($this->errors)) {
$this->customer->id_default_group = (int) $prev_id_default_group;
$this->customer->firstname = Tools::ucwords($this->customer->firstname);
if (Configuration::get('PS_B2B_ENABLE')) {
$this->customer->website = Tools::getValue('website');
// force update of website, even if box is empty, this allows user to remove the website
$this->customer->company = Tools::getValue('company');
}
if (!Tools::getIsset('newsletter')) {
$this->customer->newsletter = 0;
} elseif (!$origin_newsletter && Tools::getIsset('newsletter')) {
if ($module_newsletter = Module::getInstanceByName('blocknewsletter')) {
/** @var Blocknewsletter $module_newsletter */
if ($module_newsletter->active) {
$module_newsletter->confirmSubscription($this->customer->email);
}
}
}
if (!Tools::getIsset('optin')) {
$this->customer->optin = 0;
}
if (Tools::getValue('passwd')) {
$this->context->cookie->passwd = $this->customer->passwd;
}
if ($this->customer->update()) {
$this->context->cookie->customer_lastname = $this->customer->lastname;
$this->context->cookie->customer_firstname = $this->customer->firstname;
$this->context->smarty->assign('confirmation', 1);
} else {
$this->errors[] = Tools::displayError('The information cannot be updated.');
}
}
} else {
$_POST = array_map('stripslashes', $this->customer->getFields());
}
return $this->customer;
}
示例12: init
//.........这里部分代码省略.........
}
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
$this->context->cart->setNoMultishipping();
// As the cart is no multishipping, set each delivery address lines with the main delivery address
if (!count($this->errors)) {
$result = $this->_getCarrierList();
$wrapping_fees_tax = new Tax((int) Configuration::get('PS_GIFT_WRAPPING_TAX'));
if (version_compare(_PS_VERSION_, "1.5.2.0") <= 0) {
$wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
$wrapping_fees_tax_inc = $wrapping_fees * (1 + (double) $wrapping_fees_tax->rate / 100);
} else {
$wrapping_fees = $this->context->cart->getGiftWrappingPrice(false);
$wrapping_fees_tax_inc = $wrapping_fees = $this->context->cart->getGiftWrappingPrice();
}
$result = array_merge($result, array('allow_eu_vat_delivery' => $allow_eu_vat_delivery, 'allow_eu_vat_invoice' => $allow_eu_vat_invoice, 'HOOK_TOP_PAYMENT' => Hook::exec('displayPaymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int) $this->context->cookie->id_currency))), 'carrier_data' => $this->_getCarrierList()), $this->getFormatedSummaryDetail());
die(Tools::jsonEncode($result));
}
}
if (count($this->errors)) {
die(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors)));
}
break;
case 'multishipping':
$this->_assignSummaryInformations();
$this->context->smarty->assign('product_list', $this->context->cart->getProducts());
if ($this->context->customer->id) {
$this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id));
} else {
$this->context->smarty->assign('address_list', array());
}
$this->setTemplate(_PS_THEME_DIR_ . 'order-address-multishipping-products.tpl');
$this->display();
die;
break;
case 'cartReload':
$this->_assignSummaryInformations();
if ($this->context->customer->id) {
$this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id));
} else {
$this->context->smarty->assign('address_list', array());
}
$this->context->smarty->assign('opc', true);
$this->setTemplate(_PS_THEME_DIR_ . 'shopping-cart.tpl');
$this->display();
die;
break;
case 'noMultiAddressDelivery':
$this->context->cart->setNoMultishipping();
die;
break;
case 'emailCheck':
if (Tools::isSubmit('cust_email')) {
$customer_email = Tools::getValue('cust_email');
$is_registered = Validate::isEmail($customer_email) ? Customer::customerExists($customer_email) : 0;
$return = array('is_registered' => $is_registered);
die(Tools::jsonEncode($return));
}
break;
case 'zipCheck':
if (Tools::isSubmit('id_country')) {
$id_country = Tools::getValue('id_country');
if ($id_country > 0) {
$errors = array();
$country = new Country($id_country);
$zip_code_format = $country->zip_code_format;
if ($country->need_zip_code) {
if ($postcode = Tools::getValue('postcode') and $zip_code_format) {
$zip_regexp = '/^' . $zip_code_format . '$/ui';
$zip_regexp = str_replace(' ', '( |)', $zip_regexp);
$zip_regexp = str_replace('-', '(-|)', $zip_regexp);
$zip_regexp = str_replace('N', '[0-9]', $zip_regexp);
$zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp);
$zip_regexp = str_replace('C', $country->iso_code, $zip_regexp);
if (!preg_match($zip_regexp, $postcode)) {
$errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format)));
}
} elseif ($zip_code_format) {
$errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is required.');
} elseif ($postcode and !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
$errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format)));
}
}
}
//if($id_country>0)
$return = array('is_ok' => empty($errors), 'errors' => $errors);
die(Tools::jsonEncode($return));
}
break;
default:
throw new PrestaShopException('Unknown method "' . Tools::getValue('method') . '"');
}
} else {
throw new PrestaShopException('Method is not defined');
}
}
} elseif (Tools::isSubmit('ajax')) {
throw new PrestaShopException('Method is not defined');
}
}
示例13: addOrder
public function addOrder(ShopgateOrder $order)
{
$this->log("PS start add_order", ShopgateLogger::LOGTYPE_DEBUG);
$shopgateOrder = PSShopgateOrder::instanceByOrderNumber($order->getOrderNumber());
if ($shopgateOrder->id) {
throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_DUPLICATE_ORDER, 'external_order_id: ' . $shopgateOrder->id_order, true);
}
$comments = array();
// generate products array
$products = $this->insertOrderItems($order);
//Get or create customer
$id_customer = Customer::customerExists($order->getMail(), true, false);
$customer = new Customer($id_customer ? $id_customer : (int) $order->getExternalCustomerId());
if (!$customer->id) {
$customer = $this->createCustomer($customer, $order);
}
// prepare addresses: company has to be shorten. add mobile phone / telephone
$this->prepareAddresses($order);
//Get invoice and delivery addresses
$invoiceAddress = $this->getPSAddress($customer, $order->getInvoiceAddress());
$deliveryAddress = $order->getInvoiceAddress() == $order->getDeliveryAddress() ? $invoiceAddress : $this->getPSAddress($customer, $order->getDeliveryAddress());
//Creating currency
$this->log("PS setting currency", ShopgateLogger::LOGTYPE_DEBUG);
$id_currency = $order->getCurrency() ? Currency::getIdByIsoCode($order->getCurrency()) : $this->id_currency;
$currency = new Currency($id_currency ? $id_currency : $this->id_currency);
//Creating new cart
$this->log("PS set cart variables", ShopgateLogger::LOGTYPE_DEBUG);
$cart = new Cart();
$cart->id_lang = $this->id_lang;
$cart->id_currency = $currency->id;
$cart->id_address_delivery = $deliveryAddress->id;
$cart->id_address_invoice = $invoiceAddress->id;
$cart->id_customer = $customer->id;
if (version_compare(_PS_VERSION_, '1.4.1.0', '>=')) {
// id_guest is a connection to a ps_guest entry which includes screen width etc.
// is_guest field only exists in Prestashop 1.4.1.0 and higher
$cart->id_guest = $customer->is_guest;
}
$cart->recyclable = 0;
$cart->gift = 0;
$cart->id_carrier = (int) Configuration::get('SHOPGATE_CARRIER_ID');
$cart->secure_key = $customer->secure_key;
$this->log("PS try to create cart", ShopgateLogger::LOGTYPE_DEBUG);
if (!$cart->add()) {
throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_DATABASE_ERROR, 'Unable to create cart', true);
}
//Adding items to cart
$this->log("PS adding items to cart", ShopgateLogger::LOGTYPE_DEBUG);
foreach ($products as $p) {
$this->log("PS cart updateQty product id: " . $p['id_product'], ShopgateLogger::LOGTYPE_DEBUG);
$this->log("PS cart updateQty product quantity: " . $p['quantity'], ShopgateLogger::LOGTYPE_DEBUG);
$this->log("PS cart updateQty product quantity_difference: " . $p['quantity_difference'], ShopgateLogger::LOGTYPE_DEBUG);
$this->log("PS cart updateQty product id_product_attribute: " . $p['id_product_attribute'], ShopgateLogger::LOGTYPE_DEBUG);
$this->log("PS cart updateQty product delivery address: " . $deliveryAddress->id, ShopgateLogger::LOGTYPE_DEBUG);
//TODO deal with customizations
$id_customization = false;
if ($p['quantity'] - $p['quantity_difference'] > 0) {
// only if the result of $p['quantity'] - $p['quantity_difference'] is higher then 0
$cart->updateQty($p['quantity'] - $p['quantity_difference'], $p['id_product'], $p['id_product_attribute'], $id_customization, 'up', $deliveryAddress->id);
}
if ($p['quantity_difference'] > 0) {
$this->log("PS try to add cart message ", ShopgateLogger::LOGTYPE_DEBUG);
$message = new Message();
$message->id_cart = $cart->id;
$message->private = 1;
$message->message = 'Warning, wanted quantity for product "' . $p['name'] . '" was ' . $p['quantity'] . ' unit(s), however, the amount in stock is ' . $p['quantity_in_stock'] . ' unit(s). Only ' . $p['quantity_in_stock'] . ' unit(s) were added to the order';
$message->save();
}
}
$id_order_state = 0;
$shopgate = new Shopgate();
$payment_name = $shopgate->getTranslation('Mobile Payment');
$this->log("PS map payment method", ShopgateLogger::LOGTYPE_DEBUG);
if (!$order->getIsShippingBlocked()) {
$id_order_state = $this->getOrderStateId('PS_OS_PREPARATION');
switch ($order->getPaymentMethod()) {
case 'SHOPGATE':
$payment_name = $shopgate->getTranslation('Shopgate');
break;
case 'PREPAY':
$payment_name = $shopgate->getTranslation('Bankwire');
$id_order_state = $this->getOrderStateId('PS_OS_BANKWIRE');
break;
case 'COD':
$payment_name = $shopgate->getTranslation('Cash on Delivery');
break;
case 'PAYPAL':
$payment_name = $shopgate->getTranslation('PayPal');
break;
default:
break;
}
} else {
$id_order_state = $this->getOrderStateId('PS_OS_SHOPGATE');
switch ($order->getPaymentMethod()) {
case 'SHOPGATE':
$payment_name = $shopgate->getTranslation('Shopgate');
break;
case 'PREPAY':
$payment_name = $shopgate->getTranslation('Bankwire');
//.........这里部分代码省略.........
示例14: isEmailExists
/**
* Return if an email is already register
*
* @return boolean OR int idReferralProgram
*/
public static function isEmailExists($email, $getId = false, $checkCustomer = true)
{
if (empty($email) or !Validate::isEmail($email)) {
die(Tools::displayError('Email invalid.'));
}
if ($checkCustomer === true and Customer::customerExists($email)) {
return false;
}
$result = Db::getInstance()->getRow('
SELECT s.`id_referralprogram`
FROM `' . _DB_PREFIX_ . 'referralprogram` s
WHERE s.`email` = \'' . pSQL($email) . '\'');
if ($getId) {
return (int) $result['id_referralprogram'];
}
return isset($result['id_referralprogram']);
}
示例15: initContent
/**
* @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';
}
//.........这里部分代码省略.........