VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: studioblue on June 14, 2013, 22:22:43 PM

Title: [Solved] Can the Category List in admin-product info SHOW category ID and Name?
Post by: studioblue on June 14, 2013, 22:22:43 PM
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,

Title: Re: Can the Category List in admin-product info SHOW category ID and Name?
Post by: studioblue on June 14, 2013, 23:03:57 PM
I have too many like categories and with 3000 cats it can be confusing!!
Title: Re: Can the Category List in admin-product info SHOW category ID and Name?
Post by: studioblue on June 14, 2013, 23:42:00 PM
How do you get the category_id into the category tree that shows in the backend for product information area?



[attachment cleanup by admin]
Title: Re: Can the Category List in admin-product info SHOW category ID and Name?
Post by: PRO on June 15, 2013, 02:17:58 AM
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.

Title: Re: Can the Category List in admin-product info SHOW category ID and Name?
Post by: studioblue on June 15, 2013, 16:16:36 PM
Thanks for the reply.

You would think that this would be a simple db call but I am not sure how to write it.
Title: Re: Can the Category List in admin-product info SHOW category ID and Name?
Post by: studioblue on June 15, 2013, 16:55:56 PM
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]
Title: Re: Can the Category List in admin-product info SHOW category ID and Name?
Post by: PRO on June 15, 2013, 18:01:20 PM
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;
   }
Title: Re: Can the Category List in admin-product info SHOW category ID and Name?
Post by: studioblue on June 15, 2013, 18:57:53 PM
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!