Jump to content

[Smarty, PHP, FrontController] - Generate Dropdown with subcategories from category id selected


Recommended Posts

Hi guys,

 

I'm trying to generate a front controller which will work like that :

 

First of all you have a dropdown with main categories (which in this case is the brand of your car)

It's set like that :

<option value=categoryID> categoryName (the car brand)</option>

Thanks to this in the tpl :

<select name="brand" id="brand-select">
    <option value="">{l s="Choose the brand of your car"}</option>
    {foreach from=$subCategories item=subCategory}
    {html_options output=$subCategory.name values=$subCategory.id_category}
    {/foreach}
</select>

and this in the front controller :

    $categories =   Category::getCategories();
    foreach ($categories as $categoryInfos) {
      foreach ($categoryInfos as $categoryInfo) {
        if($categoryInfo['infos']['name'] == 'Marques'){
          $brandCat = new Category($categoryInfo['infos']['id_category']);
        }
      }
    }
    $brandSubCats = $brandCat->getSubCategories(Configuration::get('PS_LANG_DEFAULT'));
    $this->context->smarty->assign('subCategories', $brandSubCats);

What I need now, is to take the value of brand-select and call the subcategories of the selected category, to generate another dropdown, which will depend of the category/brand selected in brand-select.

 

I just don't know how can I take the value generate with my html options, in smarty (in js I know how to but I can't use it in smarty).

 

Does somebody have an idea ? Maybe I'm not going in the good direction

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...