/** * Tienda User store user method * * Method is called after user data is stored in the database * The sort order of this plugin must be set to be after the User - Tienda plugin, because * that creates an entry in userinfo, and we can't act without that. * * @param array holds the new user data * @param boolean true if a new user is stored * @param boolean true if user was succesfully stored in the database * @param string message */ function onAfterStoreUser($user, $isnew, $success, $msg) { $create_address = $this->params->get('create_address', 0); if ($isnew) { // load the config class Tienda::load('Tienda', 'defines'); $notify = $this->params->get('notify_person', 1); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables'); Tienda::load('TiendaHelperSubscription', 'helpers.subscription'); $component = JRequest::getCmd('option'); $tokens = explode(' ', $user['name']); $last_name = $first_name = ''; if (count($tokens) > 1) { $last_name = $tokens[count($tokens) - 1]; $first_name = str_replace($last_name, '', $user['name']); } else { $last_name = $user['name']; } //save the subscription number $tblUser = JTable::getInstance('UserInfo', 'TiendaTable'); $tblUser->load(array('user_id' => $user['id'])); $tblUser->user_id = $user['id']; $tblUser->sub_number = TiendaHelperSubscription::getNextSubNum(); // one-page checkout + other registrations that are not done via tienda -> we need to add data manually if ($component != 'com_tienda' || $component == 'com_tienda' && Tienda::getInstance()->get('one_page_checkout', 0)) { $tblUser->last_name = $last_name; $tblUser->first_name = $first_name; $tblUser->email = $user['email']; } if (!$tblUser->save()) { $this->sendNotification(JText::_('Error during saving subscription number'), $user['id']); JError::raiseError(500, JText::_('Error during saving subscription number')); return; } // we want to create a default address and are not registering via tienda // (tienda takes care about it automatically) if ($create_address && $component != 'com_tienda') { $tblAddress = JTable::getInstance('Addresses', 'TiendaTable'); $tblAddress->user_id = $user['id']; $tblAddress->addresstype_id = 1; $tblAddress->address_name = $this->params->get('address_title', JText::_('Main Address Default')); $tblAddress->country_id = $this->params->get('default_country', 0); $tblAddress->zone_id = $this->params->get('default_zone', 0); $tblAddress->is_default_billing = 1; $tblAddress->is_default_shipping = 1; $tblAddress->last_name = $last_name; $tblAddress->first_name = $first_name; if (!$tblAddress->store()) { $this->sendNotification(JText::_('Error during creating an empty address'), $user['id']); JError::raiseError(500, JText::_('Error during creating an empty address')); return; } } } }