News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

how to get the Category Tree dropdown

Started by iwanna, October 06, 2014, 01:28:03 AM

Previous topic - Next topic

iwanna

Hello,

I'm trying to upgrade a component that worked in VM1 and I need to get the Virtuemart Category Tree as seen as the attachment image..

my code is:
<LEGEND align=center><?php echo "Select Category";?></LEGEND>
<table width="260" cellpadding="4" cellspacing="4" border="0">
<tr>
<td nowrap><?php echo "Category"?> : </td>
<td><?php echo getCategorySelect($categoryid);?></td>
</tr>
<tr>
<td nowrap><?php echo "Manufacturer";?> : </td>
<td><?php echo getManufacturerSelect($manufacturerid);?></td>
</tr>
</table>
</FIELDSET>


so I have created this function inside file "helper.php"


defined( '_JEXEC' ) or die( 'Restricted access' );

if (!class_exists( 'VirtueMartModelCategory' )) require (JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart'.DS.'models'.DS. 'category.php');
if(!class_exists('VmModel'))require(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'vmmodel.php');

$VirtueMartModelCategory = new VirtueMartModelCategory;

function getCategorySelect($selected = -1) {

        $categories = VirtueMartModelCategory::getCategoryTreeArray(false, $keyword );
        $result = VirtueMartModelCategory::sortCategoryTreeArray( $categories );

        $nrows = $size = sizeOf($categories);

$row_list = $result['row_list'];
$depth_list = $result['depth_list'];
$categories = $result['category_tmp'];

$categorySelect = '<select name="Category" id="Category" class="txtmonospace" style="max-width:250px;">';
$categorySelect .= '<option value="0">Select Category'</option>';

for($n=0; $n < $nrows ; $n++) {
if( !isset($row_list[$n])) $row_list[$n] = $n;
if( !isset($depth_list[$n])) $depth_list[$n] = 0;

$catid = $categories[$row_list[$n]]["category_child_id"];
$repeat = $depth_list[$n]+1; // Which category depth level we are in?
$cat_name = shopMakeHtmlSafe( $categories[$row_list[$n]]["category_name"] );
$cat_name = (($repeat!=1) ? str_repeat("&nbsp;&nbsp;", $repeat-2 )."&nbsp;&nbsp;" : "") . '|'. $repeat ."| " . $cat_name;
$product_count = $category->countProducts($catid);
//$category_publish = vmCommonHTML::getYesNoIcon ( $categories[$row_list[$n]]["category_publish"] );

$categorySelect .= '<option value="'.$catid.'" '.(($catid==$selected)?" selected":"").'>'.$cat_name.' ('.$countProducts.')</option>';
}
$categorySelect .= '</select>';

return $categorySelect;
}


but I get as an error:
Quote0 - An error has occurred.
The table categories is not supported. File not found.

Can somebody help me ?

[attachment cleanup by admin]