Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Populate an array of categories and childcategories for use in javascript
 
sharmstr
Member
 
Total Posts:  61
Joined:  2009-03-15
 

This should be fairly simple, but since I dont know php that well, its taking forever to figure this out.

Anyhow, basically I have some javascript code that creates dependent selects. (Make, Model, Year).  I need to pass it an array of category and child category names from a specific parent category (which is category id 3).

I figured out how to loop through all the child categories and can get them to print out, just dont know how to build the array and pass it to the javascript code.

My categories are structured like

American Motors
-AMX
-1961
-1962
-1963
-1964
-Classic
-1962
-1963
Toyota
-Prius
-2005
-2006

and so on…

The javascript array will basically look like this in the end:

var carMakers = [
{ name: ‘American Motors’, models: [
{ name: ‘AMX’, years: [’1961’, ‘1962’, ‘1963’, ‘1964’] },
{ name: ‘Classic’, years: [’1962’, ‘1963’] }
]},
{ name: ‘Toyota’, models: [
{ name: ‘Prius’, years: [’2005’, ‘2006’] },
{ name: ‘Camry’, years: [’2005’, ‘2006’] },
{ name: ‘Corolla’, years: [’1995’, ‘1996’] }
]}
];

Any help is greatly appreciated.

shawn

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top