public function getItemProductDiscounts($orderId, $onlyPublished = 0)
{
$db = Factory::getDBO();
$q = 'SELECT d.*' . ' FROM #__phocacart_orders AS o' . ' LEFT JOIN #__phocacart_order_product_discounts AS d ON o.id = d.order_id' . ' WHERE o.id = ' . (int) $orderId;
if ($onlyPublished == 1) {
$q .= ' AND d.published = 1';
}
$q .= ' ORDER BY d.id';
$db->setQuery($q);
$items = $db->loadObjectList();
$itemsByKey = array();
if (!empty($items)) {
$oPD = array();
$iS = 4;
// specific ordering - start from 3 because 0 - 2 is taken for reward points, product discounts, cart discounts, coupon
foreach ($items as $k => $v) {
// SPECIFIC CASE - BACKWARD COMPATIBILITY
// Ordering 5 (reward points) -> 2 (product discount) -> 3 (cart discount) -> 4 (coupon)
if ($v->type == 5) {
$kS = 0;
} else {
if ($v->type == 2) {
$kS = 1;
} else {
if ($v->type == 3) {
$kS = 2;
} else {
if ($v->type == 4) {
$kS = 3;
} else {
$kS = $iS;
}
}
}
}
$itemsByKey[$v->product_id_key][$kS] = $v;
$iS++;
}
if (!empty($itemsByKey)) {
foreach ($itemsByKey as $k => $v) {
ksort($itemsByKey[$k]);
}
}
}
return $itemsByKey;
//return $items;
}