This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

amraneo

  • ***
  • 31 posts
[HELP] Keep Selected category in dropdown search !!
« on: July 19, 2017, 09:22:11 PM »
Hi,

I'm facing a problem, when I select a category it shows items for this category but in the dropdown it doesn't keep selected category and shows "All categories" instead of selected one.

Please help me to solve this problem so the selected category still shown after selecting.

My function is :

Code: [Select]
<?php
function dropdown_category( ) {
  
$categories Category::newInstance()->toTree();
  
$html  '<select class="sCategory" id="sCategory" name="sCategory">';
  
$html .= '<option value="" >' __('All categories''veronika') . '</option>';
  foreach(
$categories as $c) {
  $sscategories Category::newInstance()->findSubcategoriesEnabled$c['pk_i_id'] );
          
$html .= '<option class = "bldd" ' . ($c['s_name'] == Params::getParam('sCategory') ? ' selected="selected"' '') . ' value="' $c['pk_i_id'] . '">---' $c['s_name'] . '---</option>';
  foreach( $sscategories as $ss ) {
$html .= '<option ' . ($ss['s_name'] == Params::getParam('sCategory') ? ' selected="selected"' '') . ' value="' $ss['pk_i_id'] . '">' $ss['s_name'] . '</option>';
  }
    }
  
$html .= '</select>';
  return 
$html;
}
?>

« Last Edit: July 19, 2017, 09:23:50 PM by amraneo »

*

MB Themes

Re: [HELP] Keep Selected category in dropdown search !!
« Reply #1 on: July 19, 2017, 11:01:02 PM »
@amraneo
Make sure Params::getParam('sCategory') has some values, you are using it in comparison to identify selected category.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

amraneo

  • ***
  • 31 posts
Re: [HELP] Keep Selected category in dropdown search !!
« Reply #2 on: July 20, 2017, 01:08:27 PM »
@frosticek

I'm newbie so if you can please correct my function to have the selected category displayed in the box.

Thnak you.

Marked as best answer by amraneo on July 25, 2017, 01:18:40 PM
*

MB Themes

Re: [HELP] Keep Selected category in dropdown search !!
« Reply #3 on: July 22, 2017, 08:57:58 AM »
@amraneo
It's not possible, I do not know how or where you place it.
Work with this condition:
Code: [Select]
$c['s_name'] == Params::getParam('sCategory')
I would say it should be at least:
Code: [Select]
$c['pk_i_id'] == Params::getParam('sCategory')
if you do it on search page, you should use search id:
// define somewhere
Code: [Select]
$cat = osc_search_category_id();
$cat_id = $cat[0];

// update condition
Code: [Select]
$c['pk_i_id'] == $cat_id
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots