function listing(){
$this->setName();
$config = hikashop_config();
$app = JFactory::getApplication();
$pageInfo = new stdClass();
$pageInfo->filter = new stdClass();
$pageInfo->filter->order = new stdClass();
$pageInfo->limit = new stdClass();
$pageInfo->search = $app->getUserStateFromRequest( $this->paramBase.".search", 'search', '', 'string' );
$pageInfo->filter->order->value = $app->getUserStateFromRequest( $this->paramBase.".filter_order", 'filter_order', 'a.cart_modified','cmd' );
$pageInfo->filter->order->dir = $app->getUserStateFromRequest( $this->paramBase.".filter_order_Dir", 'filter_order_Dir', 'desc', 'word' );
$pageInfo->limit->value = $app->getUserStateFromRequest( $this->paramBase.'.list_limit', 'limit', $app->getCfg('list_limit'), 'int' );
$pageInfo->limit->start = $app->getUserStateFromRequest( $this->paramBase.'.limitstart', 'limitstart', 0, 'int' );
$pageInfo->manageUser = hikashop_isAllowed($config->get('acl_user_manage','all'));
$popup = (JRequest::getString('tmpl') === 'component');
$database = JFactory::getDBO();
if(JRequest::getString('cart_type', 'cart') == 'cart')
$filters = array('a.cart_type=\'cart\'');
else
$filters = array('a.cart_type=\'wishlist\'');
$searchMap = array('a.cart_id','a.user_id','a.cart_name','a.cart_coupon','a.cart_type');
if(!empty($pageInfo->search)){
$searchVal = '\'%'.hikashop_getEscaped(JString::strtolower( $pageInfo->search ),true).'%\'';
$filters[] = implode(" LIKE $searchVal OR ",$searchMap)." LIKE $searchVal";
}
$groupBy = 'GROUP BY a.cart_id';
$order = '';
if(!empty($pageInfo->filter->order->value)){
$order = ' ORDER BY '.$pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
}
if(!empty($filters)){
$filters = ' WHERE '. implode(' AND ',$filters);
}else{
$filters = '';
}
// 2 requests > 1 for the carts > 1 for the products
$from = 'FROM '.hikashop_table('cart').' AS a';
$cartProduct = 'JOIN '.hikashop_table('cart_product').' AS b ON a.cart_id=b.cart_id';
$query = $from.' '.$cartProduct.' '.$filters.' '.$groupBy.' '.$order;
$database->setQuery('SELECT a.*, b.* '.$query,(int)$pageInfo->limit->start,(int)$pageInfo->limit->value);
$rows = $database->loadObjectList();
if(!empty($pageInfo->search)){
$rows = hikashop_search($pageInfo->search,$rows,'cart_id');
}
$database->setQuery('SELECT COUNT(*) '.$from.' '.$cartProduct.' '.$filters.' '.$groupBy);
$pageInfo->elements = new stdClass();
$pageInfo->elements->total = $database->loadResult();
$pageInfo->elements->page = count($rows);
$currencyClass = hikashop_get('class.currency');
$this->assignRef('currencyHelper',$currencyClass);
// EO Filters & Pagination
$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);
// New filters to have only items from selected carts
$cids = array();
foreach($rows as $row){
if($row->cart_id != null)
$cids[] = $row->cart_id;
}
if(!empty($cids))
$filters = array('a.cart_id IN('.implode(",",$cids).')');
$order = '';
if(!empty($pageInfo->filter->order->value)){
$order = ' ORDER BY cart_id ASC';
}
// 2nd request to have the products caracteristics
$products = null;
if(!empty($cids)){
$product = ' LEFT JOIN '.hikashop_table('product').' AS b ON a.product_id=b.product_id';
$query = 'FROM '.hikashop_table('cart_product').' AS a '.$product.' WHERE ('.implode(') AND (',$filters).') '.$order;
$database->setQuery('SELECT a.*,b.* '.$query);
$products = $database->loadObjectList();
}
if(!empty($products)){
$ids = array();
foreach($products as $row){
$ids[] = $row->product_id;
}
$row_1 = 0;
foreach($products as $k => $row){
$currencyClass->getPrices($row,$ids,$currency_id,$main_currency,$zone_id,$discount_before_tax);
if(!isset($row->prices[0]) && isset($row_1->prices[0])){
$row->prices[0] = $row_1->prices[0];
}
$products[$k]->hide = 0;
if($row->product_type == 'variant'){
$products[--$k]->hide = 1;
}
$row_1 = $row;
}
$currentId = 0;
$values = array();
$currency = hikashop_getCurrency();
foreach($products as $product){
if(isset($product->cart_id)){
if($product->cart_id != $currentId){
$price = 0;
$quantity = 0;
$currentId = $product->cart_id;
if(isset($product->prices[0]))
$currency = $product->prices[0]->price_currency_id;
}
if(isset($product->prices[0])){
$price += $product->cart_product_quantity * $product->prices[0]->price_value;
$quantity += $product->cart_product_quantity;
}
if(!isset($values[$currentId])) $values[$currentId] = new stdClass();
$values[$currentId]->price = $price;
$values[$currentId]->quantity = $quantity;
$values[$currentId]->currency = $currency;
}
}
}
foreach($rows as $k => $row){
if($values[$row->cart_id] != null){
$rows[$k]->price = $values[$row->cart_id]->price;
$rows[$k]->quantity = $values[$row->cart_id]->quantity;
$rows[$k]->currency = $values[$row->cart_id]->currency;
}
}
$cart=hikashop_get('helper.cart');
$this->assignRef('cart',$cart);
$this->assignRef('carts',$rows);
$this->assignRef('popup',$popup);
$pageInfo->elements->total = count($rows);
$pagination = hikashop_get('helper.pagination', $pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value);
$pagination->hikaSuffix = '';
$this->assignRef('pagination',$pagination);
$this->assignRef('pageInfo',$pageInfo);
hikashop_setTitle(JText::_($this->nameListing),$this->icon,$this->ctrl);
$config =& hikashop_config();
$manage = hikashop_isAllowed($config->get('acl_wishlist_manage','all'));
$this->assignRef('manage',$manage);
$this->toolbar = array(
array('name'=>'addNew','display'=>$manage),
array('name'=>'editList','display'=>$manage),
array('name'=>'deleteList','display'=>hikashop_isAllowed($config->get('acl_wishlist_delete','all'))),
'|',
array('name' => 'pophelp', 'target' => $this->ctrl.'-listing'),
'dashboard'
);
}