This said, I try to create a module to extract Joomshopping product names and quantities per month.
My SQL query is ok and data can be correctly displayed when I test data within my helper file.
However, if I try to "conventionnally" pass data to a default.php template file, nothing is displayed, meaning probably that I return data in a wrong way.
Here's my module entry point:
Here's my helper file:<?php
// No direct access defined('_JEXEC') or die;
// Include the syndicate functions only once
require_once dirname(__FILE__) . '/helper.php';
// I know I should not use this but I tried anyway :-)
global $prod;
$prod = modProduitsHelper::getProduits($params);
require JModuleHelper::getLayoutPath('mod_produits');
?>
And here's, for now, how my default.php "template file" looks like:<?php
/**
* Helper class for module stats
*/
class modProduitsHelper
{
/**
*
* @param array $params An object containing the module parameters
*
* @access public
*/
public static function getProduits($params)
{
$user = JFactory::getUser();
$userId = (int) $user->get('id');
// Obtain a database connection
$db = JFactory::getDbo();
$query="SELECT
product_name as nom,
sum(if(month(order_date) = 1, product_quantity, 0)) as Jan,
sum(if(month(order_date) = 2, product_quantity, 0)) as Feb,
sum(if(month(order_date) = 3, product_quantity, 0)) as Mar,
sum(if(month(order_date) = 4, product_quantity, 0)) as Apr,
sum(if(month(order_date) = 5, product_quantity, 0)) as May,
sum(if(month(order_date) = 6, product_quantity, 0)) as Jun,
sum(if(month(order_date) = 7, product_quantity, 0)) as Jul,
sum(if(month(order_date) = 8, product_quantity, 0)) as Aug,
sum(if(month(order_date) = 9, product_quantity, 0)) as Sep,
sum(if(month(order_date) = 10, product_quantity, 0)) as Oct,
sum(if(month(order_date) = 11, product_quantity, 0)) as Nov,
sum(if(month(order_date) = 12, product_quantity, 0)) as `Dec`
FROM vpkbb_jshopping_order_item join vpkbb_jshopping_orders on vpkbb_jshopping_orders.order_id=vpkbb_jshopping_order_item.order_id
WHERE user_id = 398
AND year(order_date) = 2022
group by product_name
order by product_name;";
// Prepare the query
$db->setQuery($query);
// Chargement des produits.
$prod = $db->loadObjectList();
return ($prod);
}
}
?>
It looks to me like I was doing ok but I'm wrong, so if anybody could help me out on this I'd appreciate it.<?php
// No direct access
defined('_JEXEC') or die;
foreach ($prod as $pr)
echo $pr->nom . ' ' . $pr->Jan . ' ' . $pr->Feb . ' ' . $pr->Mar . ' ' . $pr->Apr . ' ' . $pr->May . ' ' . $pr->Jun . ' ' . $pr->Jul . ' ' . $pr->Aug . ' ' . $pr->Sep . ' ' . $pr->Oct . ' ' . $pr->Nov . ' ' . $pr->Dec . '<br />';
?>
It's probably a trivial issue but I just don't see it.
Thanks
Philippe