Zen Cart Logo
Forums / All Other Contributions/Addons / Can I disable 'javascript:void' in categories to preserve category click?

Can I disable 'javascript:void' in categories to preserve category click?

Views: 979

Results 1 to 6 of 6
18 Jun 2012, 8:59 PM
#1
ouroboros avatar

ouroboros

New Zenner

Join Date:
Jun 2012
Posts:
8
Plugin Contributions:
0

Can I disable 'javascript:void' in categories to preserve category click?

Hey there,

I would like to preserve in my sidebar navigation the ability to click at anytime the subcategory to be able to go back to the product array (i.e. the page with all the products photos in their respective sub-category). Right now when a customer is in a product detail page, the sidebar navigation link to go back is turned off with a "javascript:void(0)"

Since I'm not very good with php, how would I change the line of code in the "categories_ul_generator.php" file so it doesn't create a null link? Thanks for any help!

  function buildBranch($parent_id, $level = 0, $cpath = '') {
    global $cPath;
    $result = "\n".sprintf($this->parent_group_start_string, str_repeat(' ', $level*4))."\n";
    if (isset($this->data[$parent_id])) {
      foreach ($this->data[$parent_id] as $category_id => $category) {
        $result .= sprintf($this->child_start_string, str_repeat(' ', $level*4+2));
        if (isset($this->data[$category_id])) {
          $result .= $this->parent_start_string;
        }
        if ($level == 0) {
          $result .= $this->root_start_string;
          $new_cpath  = $category_id;
        } else {
          $new_cpath = $cpath."_".$category_id;
        }
        if ($cPath == $new_cpath) {
          $result .= '<a href="javascript:void(0)" class="on">'; // highlight current category & disable link
        } else {
          $result .= '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . $new_cpath) . '">';
        }
        $result .= $category['name'];
        if (SHOW_COUNTS == 'true' && ((CATEGORIES_COUNT_ZERO == '1' && $category['count'] == 0) || $category['count'] >= 1)) {
          $result .= CATEGORIES_COUNT_PREFIX . $category['count'] . CATEGORIES_COUNT_SUFFIX;
        }
        $result .= '</a>';
        if ($level == 0) {
          $result .= $this->root_end_string;
        }
        if (isset($this->data[$category_id])) {
          $result .= $this->parent_end_string;
        }
        if (isset($this->data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
          $result .= $this->buildBranch($category_id, $level+1, $new_cpath);
          $result .= sprintf($this->child_end_string, str_repeat(' ', $level*4+2))."\n";
        } else {
          $result .= sprintf($this->child_end_string, '')."\n";
        }
      }
    }
    $result .= sprintf($this->parent_group_end_string, str_repeat(' ', $level*4))."\n";
    return $result;
  }
19 Jun 2012, 2:19 AM
#2
ouroboros avatar

ouroboros

New Zenner

Join Date:
Jun 2012
Posts:
8
Plugin Contributions:
0

Re: Can I disable 'javascript:void' in categories to preserve category click?

I tried just replacing this line:

          $result .= '<a href="javascript:void(0)" class="on">'; // highlight current category & disable link

with the next line:

         $result .= '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . $new_cpath) . '">';

But this only works for one page, and then it starts spewing code! Any ideas? I don't think I can just remove that portion because it is actually building a link...

19 Jun 2012, 7:59 PM
#3
ouroboros avatar

ouroboros

New Zenner

Join Date:
Jun 2012
Posts:
8
Plugin Contributions:
0

Re: Can I disable 'javascript:void' in categories to preserve category click?

Nobody has had to do this before?

19 Jun 2012, 11:24 PM
#4
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Can I disable 'javascript:void' in categories to preserve category click?

This is not part of core Zen Cart, so you will need to identify exactly where you got the code/mod and probably let us see it live if we are to advise on how best to change it.

19 Jun 2012, 11:32 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Can I disable 'javascript:void' in categories to preserve category click?

My first guess at what may work would be essentially as you said you did, but preserving the class so the current category remains highlighted:

        if ($cPath == $new_cpath) {
          $result .= '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . $new_cpath) . '" class="on">'; // highlight current category 
        } else {
          $result .= '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . $new_cpath) . '">';
        }
20 Jun 2012, 12:06 AM
#6
ouroboros avatar

ouroboros

New Zenner

Join Date:
Jun 2012
Posts:
8
Plugin Contributions:
0

Re: Can I disable 'javascript:void' in categories to preserve category click?

Yessir that worked. I did add the class before, but I have a feeling I didn't follow the correct php procedure for including the class correctly! Thank you so much for you help!