0

i have code that show all category with details but i want to show "include_in_menu" yes or no in output array also .

i am using below code :

$collection = Mage::getModel("catalog/category")->getCollection()->addAttributeToSelect("name")->addAttributeToFilter("is_active", "1")->setLoadProductCount(true)->setProductStoreId($store);

Array output that i get :

"categories": [
    {
        "category_id": "11",
        "parent_id": "3",
        "name": "adbcd",
        "is_active": "1",
        "level": "2",
        "products_count": 0,
        "display_mode": "PRODUCTS",
        "thumbnail_url": null,
        "children": 10
    },
    {
        "category_id": "12",
        "parent_id": "85",
        "name": "abc",
        "is_active": "1",
        "level": "3",
        "products_count": 42,
        "display_mode": "PRODUCTS",
        "thumbnail_url": null,
        "children": 0
    },

i want to add is include_in_menu to array how can it be done

2

Chnage your code as below:

$collection = Mage::getModel("catalog/category")->getCollection()->addAttributeToSelect("*")->addAttributeToFilter("is_active", "1")->setLoadProductCount(true)->setProductStoreId($store);

foreach($collection as $child){
    echo "<pre>";
    print_r($child->getData());
}

Output as below:

Array
(
    [entity_id] => 3
    [entity_type_id] => 3
    [attribute_set_id] => 3
    [parent_id] => 2
    [created_at] => 2016-04-25 09:32:12
    [updated_at] => 2016-04-25 09:32:12
    [path] => 1/2/3
    [position] => 1
    [level] => 2
    [children_count] => 0
    [is_active] => 1
    [name] => test
    [meta_title] => 
    [display_mode] => PRODUCTS
    [custom_design] => 
    [page_layout] => 
    [url_key] => test
    [url_path] => test.html
    [description] => 
    [meta_keywords] => 
    [meta_description] => 
    [custom_layout_update] => 
    [available_sort_by] => 
    [include_in_menu] => 1
    [landing_page] => 
    [is_anchor] => 0
    [custom_use_parent_settings] => 0
    [custom_apply_to_products] => 0
    [custom_design_from] => 
    [custom_design_to] => 
    [filter_price_range] => 
    [product_count] => 1
)
2
  • hey this code just show active menu i want it in array – mdeveloper Apr 29 '16 at 13:02
  • I have updated code as well as output. – Prashant Valanda Apr 29 '16 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.