public function add($autodate = true, $null_values = true) { $this->id_shop = $this->id_shop ? $this->id_shop : Context::getContext()->shop->id; $this->id_shop_group = $this->id_shop_group ? $this->id_shop_group : Context::getContext()->shop->id_shop_group; $this->id_lang = $this->id_lang ? $this->id_lang : Context::getContext()->language->id; $this->birthday = empty($this->years) ? $this->birthday : (int) $this->years . '-' . (int) $this->months . '-' . (int) $this->days; $this->secure_key = md5(uniqid(rand(), true)); $this->last_passwd_gen = date('Y-m-d H:i:s', strtotime('-' . Configuration::get('PS_PASSWD_TIME_FRONT') . 'minutes')); if ($this->newsletter && !Validate::isDate($this->newsletter_date_add)) { $this->newsletter_date_add = date('Y-m-d H:i:s'); } if ($this->id_default_group == Configuration::get('PS_CUSTOMER_GROUP')) { if ($this->is_guest) { $this->id_default_group = (int) Configuration::get('PS_GUEST_GROUP'); } else { $this->id_default_group = (int) Configuration::get('PS_CUSTOMER_GROUP'); } } /* Can't create a guest customer, if this feature is disabled */ if ($this->is_guest && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) { return false; } $success = parent::add($autodate, $null_values); $this->updateGroup($this->groupBox); // start of implementation of the module code - taxamo if ($success) { $taxamo_iso_country_residence = Tools::getValue('taxamoisocountryresidence'); $taxamo_cc_prefix = Tools::getValue('taxamoccprefix'); Taxamoeuvat::addCCPrefix($this->id, $taxamo_iso_country_residence, $taxamo_cc_prefix); } // end of code implementation module - taxamo return $success; }
/** * Creates a new customer based on the given data. */ public static function create_customer_from_data(array $data, $send_email_to_admin = false, $send_email_to_customer = false) { if (is_array($data) && !empty($data['user_token']) && !empty($data['identity_token'])) { $password = Tools::passwdGen(); // Build customer fields. $customer = new CustomerCore(); $customer->firstname = $data['user_first_name']; $customer->lastname = $data['user_last_name']; $customer->id_gender = $data['user_gender']; $customer->birthday = $data['user_birthdate']; $customer->active = true; $customer->deleted = false; $customer->is_guest = false; $customer->passwd = Tools::encrypt($password); // We could get the email. if (!empty($data['user_email'])) { // It already exists. if (self::get_id_customer_for_email_address($data['user_email']) !== false) { // Create a new one. $customer->email = self::generate_random_email_address(); $customer->newsletter = false; } else { $customer->email = $data['user_email']; $customer->newsletter = true; } } else { // Create a new one. $customer->email = self::generate_random_email_address(); $customer->newsletter = false; } // Create a new user account. if ($customer->add()) { // Tie the tokens to the newly created member. if (self::link_tokens_to_id_customer($customer->id, $data['user_token'], $data['identity_token'], $data['identity_provider'])) { //Send an email to the customer if ($send_email_to_customer === true) { self::send_confirmation_to_customer($customer, $password, $data['identity_provider']); } //Send an email to the administratos if ($send_email_to_admin === true) { self::send_confirmation_to_administrators($customer, $data['identity_provider']); } //Done return $customer->id; } } } //Error return false; }
/** * Creates a new customer based on the given data. */ public static function create_customer_from_data(array $data, $send_email_to_admin = false, $send_email_to_customer = false) { if (is_array($data) && !empty($data['user_token']) && !empty($data['identity_token'])) { $password = Tools::passwdGen(); // Build customer fields. $customer = new CustomerCore(); $customer->firstname = $data['user_first_name']; $customer->lastname = $data['user_last_name']; $customer->id_gender = $data['user_gender']; $customer->birthday = $data['user_birthdate']; $customer->active = true; $customer->deleted = false; $customer->is_guest = false; $customer->passwd = Tools::encrypt($password); //Opted for the newsletter? if (!empty($data['user_newsletter'])) { $customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr()); $customer->newsletter_date_add = pSQL(date('Y-m-d H:i:s')); $customer->newsletter = true; } else { $customer->newsletter = false; } // We could get the email. if (!empty($data['user_email'])) { // It already exists. if (self::get_id_customer_for_email_address($data['user_email']) !== false) { // Create a new one. $customer->email = self::generate_random_email_address(); $customer->newsletter = false; } else { $customer->email = $data['user_email']; } } else { // Create a new one. $customer->email = self::generate_random_email_address(); $customer->newsletter = false; } // Create a new user account. if ($customer->add()) { // Tie the tokens to the newly created member. if (self::link_tokens_to_id_customer($customer->id, $data['user_token'], $data['identity_token'], $data['identity_provider'])) { //Send an email to the customer. if ($send_email_to_customer === true) { self::send_confirmation_to_customer($customer, $password, $data['identity_provider']); } //Send an email to the administrators if ($send_email_to_admin === true) { self::send_confirmation_to_administrators($customer, $data['identity_provider']); } //Process the newletter settings if ($customer->newsletter === true) { if ($module_newsletter = Module::getInstanceByName('blocknewsletter')) { if ($module_newsletter->active) { $module_newsletter->confirmSubscription($customer->email); } } } //Done return $customer->id; } } } //Error return false; }