function updatecart(){
$app = JFactory::getApplication();
$product_id = (int)JRequest::getCmd('product_id',0);
$module_id = (int)JRequest::getCmd('module_id',0);
$cart_type = JRequest::getString('hikashop_cart_type_'.$product_id.'_'.$module_id,'null');
if($cart_type == 'null')
$cart_type = JRequest::getString('cart_type','cart');
$cart_type_id = $cart_type.'_id';
// Sometimes >> getUserState / getInt
if(JRequest::getInt('cart_id',0,'GET') != 0){
$cart_id = JRequest::getInt('cart_id',0,'GET');
}else{
$cart_id = $app->getUserState(HIKASHOP_COMPONENT.'.'.$cart_type_id,0);
}
//if "add to" from the cart or wishlist
$addTo = JRequest::getString('add_to','');
if($addTo != ''){
$from_id = $cart_id;
if($addTo == 'cart')
JRequest::setVar('from_id',$cart_id);
$cart_id = $app->getUserState(HIKASHOP_COMPONENT.'.'.$addTo.'_id',0);
$cart_type_id = $addTo.'_id';
JRequest::setVar('cart_type', $addTo);
}else{
JRequest::setVar('cart_type', $cart_type);
}
//JRequest::setVar('wishlist_id',JRequest::getInt('wishlist_id','0'));
JRequest::setVar($cart_type_id, $cart_id);
$char = JRequest::getString('characteristic','');
if(!empty($char)){
return $this->show();
}else{
$tmpl = JRequest::getCmd('tmpl','index');
$add = JRequest::getCmd('add','');
if(!empty($add)){
$add=1;
}else{
$add=0;
}
if(empty($product_id)){
$product_id = JRequest::getCmd('cid',0);
}
$cart_product_id = JRequest::getCmd('cart_product_id',0);
$quantity = JRequest::getInt('quantity',1);
$class = hikashop_get('class.cart');
if(hikashop_loadUser() != null || $cart_type != 'wishlist'){
if(!empty($product_id)){
$type = JRequest::getWord('type','product');
if($type=='product'){
$product_id=(int)$product_id;
}
$status = $class->update($product_id,$quantity,$add,$type);
}elseif(!empty($cart_product_id)){
$status = $class->update($cart_product_id,$quantity,$add,'item');
}else{
$formData = JRequest::getVar( 'item', array(), '', 'array' );
if(!empty($formData)){
$class->update($formData,0,$add,'item');
}else{
$formData = JRequest::getVar( 'data', array(), '', 'array' );
if(!empty($formData)){
$class->update($formData,0,$add);
}
}
}
}
$app->setUserState(HIKASHOP_COMPONENT.'.'.$cart_type.'_new', '1');
if(@$class->errors && $tmpl!='component'){
if(!empty($_SERVER['HTTP_REFERER'])){
if(strpos($_SERVER['HTTP_REFERER'],HIKASHOP_LIVE)===false && preg_match('#^https?://.*#',$_SERVER['HTTP_REFERER'])) return false;
$app->redirect($_SERVER['HTTP_REFERER']);
}else{
echo '<html><head><script type="text/javascript">history.back();</script></head><body></body></html>';
exit;
}
}
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_method','');
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_id','');
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_data','');
$app->setUserState( HIKASHOP_COMPONENT.'.payment_method','');
$app->setUserState( HIKASHOP_COMPONENT.'.payment_id','');
$app->setUserState( HIKASHOP_COMPONENT.'.payment_data','');
$config =& hikashop_config();
$checkout = JRequest::getString('checkout','');
if(!empty($checkout)){
global $Itemid;
$url = 'checkout';
if(!empty($Itemid)){
$url.='&Itemid='.$Itemid;
}
$url = hikashop_completeLink($url,false,true);
$this->setRedirect($url);
}
else if($cart_type == 'wishlist'){
if(hikashop_loadUser() == null){
$app->enqueueMessage('LOGIN_REQUIRED_FOR_WISHLISTS');
$stay = 0;
$url = JRequest::getVar('return_url','');
if(!empty($url)){
$url=base64_decode(urldecode($url));
}
$url = str_replace('&popup=1','',$url);
}else{
$redirectConfig = $config->get('redirect_url_after_add_cart','stay_if_cart');
$url='';
$stay = 0;
switch($redirectConfig){
case 'ask_user':
$url = JRequest::getVar('return_url','');
if(!empty($url)){
$url=base64_decode(urldecode($url));
}
$url = str_replace('&popup=1','',$url);
if(JRequest::getInt('popup',0) || JRequest::getInt('quantity',0)){
if(strpos($url,'?')){
$url.='&';
}else{
$url.='?';
}
$url.='popup=1';
}
JRequest::setVar('cart_type','wishlist');
$app->setUserState( HIKASHOP_COMPONENT.'.popup_cart_type','wishlist');
break;
case 'stay':
$stay = 1;
break; //$stay = 1; && $url ='';
case 'checkout':
break; //$stay = 0; && $url ='';
case 'stay_if_cart':
$module = JModuleHelper::getModule('hikashop_cart',false);
if($module != null){
$stay = 1;
}
break;
default:
break;
}
}
if(empty($url)){
global $Itemid;
if(isset($from_id))$cart_id = $from_id;
if(JRequest::getInt('new_'.$cart_type.'_id',0)!= 0 && JRequest::getInt('delete',0) == 0)$cart_id = JRequest::getInt('new_'.$cart_type.'_id',0);
$cart = $class->get($cart_id,false,$cart_type);
if(!empty($cart) && (int)$cart_id != 0){
$url = 'cart&task=showcart&cart_type=wishlist&cart_id='.$cart_id.'&Itemid='.$Itemid;
}else{
$url = 'cart&task=showcarts&cart_type=wishlist&Itemid='.$Itemid;
}
$url = hikashop_completeLink($url,false,true);
}
if($stay == 0){
if(strpos($url,HIKASHOP_LIVE)===false && preg_match('#^https?://.*#',$url)) return false;
$this->setRedirect($url);
}else{
echo '<html><head><script type="text/javascript">history.back();</script></head><body></body></html>';
exit;
}
}else{
$url = JRequest::getVar('return_url','');
if(empty($url)){
$url = JRequest::getVar('url','');
$url = urldecode($url);
}else{
$url = base64_decode(urldecode($url));
}
$url = str_replace('&popup=1','',$url);
if(empty($url)){
global $Itemid;
$url = 'checkout';
if(!empty($Itemid)){
$url.='&Itemid='.$Itemid;
}
$url = hikashop_completeLink($url,false,true);
}
if($tmpl=='component'){
//display cart module content
$js ='';
jimport('joomla.application.module.helper');
global $Itemid;
if(isset($Itemid) && empty($Itemid)){
$Itemid=null;
JRequest::setVar('Itemid',null);
}
$module = JModuleHelper::getModule('hikashop_cart',false);
$config =& hikashop_config();
$params = new HikaParameter( @$module->params );
if(!empty($module)){
$module_options = $config->get('params_'.$module->id);
}
if(empty($module_options)){
$module_options = $config->get('default_params');
}
foreach($module_options as $key => $optionElement){
$params->set($key,$optionElement);
}
if(!empty($module)){
foreach(get_object_vars($module) as $k => $v){
if(!is_object($v)){
$params->set($k,$v);
}
}
$params->set('from','module');
}
$params->set('return_url',$url);
hikashop_getLayout('product','cart',$params,$js);
return true;
}else{
$config =& hikashop_config();
if(JRequest::getInt('popup',0) || (@JRequest::getInt('quantity',0) && $config->get('redirect_url_after_add_cart','stay_if_cart') == 'ask_user')){
if(strpos($url,'?')){
$url.='&';
}else{
$url.='?';
}
$url.='popup=1';
}
if(strpos($url,HIKASHOP_LIVE)===false && preg_match('#^https?://.*#',$url)) return false;
$this->setRedirect($url);
return false;
}
}
}
}