public static
getProducts
(mixed $limitOffset = 0, mixed $limitCount = 1, mixed $orderingItem = 1, mixed $orderingCat = 0, mixed $checkPublished = false, mixed $checkStock = false, mixed $checkPrice = false, mixed $categoriesList = 0, mixed $categoryIds = array(), mixed $featuredOnly = 0, mixed $type = array(0, 1), mixed $queryColumns = '', mixed $return = '', mixed $filterLang = false)
/*
* checkPublished = true - select only published products
* checkPublished = false - select all (published|unpublished) products
* PUBLISHED MEANS, THEY ARE REALLY PUBLISHED - they are published as products and their category is published too.
*
* checkStock - check Stock or not ( > 0 )
* checkPrice - check if the product has price or not ( > 0 )
*/
public static function getProducts($limitOffset = 0, $limitCount = 1, $orderingItem = 1, $orderingCat = 0, $checkPublished = false, $checkStock = false, $checkPrice = false, $categoriesList = 0, $categoryIds = array(), $featuredOnly = 0, $type = array(0, 1), $queryColumns = '', $return = '', $filterLang = false)
{
/*phocacart import('phocacart.ordering.ordering');*/
$ordering = PhocacartOrdering::getOrderingCombination($orderingItem, $orderingCat);
$db = Factory::getDBO();
$wheres = array();
$user = PhocacartUser::getUser();
$userLevels = implode(',', $user->getAuthorisedViewLevels());
$userGroups = implode(',', PhocacartGroup::getGroupsById($user->id, 1, 1));
$wheres[] = " a.access IN (" . $userLevels . ")";
$wheres[] = " c.access IN (" . $userLevels . ")";
$wheres[] = " (ga.group_id IN (" . $userGroups . ") OR ga.group_id IS NULL)";
$wheres[] = " (gc.group_id IN (" . $userGroups . ") OR gc.group_id IS NULL)";
if ($checkPublished) {
$wheres[] = " a.published = 1";
$wheres[] = " c.published = 1";
}
if (!empty($type) && is_array($type)) {
$wheres[] = 'c.type IN (' . implode(',', $type) . ')';
}
if ($checkStock) {
$wheres[] = " a.stock > 0";
}
if ($checkPrice) {
$wheres[] = " a.price > 0";
}
if (!empty($categoryIds)) {
$catIdsS = implode(',', $categoryIds);
$wheres[] = 'pc.category_id IN (' . $catIdsS . ')';
}
if ($featuredOnly) {
$wheres[] = 'a.featured = 1';
}
// Additional Hits
if ($orderingItem == 17 || $orderingItem == 18) {
$wheres[] = 'ah.product_id = a.id';
$wheres[] = 'ah.user_id = ' . (int) $user->id;
$wheres[] = 'ah.user_id > 0';
}
// Filter langauge
if ($filterLang) {
$lang = Factory::getLanguage()->getTag();
$wheres[] = PhocacartUtilsSettings::getLangQuery('a.language', $lang);
$wheres[] = PhocacartUtilsSettings::getLangQuery('c.language', $lang);
}
// Views Plugin can load additional columns
$additionalColumns = array();
$pluginLayout = PluginHelper::importPlugin('pcv');
if ($pluginLayout) {
$pluginOptions = array();
$eventData = array();
Factory::getApplication()->triggerEvent('onPCVonProductsBeforeLoadColumns', array('com_phocacart.products', &$pluginOptions, $eventData));
if (isset($pluginOptions['columns']) && $pluginOptions['columns'] != '') {
if (!empty($pluginOptions['columns'])) {
foreach ($pluginOptions['columns'] as $k => $v) {
$additionalColumns[] = PhocacartText::filterValue($v, 'alphanumeric3');
}
}
}
}
$baseColumns = array('a.id', 'a.title', 'a.image', 'a.video', 'a.alias', 'a.description', 'a.description_long', 'a.sku', 'a.ean', 'a.stockstatus_a_id', 'a.stockstatus_n_id', 'a.min_quantity', 'a.min_multiple_quantity', 'a.stock', 'a.unit_amount', 'a.unit_unit', 'a.price', 'a.price_original', 'a.date', 'a.sales', 'a.featured', 'a.external_id', 'a.condition', 'a.points_received', 'a.points_needed', 'a.delivery_date', 'a.type', 'a.type_feed', 'a.type_category_feed', 'a.params_feed', 'a.gift_types');
$col = array_merge($baseColumns, $additionalColumns);
$col = array_unique($col);
/*
* type_feed - specific type of products used in XML feed (for example by Google products: g:product_type)
* type_category_feed - specific type of product category used in XML feed (for example by Google products: g:google_product_category)
* - overrides category type_feed (type feed in category table)
* type - digital (downloadable) product or physical product
*/
if ($queryColumns != '') {
$columns = $queryColumns;
$groupsFull = $queryColumns;
$groupsFast = 'a.id';
} else {
$columns = implode(',', $col) . ', c.id AS catid, c.title AS cattitle, c.alias AS catalias, c.title_feed AS cattitlefeed, c.type_feed AS cattypefeed, MIN(ppg.price) as group_price, MAX(pptg.points_received) as group_points_received, t.id as taxid, t.tax_rate AS taxrate, t.calculation_type AS taxcalculationtype, t.title AS taxtitle, m.title AS manufacturertitle,' . ' AVG(r.rating) AS rating,' . ' at.required AS attribute_required';
$groupsFull = implode(',', $col) . ', c.id, c.title, c.alias, c.title_feed, c.type_feed, ppg.price, pptg.points_received, t.id, t.tax_rate, t.calculation_type, t.title, m.title, r.rating, at.required';
$groupsFast = 'a.id';
}
$groups = PhocacartUtilsSettings::isFullGroupBy() ? $groupsFull : $groupsFast;
$q = ' SELECT ' . $columns;
if ($categoriesList == 1) {
$q .= ', GROUP_CONCAT(c.id) AS categories';
} else {
if ($categoriesList == 2) {
$q .= ', GROUP_CONCAT(c.title SEPARATOR "|") AS categories';
} else {
if ($categoriesList == 3) {
$q .= ', GROUP_CONCAT(c.id, ":", c.alias SEPARATOR "|") AS categories';
} else {
if ($categoriesList == 4) {
$q .= ', GROUP_CONCAT(c.id, ":", c.title SEPARATOR "|") AS categories';
} else {
if ($categoriesList == 5) {
// add to 2 type_category_feed - used in XML FEED
$q .= ', GROUP_CONCAT(c.title SEPARATOR "|") AS categories';
$q .= ', GROUP_CONCAT(c.type_feed SEPARATOR "|") AS feedcategories';
}
}
}
}
}
// Possible DISTINCT
//$q .= ', GROUP_CONCAT(DISTINCT c.id, ":", c.title SEPARATOR "|") AS categories';
$q .= ' FROM #__phocacart_products AS a' . ' LEFT JOIN #__phocacart_product_categories AS pc ON pc.product_id = a.id' . ' LEFT JOIN #__phocacart_categories AS c ON c.id = pc.category_id' . ' LEFT JOIN #__phocacart_taxes AS t ON t.id = a.tax_id' . ' LEFT JOIN #__phocacart_reviews AS r ON a.id = r.product_id AND r.id > 0' . ' LEFT JOIN #__phocacart_manufacturers AS m ON m.id = a.manufacturer_id' . ' LEFT JOIN #__phocacart_attributes AS at ON a.id = at.product_id AND at.id > 0 AND at.required = 1' . ' LEFT JOIN #__phocacart_item_groups AS ga ON a.id = ga.item_id AND ga.type = 3' . ' LEFT JOIN #__phocacart_item_groups AS gc ON c.id = gc.item_id AND gc.type = 2' . ' LEFT JOIN #__phocacart_product_price_groups AS ppg ON a.id = ppg.product_id AND ppg.group_id IN (SELECT group_id FROM #__phocacart_item_groups WHERE item_id = a.id AND group_id IN (' . $userGroups . ') AND type = 3)' . ' LEFT JOIN #__phocacart_product_point_groups AS pptg ON a.id = pptg.product_id AND pptg.group_id IN (SELECT group_id FROM #__phocacart_item_groups WHERE item_id = a.id AND group_id IN (' . $userGroups . ') AND type = 3)';
// Additional Hits
if ($orderingItem == 17 || $orderingItem == 18) {
$q .= ' LEFT JOIN #__phocacart_hits AS ah ON a.id = ah.product_id';
}
$q .= ' WHERE ' . implode(' AND ', $wheres) . ' GROUP BY ' . $groups;
if ($ordering != '') {
$q .= ' ORDER BY ' . $ordering;
}
if ((int) $limitCount > 0) {
$q .= ' LIMIT ' . (int) $limitOffset . ', ' . (int) $limitCount;
}
$db->setQuery($q);
if ($return == 'column') {
$products = $db->loadColumn();
} else {
$products = $db->loadObjectList();
}
return $products;
}