public function getItemProducts($orderId)
{
$db = Factory::getDBO();
//$query = 'SELECT DISTINCT p.*, pd.download_token, pd.download_file, pd.download_folder, pd.published as download_published, pd.type as download_type'
// .' FROM #__phocacart_orders AS o'
$query = 'SELECT DISTINCT p.*' . ' FROM #__phocacart_orders AS o' . ' LEFT JOIN #__phocacart_order_products AS p ON o.id = p.order_id' . ' LEFT JOIN #__phocacart_products AS pr ON pr.id = p.product_id' . ' WHERE o.id = ' . (int) $orderId . ' ORDER BY p.id';
$db->setQuery($query);
$items = $db->loadObjectList();
// BE AWARE
// Product ID ... is an ID of product
// OrderProduct ID ... is an ID of ordered product
// There is one product ID but more ordered variants of one product
// PRODUCT 1 (Product ID = 1) can have different Attributes when ordered
// PRODUCT 1 with attribute 1 (OrderProduct ID = 1)
// PRODUCT 2 with attribute 2 (OrderProduct ID = 2)
// If you order one product but you will select it with different attributes, you are ordering in fact more products
// derivated frome the one
if (!empty($items)) {
foreach ($items as $k => $v) {
$attributes = $this->getItemAttributes($orderId, $v->id);
if (!empty($attributes)) {
$v->attributes = array();
foreach ($attributes as $k2 => $v2) {
if (isset($v2->id) && $v2->id > 0) {
$v->attributes[$k2] = $v2;
}
}
}
$downloads = $this->getItemDownloads($orderId, $v->id);
if (!empty($downloads)) {
$v->downloads = array();
foreach ($downloads as $k2 => $v2) {
if (isset($v2->id) && $v2->id > 0) {
$v->downloads[$k2] = $v2;
}
}
}
}
}
return $items;
}