Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Categories XC


Kawazu

Recommended Posts

Hello, I recently downloaded and installed the Categories XC contrib (http://www.oscommerce.com/community/contributions,4234/) and everything seemed to be going quite smoothly; it worked properly, it was simple enough to mod to my liking, it was easy to install, etc., but then I ran into a problem. When I visit the product info page all the categories are expanded and the ability to expand and collapse them is lost. Essentially, the little plus and minus signs that expand and collapse the menus disappear (I'm aware that's it's more complicated than that, but that's the simple way of putting it). I've spent a great deal of time trying to solve this issue and I think I've narrowed it down to a problem with a JavaScript function; however, I know almost no JavaScript (I'm adequate with PHP... not so much with JavaScript). Internet Explorer says it has something to do with document.getElementById being either null or not an object. I will post the code for the only two files included with the package. Any help anyone can offer is greatly appreciated, and I thank you very much in advance.

 

-Ian

 

categories-xc.php

<script language="JavaScript" type="text/javascript" src="includes/xc.js"></script>
<?php
/*
 $Id: categories-xc.php, v 1.0 2006/05/08

 Released under the GNU General Public License

 OSC Implementation - Copyright (c) 2006 Grant Perry
 http://www.grantusmaximus.com

 Javascript XC Menu - Copyright (c) 2003 Ben Boyle
 http://inspire.server101.com/js/xc/
*/

// Categories_tree written by Gideon Romm from Symbio Technologies, LLC

function tep_show_categoryxc($cid, $cpath, $display_empty) {
 global $categoriesxc_string, $languages_id, $HTTP_GET_VARS;
 global $level;
 $selectedPath = array();

// Get all of the categories on this level


 $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = " . $cid . " and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

 while ($categories = tep_db_fetch_array($categories_query))  {
if ($level{$categories['parent_id']} == "") { $level{$categories['parent_id']} = 0; }
$level{$categories['categories_id']} = $level{$categories['parent_id']} + 1;

// Add category link to $categoriesxc_string
$products_in_category = tep_count_products_in_category($categories['categories_id']);
if ($display_empty == 0 && $products_in_category < 1) {
	$display_category = false;
} else {
	$display_category = true;
}


if ($display_category == true) {

	if ($display_category == true) {

if ($level{$categories['parent_id']} == 0) {
$categoriesxc_string .= "<hr><li><a href=";
} else 
{
$categoriesxc_string .= "<li><a href=";
}
}
	$cPath_new = $cpath;
	if ($level{$categories['parent_id']} > 0) {
	  $cPath_new .= "_";
	}
	$cPath_new .= $categories['categories_id'];

	$cPath_new_text = "cPath=" . $cPath_new;

	$categoriesxc_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new_text);
	$categoriesxc_string .= '" title="'.$categories['categories_name'].'">';

	if ($HTTP_GET_VARS['cPath']) {
	  $selectedPath = split("_", $HTTP_GET_VARS['cPath']);
	}

	//if (in_array($categories['categories_id'], $selectedPath)) { $categoriesxc_string .= '<strong>'; }

	$categoriesxc_string .= $categories['categories_name'];

	//if (in_array($categories['categories_id'], $selectedPath)) { $categoriesxc_string .= '</strong>'; }

	$categoriesxc_string .= '</a>';

	if (SHOW_COUNTS) {
	  if ($products_in_category > 0) {
		$categoriesxc_string .= ' (' . $products_in_category . ')';
	  }
	}

	// If I have subcategories, get them and show them
	if (tep_has_category_subcategories($categories['categories_id'])) {
		$categoriesxc_string .= "<ul id=\"catid".$categories['categories_id']."\" title=\"".$categories['categories_name']."\">\n";
		tep_show_categoryxc($categories['categories_id'], $cPath_new, $display_empty);
		$categoriesxc_string .= "</ul>\n";
	}
   $categoriesxc_string .= "</li>\n";
}	
 }
}
?>


<!--categories XC //-->
	  <tr>
		<td>
<?php
 $info_box_contents = array();
 $info_box_contents[] = array( 'align' => 'left',
							  'text'  => '<span style="color:' . $font_color . ';">' . BOX_HEADING_CATEGORIES . '</span>'
						  );
 new infoBoxHeading($info_box_contents, false, false);

 $categoriesxc_string = '';
 $categoriesxc_string .= "<script type=\"text/javascript\" src=\"/includes/xc.js\"></script>\n";
 $categoriesxc_string .= "<div id=\"catxcdiv\">\n";
 $categoriesxc_string .= "<ul id=\"catxc\">\n";

 // tep_show_categoryxc(<top category_id>, <top cpath>, <1=Show empty Categories, 0=Hide empty Categories>)
 tep_show_categoryxc(0,'',0);

 $categoriesxc_string .= "</ul>\n";
 $categoriesxc_string .= "<script type=\"text/javascript\">\n<!--\n";
 $categoriesxc_string .= "window.onload = function() {xcSet('catxc', 'xc', '";

 // Checks Category path and opens menu when there are child categories
 if ($HTTP_GET_VARS['cPath']) {
  $selectedPath = split("_", $HTTP_GET_VARS['cPath']);
  if (count($selectedPath) > 1) {
	  if (tep_has_category_subcategories($selectedPath[count($selectedPath)-2])) {
		$categoriesxc_string .= "catid".$selectedPath[count($selectedPath)-2];
	};		
  } elseif (count($selectedPath) == 1) {
	  if (tep_has_category_subcategories($selectedPath[0])) {
		$categoriesxc_string .= "catid".$selectedPath[0];
	};
  };
};
 $categoriesxc_string .= "');};\n";
 $categoriesxc_string .= "//-->\n</script>\n";
 $categoriesxc_string .= "</div>\n";



 $info_box_contents = array();
 $info_box_contents[] = array('text'  => $categoriesxc_string);
 new infoBox($info_box_contents);
?>
		</td>
	  </tr>
<!--categories_eof XC //-->

 

xc.js

/*
* date:	2003-01-23
* info:	http://inspire.server101.com/js/xc/
*/

var xcNode = [];

function xcSet(m, c) {
if (document.getElementById && document.createElement) {
m = document.getElementById(m).getElementsByTagName('ul');
var d, p, x, h, i, j;
for (i = 0; i < m.length; i++) {
	if (d = m[i].getAttribute('id')) {
		xcCtrl(d, c, 'x', '[+]', 'Show', m[i].getAttribute('title')+' (expand menu)');
		x = xcCtrl(d, c, 'c', '[-]', 'Hide', m[i].getAttribute('title')+' (collapse menu)');

		p = m[i].parentNode;
		if (h = !p.className) {
			j = 2;
			while ((h = !(d == arguments[j])) && (j++ < arguments.length));
			if (h) {
				m[i].style.display = 'none';
				x = xcNode[d+'x'];
			}
		}

		p.className = c;
		p.insertBefore(x, p.firstChild);
	}
}
}}


function xcShow(m) {
xcXC(m, 'block', m+'c', m+'x');
}


function xcHide(m) {
xcXC(m, 'none', m+'x', m+'c');
}


function xcXC(e, d, s, h) {
e = document.getElementById(e);
e.style.display = d;
e.parentNode.replaceChild(xcNode[s], xcNode[h]);
xcNode[s].firstChild.focus();
}


function xcCtrl(m, c, s, v, f, t) {
var a = document.createElement('a');
a.setAttribute('href', 'java script:xc'+f+'(\''+m+'\');');
a.setAttribute('title', t);
a.appendChild(document.createTextNode(v));

var d = document.createElement('div');
d.className = c+s;
d.appendChild(a);

return xcNode[m+s] = d;
}

Ian Osos

Web Developer

Link to comment
Share on other sites

  • 3 weeks later...

Yeah... bumping again because I still have no idea... although I've kind of left it on the back burner while I worked on other stuff... <__< Anyways, *bump* please help!

Ian Osos

Web Developer

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...