function restoreSession(&$user_id){
$app = JFactory::getApplication();
$cart = $app->getUserState('com_hikashop.cart_id');
//it's really important to check on $cart, otherwise, it doesn't work with the normal joomla login
if(empty($cart) && !empty($this->cart)){
$app->setUserState('com_hikashop.cart_id',$this->cart);
if(!defined('DS'))
define('DS', DIRECTORY_SEPARATOR);
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
$cartClass = hikashop_get('class.cart');
$cartClass->initCart();
}
if(!empty($cart) || !empty($this->cart)){
$config = hikashop_config();
//delete old carts when a new cart is present and that the multicart mode is deactivated
if( !$app->isAdmin() && !$config->get('enable_multicart') && !empty($user_id) ){
$db = JFactory::getDBO();
$db->setQuery('SELECT cart_id FROM #__hikashop_cart WHERE user_id='.(int)$user_id).' AND cart_type = '.$db->Quote('cart');
$ids = $db->loadObjectList('cart_id');
if(isset($ids[$this->cart]))
unset($ids[$this->cart]);
if(count($ids)){
$cartClass = hikashop_get('class.cart');
foreach($ids as $id){
$cartClass->delete($id->cart_id,'old');
}
}
}
}
$wishlist = $app->getUserState('com_hikashop.wishlist_id');
//it's really important to check on $wishlist, otherwise, it doesn't work with the normal joomla login
if(empty($wishlist) && !empty($this->wishlist)){
$app->setUserState('com_hikashop.wishlist_id',$this->wishlist);
if(!defined('DS'))
define('DS', DIRECTORY_SEPARATOR);
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
$cartClass = hikashop_get('class.cart');
$cart_type = JRequest::getString('cart_type','cart');
JRequest::setVar('cart_type','wishlist');
$cartClass->initCart();
JRequest::setVar('cart_type',$cart_type);
}
$entries = $app->getUserState('com_hikashop.entries_fields');
if(empty($entries) && !empty($this->entries)){
$app->setUserState('com_hikashop.entries_fields',$this->entries);
}
$currency = $app->getUserState('com_hikashop.currency_id');
if(empty($currency) && !empty($this->currency)){
$app->setUserState('com_hikashop.currency_id',$this->currency);
}
$checkout_fields_ok = $app->getUserState('com_hikashop.checkout_fields_ok');
if(empty($checkout_fields_ok) && !empty($this->checkout_fields_ok)){
$app->setUserState('com_hikashop.checkout_fields_ok',$this->checkout_fields_ok);
}
$checkout_fields = $app->getUserState('com_hikashop.checkout_fields');
if(empty($checkout_fields) && !empty($this->checkout_fields)){
$app->setUserState('com_hikashop.checkout_fields',$this->checkout_fields);
}
//on some servers with some osbcure config, we really need to force the fields value in the POST/REQUEST as the checkout tries to get them from there after the login
if(!empty($this->checkout_fields)){
foreach($this->checkout_fields as $k =>$v){
if(!isset($_REQUEST['data']['order'][$k])){
$_POST['data']['order'][$k] = $_REQUEST['data']['order'][$k] = $v;
}
}
}
}