Tree View

edited December 2010 in News & Announcements
Hello,

I have 3 level ads, like category >> sub-category >> products.

for category tree view is working fine...
for sub-category tree view is also working fine.. It's code like below
foreach($categories as $category) { $cat_id = $category['id']; $return[$cat_id] = array('id' => $cat_id, 'label' => $category['title'], 'parent_id' => 0, 'location' => fuel_url('ads/categories/edit/'.$cat_id)); } foreach($sub_categories as $val) { $attributes = ($val['published'] == 'no') ? array('class' => 'unpublished', 'title' => 'unpublished') : NULL; $return["s_".$val['id']] = array('label' => $val['title'], 'parent_id' => $val['id_ads_categories'], 'location' => fuel_url('ads/subcategories/edit/'.$val['id']), 'attributes' => $attributes); }

for subcategory, I have assign $return["s_".$val['id']] and also removed attribute "id=>$sub_cat_id"

but how to manage in 3rd level?? Here is my code for product Tree view

$CI =& get_instance(); $CI->load->module_model(ADS_FOLDER, 'ads_categories_model'); $CI->load->module_model(ADS_FOLDER, 'ads_subcategories_model'); $CI->load->module_model(ADS_FOLDER, 'ads_products_model'); $CI->load->helper('array'); $return = array(); $categories = $CI->ads_categories_model->find_all(array(), 'title asc'); $sub_categories = $CI->ads_subcategories_model->find_all('', 'title asc'); $products = $CI->ads_products_model->find_all('', 'product_name asc'); // CATEGORY TREE LEVELS // foreach($categories as $category) { $cat_id = $category['id']; $return[$category['id']] = array('id' => $category['id'], 'label' => $category['title'], 'parent_id' => 0, 'location' => fuel_url('ads/categories/edit/'.$category['id'])); } // SUB-CATEGORY TREE LEVELS // foreach($sub_categories as $val) { $attributes = ($val['published'] == 'no') ? array('class' => 'unpublished', 'title' => 'unpublished') : NULL; $return["s_".$val['id']] = array('label' => $val['title'], 'parent_id' => $val['id_ads_categories'], 'location' => fuel_url('ads/subcategories/edit/'.$val['id']), 'attributes' => $attributes); } // PRODUCT TREE LEVELS // foreach($products as $prod) { $attributes = ($prod['published'] == 'no') ? array('class' => 'unpublished', 'product_name' => 'unpublished') : NULL; $return["p_".$prod['id']] = array('label' => $prod['product_name'], 'parent_id' => $prod['id_ads_subcategories'], 'location' => fuel_url('ads/products/edit/'.$prod['id']), 'attributes' => $attributes); }

I want to result like below way..

Vehicle (Root Category)
| Cars (Inside Category)
| | Audi A6 (Inside Sub-Category)

Vehicle --> Category
Cars --> Sub Category
Audi A6 --> Product


But currently I am getting Result like this..

Vehicle
| Cars (Inside Category)
| Audi A6 (Inside Category)

So what change is required?

Comments

  • edited 7:38PM
    I think the issue is that the products parent_id is not a unique value with regards to the menu. Try prepending the "s_" that you have used to identify the sub categories for the parent_id like below:

    foreach($products as $prod) { $attributes = ($prod['published'] == 'no') ? array('class' => 'unpublished', 'product_name' => 'unpublished') : NULL; $return["p_".$prod['id']] = array('id' => "p_".$prod['id'], 'label' => $prod['product_name'], 'parent_id' => "s_".$prod['id_ads_subcategories'], 'location' => fuel_url('ads/products/edit/'.$prod['id']), 'attributes' => $attributes); }
Sign In or Register to comment.