-- url of the page with the problem -- : Localhost - Testing
-- HikaShop version -- : HikaShop Business: 2.2.1
-- Joomla version -- : 3.1.5
-- PHP version -- : 5.3.8
-- Browser(s) name and version -- : Not Applicable
-- Error-message(debug-mod must be tuned on) -- : Lots so far
Hello, I am looking for a little bit of help. I have tried a few different components for managing users that integrate with Hikashop and have not liked what was available for various reasons. I created a user component that allows me to customize the Login page, Registration page, and Profile pages more the way I want them. I have also created a User Plugin so I can choose what fields show on all of these pages (address1, address 2, email, etc.)
I am now working on the Profile Page and would like to show the Hikashop address instead of the Joomla one. I am using code from the standard user - profile plugin in my own and it works like the original shows address1 and updates the table #__user_profiles when updating the user information.
The original onContentPrepareData function is as follows.
public function onContentPrepareData($context, $data)
{
// Check we are manipulating a valid form.
if (!in_array($context, array('com_users.profile', 'com_users.user', 'com_users.registration', 'com_usermod.profile', 'com_usermod.notlogged', 'com_admin.profile')))
{
return true;
}
if (is_object($data))
{
$userId = isset($data->id) ? $data->id : 0;
if (!isset($data->profile) and $userId > 0)
{
// Load the profile data from the database.
$db = JFactory::getDbo();
$db->setQuery(
'SELECT profile_key, profile_value FROM #__user_profiles' .
' WHERE user_id = ' . (int) $userId . " AND profile_key LIKE 'profile.%'" .
' ORDER BY ordering'
);
try
{
$results = $db->loadRowList();
}
catch (RuntimeException $e)
{
$this->_subject->setError($e->getMessage());
return false;
}
// Merge the profile data.
$data->profile = array();
foreach ($results as $v)
{
$k = str_replace('profile.', '', $v[0]);
$data->profile[$k] = json_decode($v[1], true);
if ($data->profile[$k] === null)
{
$data->profile[$k] = $v[1];
}
}
}
if (!JHtml::isRegistered('users.url'))
{
JHtml::register('users.url', array(__CLASS__, 'url'));
}
if (!JHtml::isRegistered('users.calendar'))
{
JHtml::register('users.calendar', array(__CLASS__, 'calendar'));
}
if (!JHtml::isRegistered('users.tos'))
{
JHtml::register('users.tos', array(__CLASS__, 'tos'));
}
}
return true;
}
After doing a few searches I am close but have not been able to come up with the best query to get the hikashop (address_street and address_street2 from the table #__hikashop_address) and inject it into the $data->profile array.
I believe I have to get the user_id from #__hikashop_user where the field user_cms_id matches the current users id.
// Get a db connection.
$hikashop_user_id = JFactory::getDbo();
// Create a new query object.
$hikashop_query = $hikashop_user_id->getQuery(true);
$hikashop_user_id->setQuery('SELECT user_id, user_cms_id FROM #__hikashop_user WHERE user_cms_id = ' . (int) $userId);
// Set $hikashop_id as the id we matched up in the hikashop_user_id query
$hikashop_id = $hikashop_user_id_results['user_id'];
And then use this user_id to query the #__hikashop_address table and get the address_street and address_street2 fields that match the current user.
// Load the users hikashop address that matches the correct id
$hikashop_db = JFactory::getDbo();
$hikashop_db->setQuery('SELECT address_id, address_user_id FROM #__hikashop_address WHERE address_user_id =' . (int) $hikashop_id);
Does anyone know if I can write one query to get all the user_profile info, and the hikashop_address info?
After that query is figured out I need to figure out how to inject it all into the $data->profile array that the user profile plugin will display for editing in the profile, and also change the onUserAfterSave function to update both the hikashop_address table and user_profile table.
Any help would be great, I am ok with standard sql queries but these ones are making my head spin.