Loading


Advertisement:

Author Topic: show category if has item only SOLVED [by Teseo]  (Read 110 times)

sirjones

  • Full Member
  • ***
  • Posts: 102
show category if has item only SOLVED [by Teseo]
« on: March 18, 2017, 01:30:50 pm »
this below code found in this forum (perhaps figured by Teseo)
worked find, but isn't show if has item(s) only,

how to make it only show the caetgory or sub if has item?

Code: [Select]
function cust_categories_select_highlight_root($name = 'sCategory', $category = null, $default_item = null) {
    if($default_item == null) $default_item = __('Select a category');
    $categories = Category::newInstance()->toTree();
    echo '<select name="' . $name . '" id="' . $name . '">';
    echo '<option value="">' . $default_item . '</option>';
    foreach($categories as $c) {

        echo '<option style="background-color: #a06081; color: #ffffff;" value="' . $c['pk_i_id'] . '"' . ( ($category['pk_i_id'] == $c['pk_i_id']) ? 'selected="selected"' : '' ) . '>' . $c['s_name'] . '</option>';

        if(isset($c['categories']) && is_array($c['categories'])) {
            CategoryForm::subcategory_select($c['categories'], $category, $default_item, 1);

        }
    }
    echo '</select>';
}
« Last Edit: March 18, 2017, 04:37:05 pm by sirjones »

teseo

  • Hero Member
  • *****
  • Posts: 5748
Re: show category if has item only
« Reply #1 on: March 18, 2017, 03:32:38 pm »
Hi,

Code: [Select]
function cust_categories_select_highlight_root($name = 'sCategory', $category = null, $default_item = null) {
    if($default_item == null) $default_item = __('Select a category');
    $categories = Category::newInstance()->toTree();
    echo '<select name="' . $name . '" id="' . $name . '">';
    echo '<option value="">' . $default_item . '</option>';
    foreach($categories as $c) {
        if ($c['i_num_items']) {
            echo '<option style="background-color: #a06081; color: #ffffff;" value="' . $c['pk_i_id'] . '"' . (($category['pk_i_id'] == $c['pk_i_id']) ? 'selected="selected"' : '') . '>' . $c['s_name'] . '</option>';
       
            if (isset($c['categories']) && is_array($c['categories'])) {
                foreach ($c['categories'] as $key => $subcat) {
                    if (!$subcat['i_num_items']) {
                        unset ($c['categories'][$key]);
                    }
                }
                CategoryForm::subcategory_select($c['categories'], $category, $default_item, 1);
            }
        }
    }
    echo '</select>';
}

Regards

sirjones

  • Full Member
  • ***
  • Posts: 102
Re: show category if has item only SOLVED [by Teseo]
« Reply #2 on: March 18, 2017, 04:34:48 pm »
You are a rock..
many thanks......