/** * Build an SQL query to load the list data. * * @return JDatabaseQuery * * @since 1.6 */ protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); $user = JFactory::getUser(); $jinput = JFactory::getApplication()->input; $layout = $jinput->get('layout', 'default', 'STRING'); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from('`#__kart_items` AS a'); $query->JOIN('LEFT', '`#__categories` AS c ON c.id=a.category'); // Filter by search in title. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.item_id = ' . (int) substr($search, 3)); } else { $search = $db->Quote('%' . $db->escape($search, true) . '%'); $query->where('( a.name LIKE ' . $search . ')'); } } // Filter by published state. $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } elseif ($published === '') { if ($layout == 'my') { $query->where('(a.state IN (0, 1))'); } else { $query->where('(a.state = 1)'); } } // Filter by category. $filter_menu_category = $this->state->get("filter.menu_category"); if ($filter_menu_category) { $filter_show_subcat_products = $this->state->get("filter.show_subcat_products"); if ($filter_show_subcat_products) { $catWhere = $this->getWhereCategory($filter_menu_category); if ($catWhere) { foreach ($catWhere as $cw) { $query->where($cw); } } } else { $query->where("a.category = '" . $db->escape($filter_menu_category) . "'"); } } else { $filter_category = $this->state->get("filter.category"); if ($filter_category) { $catWhere = $this->getWhereCategory($filter_category); if ($catWhere) { foreach ($catWhere as $cw) { $query->where($cw); } } } } if ($layout == 'default') { // Show only the native products and published category, $query->where(" c.published = 1"); $query->where(" a.parent = 'com_quick2cart'"); $storeHelper = new storeHelper(); $storeIds = $storeHelper->getStoreIds(1); if (!empty($storeIds)) { $storeidStr = implode(',', $storeIds); $query->where(" a.store_id IN (" . $storeidStr . ')'); } else { // If all stores are unpublished then dont show $query->where(" a.store_id = -1"); } $filter_category = $this->state->get("filter.category"); if ($filter_category) { // Show from decedor category $catWhere = $this->getWhereCategory($filter_category); if ($catWhere) { foreach ($catWhere as $cw) { $query->where($cw); } } } } else { // My stores view. // Filter by store. $filter_store = $this->state->get("filter.store"); // Get all published stores by logged in user $comquick2cartHelper = new comquick2cartHelper(); $my_stores = $comquick2cartHelper->getStoreIds($user->id); if (count($my_stores)) { // Get all store ids foreach ($my_stores as $key => $value) { $stores[] = $value["store_id"]; } // If store filter is selected, check it in my stores array if ($filter_store) { if (in_array($filter_store, $stores)) { $query->where("a.store_id = '" . $db->escape($filter_store) . "'"); } } else { // If selected store filter is not found in my stores array, show products from all stores for logged in user $stores = implode(',', $stores); if (!empty($stores)) { $query->where(" a.store_id IN (" . $stores . ")"); } } } else { // Unauthorized access $query->where(" a.store_id=0"); } } // Add the list ordering clause. $orderCol = $this->state->get('list.ordering'); $orderDirn = $this->state->get('list.direction'); if ($orderCol && $orderDirn) { $query->order($db->escape($orderCol . ' ' . $orderDirn)); } return $query; }