Author Topic: help me , this script doesnt count the total of product on their lv3 subcategory  (Read 804 times)

bonbin

  • Beginner
  • *
  • Posts: 25
dear,

can someone help me to find out how to makes this module count the total of product from all of their subcategory, or at least makes it count till lv4/lv5

i know this module are not from virtuemart, im using this some premium template
but since my member is expired, they are rejecting to tell me the way for fixing this problem :(
im not gonna subscribing their template again.

i really need some  help from someone who are understand about coding

and here is the code
Code: [Select]
class modTPIndexHelper{

function getList(&$params){
global $mainframe;

$img = ($params->get('modtype') == 0)  ? "category_full_image" : "category_thumb_image";
$db =& JFactory::getDBO();
$query = "SELECT b.category_name, b.category_description, b.category_id, b." . $img . " FROM #__vm_category_xref AS a, #__vm_category AS b WHERE a.category_parent_id = 0 AND a.category_child_id = b.category_id AND b.category_publish = 'Y' ORDER BY b.list_order ASC";
$db->setQuery($query);
$rows = $db->loadObjectList();

$i = 0;
$lists = array();
foreach($rows as $row){
$lists[$i]->name = $row->category_name;
$lists[$i]->desc = $row->category_description;
$lists[$i]->id = $row->category_id;
$lists[$i]->filename= $row->$img;
$i++;
}

return $lists;
}

function getListChild($params, $param){
global $mainframe;

$img = ($params->get('modtype') == 0)  ? "category_full_image" : "category_thumb_image";
$db =& JFactory::getDBO();
$query = "SELECT b.category_name, b.category_id, b." . $img . " FROM #__vm_category_xref AS a, #__vm_category AS b WHERE a.category_parent_id = $param AND a.category_child_id = b.category_id AND b.category_publish = 'Y' ORDER BY b.list_order ASC";
$db->setQuery($query);
$rows = $db->loadObjectList();

$i = 0;
$lists = array();
foreach($rows as $row){
$query = "SELECT COUNT(*) AS total FROM #__vm_product_category_xref WHERE category_id=" . $row->category_id;
$db->setQuery($query);
$lists[$i]->name = $row->category_name;
$lists[$i]->id = $row->category_id;
$lists[$i]->filename= $row->$img;
$lists[$i]->total = $db->loadResult();
$i++;
}

return $lists;
}
}

thx so much for future assistance


bonbin

  • Beginner
  • *
  • Posts: 25
i found the solution already for this problem

change the code from line 31 with this

Code: [Select]
function getListChild($params, $param){
global $mainframe;

$img = ($params->get('modtype') == 0)  ? "category_full_image" : "category_thumb_image";
$db =& JFactory::getDBO();
$query = "SELECT b.category_name, b.category_id, b." . $img . " FROM #__vm_category_xref AS a, #__vm_category AS b WHERE a.category_parent_id = $param AND a.category_child_id = b.category_id AND b.category_publish = 'Y' ORDER BY b.list_order ASC";
$db->setQuery($query);
$rows = $db->loadObjectList();

$i = 0;
$lists = array();
foreach($rows as $row){
$query = "SELECT COUNT(*) AS total FROM #__vm_product_category_xref WHERE category_id=" . $row->category_id;
$db->setQuery($query);
$lists[$i]->name = $row->category_name;
$lists[$i]->id = $row->category_id;
$lists[$i]->filename= $row->$img;
$lists[$i]->total = $db->loadResult();


$query1 = "SELECT COUNT(*) AS total FROM #__vm_product_category_xref WHERE category_id in ( SELECT category_child_id FROM #__vm_category_xref  WHERE category_parent_id = " . $row->category_id . ")" ;
$db->setQuery($query1);
$lists[$i]->total += $db->loadResult();

$i++;
}

return $lists;
}
}