Back to PhocacartProduct class

Method getProductPrice

public static
getProductPrice
(mixed $type = 1, mixed $onlyAvailableProducts = 0, mixed $lang = '', mixed $filterProducts = array())

Method getProductPrice - Source code

public static function getProductPrice($type = 1, $onlyAvailableProducts = 0, $lang = '', $filterProducts = array())
{
    switch ($type) {
        case 2:
            $select = 'MIN(p.price)';
            break;
        case 1:
        default:
            $select = 'MAX(p.price)';
            break;
    }
    $db = Factory::getDBO();
    $wheres = array();
    $lefts = array();
    $wheres[] = ' p.published = 1';
    if ($lang != '' && $lang != '*') {
        $wheres[] = " p.language = " . $db->quote($lang);
    }
    if ($onlyAvailableProducts == 1) {
        $rules = PhocacartProduct::getOnlyAvailableProductRules();
        $wheres = array_merge($wheres, $rules['wheres']);
        $lefts = array_merge($lefts, $rules['lefts']);
    }
    $group = PhocacartUtilsSettings::isFullGroupBy() ? ' GROUP BY p.published' : '';
    if (!empty($filterProducts)) {
        $productIds = implode(',', $filterProducts);
        $wheres[] = 'p.id IN (' . $productIds . ')';
    }
    $q = ' SELECT ' . $select . ' FROM  #__phocacart_products AS p' . (!empty($lefts) ? ' LEFT JOIN ' . implode(' LEFT JOIN ', $lefts) : '') . (!empty($wheres) ? ' WHERE ' . implode(' AND ', $wheres) : '') . $group . ' ORDER BY p.id' . ' LIMIT 1';
    /*	// Don't care about access rights to make the query faster
       $q = 'SELECT '.$select
       . ' FROM #__phocacart_products AS p'
       . ' WHERE p.published = 1'
       . ' ORDER BY p.id'
       . ' LIMIT 1';*/
    $db->setQuery($q);
    $price = $db->loadResult();
    return $price;
}