/** Gets an existing user or creates a new one * * @param int $id * @param string $email * @param string $unique_gateway_id The ID that uniquely identifies the user to the payment system * @return JUser object * @access protected */ function &_getUser($id, $email, $unique_gateway_id = false) { $config = Tienda::getInstance(); $user = JFactory::getUser($id); if ($user->id) { return $user; } // try to find out if the email is registered jimport('joomla.user.helper'); if ($id = JUserHelper::getUserId($email)) { $user = JFactory::getUser($id); if ($user->id) { return $user; } } if ($unique_gateway_id) { // try to find a user in the payment_details if he ever made a payment if ($id = $this->_findUserId($unique_gateway_id, 'PAYERID')) { $user = JFactory::getUser($id); if ($user->id) { return $user; } } } // if no existing user found, create a new one $msg = new stdClass(); $msg->type = ''; $msg->message = ''; $newuser_email = $email; // create user from email jimport('joomla.user.helper'); $details['name'] = $newuser_email; $details['username'] = $newuser_email; $details['email'] = $newuser_email; $details['password'] = JUserHelper::genRandomPassword(); $details['password2'] = $details['password']; $details['block'] = $config->get('block_automatically_registered') ? '1' : '0'; if ($user = TiendaHelperUser::createNewUser($details, $msg)) { if (!$config->get('block_automatically_registered')) { // login the new user $login = TiendaHelperUser::login($details, '1'); } // indicate that user was registed by AS automatically $user->set('automatically_registered', true); } return $user; }
/** * Gets an existing user or creates a new one * * @param array $submitted_values Data for a new user * @param int $user_id Existing user id (optional) * @return JUser object * @access protected */ function _getUser($submitted_values, $user_id = 0) { $config = Tienda::getInstance(); if ($user_id) { $user = JFactory::getUser($user_id); } else { $user = JFactory::getUser(); } if ($user->id) { return $user; } Tienda::load('TiendaHelperUser', 'helpers.user'); $newuser_email = $submitted_values['CustomerEMail']; // create user from email jimport('joomla.user.helper'); $details['name'] = $newuser_email; $details['username'] = $newuser_email; $details['email'] = $newuser_email; $details['password'] = JUserHelper::genRandomPassword(); $details['password2'] = $details['password']; $details['block'] = $config->get('block_automatically_registered') ? '1' : '0'; if ($user = TiendaHelperUser::createNewUser($details)) { if (!$config->get('block_automatically_registered')) { // login the new user $login = TiendaHelperUser::login($details, '1'); } // indicate that user was registed by AS automatically $user->set('automatically_registered', true); } return $user; }
/** * Processes a new order * * @param $order_id * @return unknown_type */ function processOrder($order_id) { // get the order $model = JModel::getInstance('Orders', 'TiendaModel'); $model->setId($order_id); $order = $model->getItem(); if ($order->user_id < Tienda::getGuestIdStart()) { //load language from frontend so it has email language strings $lang = JFactory::getLanguage(); $lang->load('com_tienda', JPATH_SITE); $details = array(); $details['name'] = $order->billing_first_name . ' ' . $order->billing_last_name; $details['username'] = $order->userinfo_email; $details['email'] = $order->userinfo_email; jimport('joomla.user.helper'); $details['password'] = JUserHelper::genRandomPassword(); $details['password2'] = $details['password']; $user = TiendaHelperUser::createNewUser($details); $order->user_id = $user->id; //update the order to the new user $table = $model->getTable(); $table->load($order->order_id); $table->user_id = $user->id; $table->save(); $model->clearCache(); // } // find the products in the order that are integrated foreach ($order->orderitems as $orderitem) { $model = JModel::getInstance('Products', 'TiendaModel'); $model->setId($orderitem->product_id); $product = $model->getItem(); $core_user_change_gid = $product->product_parameters->get('core_user_change_gid'); $core_user_new_gid = $product->product_parameters->get('core_user_new_gid'); if (!empty($core_user_change_gid)) { DSCAcl::addgroup($order->user_id, $core_user_new_gid); } } }
public function save($values, $options = array()) { $result = new stdClass(); $result->error = false; Tienda::load('TiendaHelperUser', 'helpers.user'); $userHelper = new TiendaHelperUser(); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); $userinfo = JTable::getInstance('UserInfo', 'TiendaTable'); $user_id = $values["user_id"]; $create_account = $values["checkout_method"] == 'register' ? true : false; $guest_checkout = $this->defines->get('guest_checkout_enabled', '1'); if ($values["checkout_method"] == "guest") { // save the real user info in the userinfo table $userinfo->user_id = $user_id; $userinfo->email = $values['email_address']; if (!$userinfo->save()) { $result->error = true; $this->setError($userinfo->getError()); } // save the billing and shipping addresses? //$this->setAddresses($submitted_values, true, true); } elseif ($values["checkout_method"] == "register") { // create a new user from billing info $details = array('email' => $values['email_address'], 'name' => @$values['billing_input_first_name'] . ' ' . @$values['billing_input_middle_name'] . ' ' . @$values['billing_input_last_name'], 'username' => $values['email_address']); if (strlen(trim($details['name'])) == 0) { $details['name'] = JText::_('COM_TIENDA_USER'); } $details['password'] = $values["register-new-password"]; $details['password2'] = $values["register-new-password2"]; if (!($user = $userHelper->createNewUser($details, false))) { $result->error = true; //$this->setError( $user->getError() ); } else { $userHelper->login(array('username' => $user->username, 'password' => $details['password'])); $user_id = $user->id; $userinfo->load(array('user_id' => $user_id)); $userinfo->user_id = $user_id; $userinfo->first_name = @$values['billing_input_first_name']; $userinfo->last_name = @$values['billing_input_last_name']; $userinfo->company = @$values['billing_input_company']; $userinfo->middle_name = @$values['billing_input_middle_name']; $userinfo->phone_1 = @$values['billing_input_phone_1']; $userinfo->email = $values['email_address']; if (!$userinfo->save()) { $result->error = true; $this->setError($userinfo->getError()); } } } $result->user_id = $user_id; $result->userinfo = $userinfo; $this->result = $result; DSCModel::addIncludePath(JPATH_SITE . '/components/com_tienda/models'); $model = DSCModel::getInstance('Userinfo', 'TiendaModel'); $model->clearCache(); if ($result->error) { return false; } return $result; }