Back to PhocacartDiscountCart class

Method getDiscountProductsById

public static
getDiscountProductsById
(mixed $discounId, mixed $select = 0)

Method getDiscountProductsById - Source code

public static function getDiscountProductsById($discounId, $select = 0)
{
    $db = Factory::getDBO();
    if ($select == 1) {
        $query = 'SELECT di.discount_id';
    } else {
        $query = 'SELECT a.id as id, a.title as title, group_concat(c.title SEPARATOR \' \') AS categories_title';
    }
    $query .= ' FROM #__phocacart_products AS a' . ' LEFT JOIN #__phocacart_discount_products AS di ON a.id = di.product_id' . ' 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' . ' WHERE di.discount_id = ' . (int) $discounId;
    if ($select == 1) {
        $query .= ' GROUP BY di.discount_id';
    } else {
        $query .= ' GROUP BY di.discount_id, a.id, a.title';
    }
    $db->setQuery($query);
    if ($select == 1) {
        $coupon = $db->loadColumn();
    } else {
        $coupon = $db->loadObjectList();
    }
    return $coupon;
}