function showcart(){
$app = JFactory::getApplication();
$menus = $app->getMenu();
$menu = $menus->getActive();
if(empty($menu)){
if(!empty($Itemid)){
$menus->setActive($Itemid);
$menu = $menus->getItem($Itemid);
}
}
if(empty($cart_type)){
if (is_object( $menu )) {
$cart_type = $menu->params->get('cart_type');
JRequest::setVar('cart_type',$cart_type);
}
}
if(empty($cart_type)){
$cart_type = $this->params->get('cart_type','cart');
}
$module = hikashop_get('helper.module');
$module->initialize($this);
$database = JFactory::getDBO();
$config =& hikashop_config();
$currencyClass = hikashop_get('class.currency');
$class = hikashop_get('class.cart');
$productClass = hikashop_get('class.product');
$main_currency = (int)$config->get('main_currency',1);
$currency_id = hikashop_getCurrency();
if($config->get('tax_zone_type','shipping')=='billing'){
$zone_id = hikashop_getZone('billing');
}else{
$zone_id = hikashop_getZone('shipping');
}
$discount_before_tax = (int)$config->get('discount_before_tax',0);
//$cart_type = $this->params->get('cart_type','cart');
$cart_id = JRequest::getInt('cart_id','');
if(empty($cart_id) || $cart_id == 0){
$cart_id = $app->getUserState( HIKASHOP_COMPONENT.'.'.$cart_type.'_id', 0, 'int' );
if($cart_id == 0){
//SQL Request
$session = JFactory::getSession();
$session_id = '';
if($session->getId()){
$session_id = $session->getId();
}
if(hikashop_loadUser() == null){
$filter = 'a.session_id = '.$database->Quote($session_id);
}else{
$userInfo = hikashop_loadUser(true);
$filter = '(a.user_id = '.(int)$userInfo->user_cms_id.' OR a.session_id = '.$database->Quote($session_id).')';
}
$query = 'SELECT a.* FROM '.hikashop_table('cart').' AS a WHERE a.cart_type = '.$database->Quote($cart_type).' AND '.$filter;
$database->setQuery($query);
$userCarts = $database->loadObjectList();
$ok = 0;
$old_modified = 0;
foreach($userCarts as $userCart){
if((int)$userCart->cart_current == 1){
$cart_id = (int)$userCart->cart_id;
$ok = 1;
}else if($ok == 0){
if($old_modified <= $userCart->cart_modified){
$cart_id = $userCart->cart_id;
$old_modified = $userCart->cart_modified;
}
}
}
}
}
$app->setUserState( HIKASHOP_COMPONENT.'.'.$cart_type.'_id', $cart_id, 'int' );
$rows = $class->get($cart_id,false,$cart_type);
$popup = hikashop_get('helper.popup');
$this->assignRef('popup',$popup);
//get the cart user id
$query = 'SELECT * FROM '.hikashop_table('cart').' AS a WHERE a.cart_id = '.$cart_id;
$database->setQuery($query);
$cartVal = $database->loadObject();
// If empty cart > redirect to the carts listing
if($cartVal == null){
global $Itemid;
$url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=cart&task=showcarts&cart_type='.$cart_type.'&Itemid='.$Itemid;
$app->redirect($url);
}
$user = $cartVal->user_id;
//Get the list of the buyers
if($cartVal->cart_type == 'wishlist' && $user == $cartVal->user_id){
$query='SELECT a.*,b.* FROM '.hikashop_table('order').' AS a LEFT JOIN '.hikashop_table('order_product').' AS b ON a.order_id=b.order_id WHERE b.order_product_wishlist_id ='.(int)$cart_id;
$database->setQuery($query);
$buyers = $database->loadObjectList();
foreach($buyers as $j => $buyer){
foreach($rows as $k => $row){
if($row->product_id == $buyer->product_id){
if($buyer->order_user_id == $user){
$rows[$k]->bought[$j] = JText::_('ORDER_NUMBER').": ".$buyer->order_id;
}else{
$userClass = hikashop_get('class.user');
$user = $userClass->get($buyer->order_user_id);
if(!empty($user->username)){
$rows[$k]->bought[$j] = $user->username;
}else if(!empty($user->user_email)){
$rows[$k]->bought[$j] = $user->user_email;
}else{
$rows[$k]->bought[$j] = JText::_('HKASHOP_USER_ID').": ".$buyer->order_user_id;
}
}
}
}
}
}
//Set the rights to display the wishlist
if(/*$user->usertype != null &&*/ $cartVal->cart_share == 'registered'){
$cartVal->display = 'registered';
}
else if($cartVal->cart_share == 'public'){
$cartVal->display = 'public';
}
else if(in_array($user,explode(',',$cartVal->cart_share))){
$cartVal->display = $cartVal->cart_share;
}
else if(JRequest::getString('link','link') == $cartVal->cart_share || strlen($cartVal->cart_share) == 20){
$cartVal->display = $cartVal->cart_share;
}
else{
$cartVal->display = 'main';
}
if($cart_type == 'cart'){
$cartVal->display = 'main';
}
$total = new stdClass();
if(!empty($rows)){
$variants = false;
$ids = array();
foreach($rows as $k => $row){
$ids[]=$row->product_id;
if($row->product_type=='variant'){
$variants = true;
foreach($rows as $k2 => $row2){
if($row->product_parent_id==$row2->product_id){
$rows[$k2]->variants[]=&$rows[$k];
}
}
}
}
if($variants){
$this->selected_variant_id = 0;
$query = 'SELECT a.*,b.* FROM '.hikashop_table('variant').' AS a LEFT JOIN '.hikashop_table('characteristic').' AS b ON a.variant_characteristic_id=b.characteristic_id WHERE a.variant_product_id IN ('.implode(',',$ids).') ORDER BY a.ordering ASC,b.characteristic_value ASC';
$database->setQuery($query);
$characteristics = $database->loadObjectList();
if(!empty($characteristics)){
foreach($rows as $k => $row){
$element =& $rows[$k];
$product_id=$row->product_id;
if($row->product_type=='variant'){
continue;
}
$mainCharacteristics = array();
foreach($characteristics as $characteristic){
if($product_id==$characteristic->variant_product_id){
$mainCharacteristics[$product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id]=$characteristic;
}
if(!empty($element->options)){
foreach($element->options as $k => $optionElement){
if($optionElement->product_id==$characteristic->variant_product_id){
$mainCharacteristics[$optionElement->product_id][$characteristic->characteristic_parent_id][$characteristic->characteristic_id]=$characteristic;
}
}
}
}
if(!empty($element->variants)){
$this->addCharacteristics($element,$mainCharacteristics,$characteristics);
}
if(!empty($element->options)){
foreach($element->options as $k => $optionElement){
if(!empty($optionElement->variants)){
$this->addCharacteristics($element->options[$k],$mainCharacteristics,$characteristics);
}
}
}
}
}
}
$product_quantities = array();
foreach($rows as $row){
if(empty($product_quantities[$row->product_id])){
$product_quantities[$row->product_id] = (int)@$row->cart_product_quantity;
}else{
$product_quantities[$row->product_id]+=(int)@$row->cart_product_quantity;
}
}
foreach($rows as $k => $row){
$rows[$k]->cart_product_total_quantity = $product_quantities[$row->product_id];
}
$currencyClass->getPrices($rows,$ids,$currency_id,$main_currency,$zone_id,$discount_before_tax);
foreach($rows as $k => $row){
if(!empty($row->variants)){
foreach($row->variants as $k2 => $variant){
$productClass->checkVariant($rows[$k]->variants[$k2],$row);
}
}
}
foreach($rows as $k => $row){
$currencyClass->calculateProductPriceForQuantity($rows[$k]);
$rows[$k]->hide = 0;
if($row->product_type == 'variant'){
$rows[--$k]->hide = 1;
}
}
$total=new stdClass();
$currencyClass->calculateTotal($rows,$total,$currency_id);
}
$this->assignRef('total',$total);
$this->assignRef('cartVal',$cartVal);
$this->assignRef('rows',$rows);
$this->assignRef('config',$config);
$cart=hikashop_get('helper.cart');
$this->assignRef('cart',$cart);
$this->assignRef('currencyHelper',$currencyClass);
$cart->cartCount(true);
$url = $this->init(true);
$this->params->set('url',$url);
ob_start();
$cart->getJS($url,false);
$notice_html = ob_get_clean();
$this->assignRef('notice_html',$notice_html);
if(hikashop_level(2)){
$null=null;
$fieldsClass=hikashop_get('class.field');
$itemFields = $fieldsClass->getFields('frontcomp',$null,'item','checkout&task=state');
$this->assignRef('itemFields',$itemFields);
$this->assignRef('fieldsClass',$fieldsClass);
}
JHTML::_('behavior.tooltip');
}