Author Topic: [Solved] Can the Category List in admin-product info SHOW category ID and Name?  (Read 1957 times)

studioblue

  • Beginner
  • *
  • Posts: 26
VM 2.012b
Joomla 2.5

I was wondering if, in the product information Tab where you select a category, can it also show the category id.  Just not great at php so I am not sure how to get the category-id to show after the category name.
I see in the code where the category_tree is being called but I am not sure if the id is available.?


Thanks,


studioblue

  • Beginner
  • *
  • Posts: 26
I have too many like categories and with 3000 cats it can be confusing!!

studioblue

  • Beginner
  • *
  • Posts: 26
How do you get the category_id into the category tree that shows in the backend for product information area?



[attachment cleanup by admin]

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10431
  • VirtueMart Version: 3+
I have tried this, and can get numbers to display, but its not the category id.

It's 0, when its the parent category,

then, the child categories show the parent category id beside them.


studioblue

  • Beginner
  • *
  • Posts: 26
Thanks for the reply.

You would think that this would be a simple db call but I am not sure how to write it.

studioblue

  • Beginner
  • *
  • Posts: 26
I see the category_id in the option values.  You can view them in the attached image of the options for the input select.

[attachment cleanup by admin]

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10431
  • VirtueMart Version: 3+
the only code I see in the category tree is for child categories

static public function categoryListTreeLoop ($selectedCategories = array(), $cid = 0, $level = 0, $disabledFields = array()) {

      self::$counter++;

      static $categoryTree = '';

      $virtuemart_vendor_id = 1;

//       vmSetStartTime('getCategories');
      $categoryModel = VmModel::getModel ('category');
      $level++;

      $categoryModel->_noLimit = TRUE;
      $app = JFactory::getApplication ();
      $records = $categoryModel->getCategories ($app->isSite (), $cid);
//       vmTime('getCategories','getCategories');
      $selected = "";
      if (!empty($records)) {
         foreach ($records as $key => $category) {

            $childId = $category->category_child_id;

            if ($childId != $cid) {
               if (in_array ($childId, $selectedCategories)) {
                  $selected = 'selected=\"selected\"';
               } else {
                  $selected = '';
               }

               $disabled = '';
               if (in_array ($childId, $disabledFields)) {
                  $disabled = 'disabled="disabled"';
               }

               if ($disabled != '' && stristr ($_SERVER['HTTP_USER_AGENT'], 'msie')) {
                  //IE7 suffers from a bug, which makes disabled option fields selectable
               } else {
                  $categoryTree .= '<option ' . $selected . ' ' . $disabled . ' value="' . $childId . '">';
                  $categoryTree .= str_repeat (' - ', ($level - 1));
                  $categoryTree .= $category->category_name. '</option>';
               }
            }

            if ($categoryModel->hasChildren ($childId)) {
               self::categoryListTreeLoop ($selectedCategories, $childId, $level, $disabledFields);
            }

         }
      }

      return $categoryTree;
   }

studioblue

  • Beginner
  • *
  • Posts: 26
Thanks for your help, PRO.  Here is the solution.

in administrator/components/com_virtuemart/helpers/shopfunctions.php

Where your code above says:

} else {

                  $categoryTree .= '<option ' . $selected . ' ' . $disabled . ' value="' . $childId . '">';

                  $categoryTree .= str_repeat (' - ', ($level - 1));



                  $categoryTree .= $category->category_name . '</option>';

               }

REPLACE WITH

} else {

                  $categoryTree .= '<option ' . $selected . ' ' . $disabled . ' value="' . $childId . '">';

                  $categoryTree .= str_repeat (' - ', ($level - 1));



                  $categoryTree .= $category->category_name . "-" . $childId .'</option>';

               }

works like a charm!