/*
* Administration
*/
public static function getDiscountsById($productId, $return = 0)
{
$db = Factory::getDBO();
$query = 'SELECT a.id, a.title, a.alias, a.discount, a.access, a.discount, a.calculation_type, a.quantity_from, a.valid_from, a.valid_to, a.description, a.background_image' . ' FROM #__phocacart_product_discounts AS a' . ' WHERE a.product_id = ' . (int) $productId . ' ORDER BY a.ordering';
$db->setQuery($query);
if ($return == 0) {
return $db->loadObjectList();
} else {
if ($return == 1) {
return $db->loadAssocList();
} else {
$discounts = $db->loadAssocList();
$discountsSubform = array();
$i = 0;
if (!empty($discounts)) {
foreach ($discounts as $k => $v) {
$discountsSubform['discounts' . $i]['id'] = (int) $v['id'];
$discountsSubform['discounts' . $i]['title'] = (string) $v['title'];
$discountsSubform['discounts' . $i]['alias'] = (string) $v['alias'];
$discountsSubform['discounts' . $i]['access'] = (int) $v['access'];
$discountsSubform['discounts' . $i]['discount'] = (string) $v['discount'];
$discountsSubform['discounts' . $i]['calculation_type'] = (int) $v['calculation_type'];
$discountsSubform['discounts' . $i]['quantity_from'] = (int) $v['quantity_from'];
//$discountsSubform['discounts' . $i]['quantity_to'] = (int)$v['quantity_to'];
$discountsSubform['discounts' . $i]['valid_from'] = $v['valid_from'];
$discountsSubform['discounts' . $i]['valid_to'] = $v['valid_to'];
$discountsSubform['discounts' . $i]['description'] = $v['description'];
$discountsSubform['discounts' . $i]['background_image'] = $v['background_image'];
if ((int) $v['id'] > 0) {
$discountsSubform['discounts' . $i]['groups'] = PhocacartGroup::getGroupsById((int) $v['id'], 4, 1);
}
if (empty($discountsSubform['discounts' . $i]['groups'])) {
$discountsSubform['discounts' . $i]['groups'] = PhocacartGroup::getDefaultGroup(1);
}
$i++;
}
}
return $discountsSubform;
}
}
return false;
}