public static function getCouponProductsById($couponId, $select = 0)
{
$db = Factory::getDBO();
if ($select == 1) {
$query = 'SELECT co.coupon_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_coupon_products AS co ON a.id = co.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 co.coupon_id = ' . (int) $couponId;
if ($select == 1) {
$query .= ' GROUP BY co.coupon_id';
} else {
$query .= ' GROUP BY co.coupon_id, a.id, a.title';
}
$db->setQuery($query);
if ($select == 1) {
$coupon = $db->loadColumn();
} else {
$coupon = $db->loadObjectList();
}
return $coupon;
}