Advertisement:

Author Topic: Help to make a range slider or a dropdown list in sidebar search for car mileage  (Read 845 times)

ad.min

  • Newbie
  • *
  • Posts: 25
Hello I really need help to make a range slider or a drop down list in the sidebar search so the users could perform a search by car mileage. Thanks in advance !

ad.min

  • Newbie
  • *
  • Posts: 25
For range slider i need to retrieve the maximum mileage value and set it as maximum value of slider and dynamically display the ads for cars wich has mileage value within the range as the range min and max values are modified  without pressing the search button (same way like in price slider) . This would be used for car attributes plugin. Any ideas how this could be done or links where with similar script? Thanks

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
You could make an additional field as dropdown, with the values:
For ex
0-10000,10001-15000,15001-20000 etc.
« Last Edit: March 26, 2018, 07:29:42 pm by marius-ciclistu »

ad.min

  • Newbie
  • *
  • Posts: 25
Thanks . I tried this

I tried this in search-form.php

Quote

      <div class="row one_input">
        <h6><?php _e('Mileage', 'cars_attributes'); ?></h6>
   
      <select name="min_mileage" id="min_mileage">
            <?php $min_mileage = Params::getParam('min_mileage') ; ?>
            <option value=""><?php _e('min', 'cars_attributes');?></option>
            <option value="0"><?php $min_mileage = 0; ?><?php _e('0 km', 'cars_attributes');?></option>
            <option value="50000"><?php $min_mileage = 50000; ?><?php _e('50.000 km', 'cars_attributes');?></option>
            <option value="100000"><?php $min_mileage = 100000; ?><?php _e('100.000 km', 'cars_attributes');?></option>
            <option value="150000"><?php $min_mileage = 150000; ?><?php _e('150.000 km', 'cars_attributes');?></option>
            <option value="200000"><?php $min_mileage = 200000; ?><?php _e('200.000 km', 'cars_attributes');?></option>
            <option value="250000"><?php $min_mileage = 250000; ?><?php _e('250.000 km', 'cars_attributes');?></option>
            <option value="300000"><?php $min_mileage = 300000; ?><?php _e('300.000 km', 'cars_attributes');?></option>
            <option value="350000"><?php $min_mileage = 350000; ?><?php _e('350.000 km', 'cars_attributes');?></option>   
            <option value="400000"><?php $min_mileage = 400000; ?><?php _e('400.000 km', 'cars_attributes');?></option>
            <option value="450000"><?php $min_mileage = 450000; ?><?php _e('450.000 km', 'cars_attributes');?></option>
            <option value="500000"><?php $min_mileage = 500000; ?><?php _e('500.000 km', 'cars_attributes');?></option>
            <option value="550000"><?php $min_mileage = 550000; ?><?php _e('550.000 km', 'cars_attributes');?></option>
            <option value="600000"><?php $min_mileage = 600000; ?><?php _e('600.000 km', 'cars_attributes');?></option>
            <option value="650000"><?php $min_mileage = 650000; ?><?php _e('650.000 km', 'cars_attributes');?></option>
            <option value="700000"><?php $min_mileage = 700000; ?><?php _e('700.000 km', 'cars_attributes');?></option>
            <option value="750000"><?php $min_mileage = 750000; ?><?php _e('750.000 km', 'cars_attributes');?></option>
            <option value="800000"><?php $min_mileage = 800000; ?><?php _e('800.000 km', 'cars_attributes');?></option>
            <option value="850000"><?php $min_mileage = 850000; ?><?php _e('850.000 km', 'cars_attributes');?></option>
            <option value="900000"><?php $min_mileage = 900000; ?><?php _e('900.000 km', 'cars_attributes');?></option>
            <option value="950000"><?php $min_mileage = 950000; ?><?php _e('950.000 km', 'cars_attributes');?></option>
            <option value="1000000"><?php $min_mileage = 1000000; ?><?php _e('1.000.000 km', 'cars_attributes');?></option>   
      </select>   
     
            <select name="max_mileage" id="max_mileage">
            <?php $max_mileage = Params::getParam('max_mileage') ; ?>
            <option value=""><?php _e('max', 'cars_attributes');?></option>
            <option value="0"><?php $max_mileage = 0; ?><?php _e('0 km', 'cars_attributes');?></option>
            <option value="50000"><?php $max_mileage = 50000; ?><?php _e('50.000 km', 'cars_attributes');?></option>
            <option value="100000"><?php $max_mileage = 100000; ?><?php _e('100.000 km', 'cars_attributes');?></option>
            <option value="150000"><?php $max_mileage = 150000; ?><?php _e('150.000 km', 'cars_attributes');?></option>
            <option value="200000"><?php $max_mileage = 200000; ?><?php _e('200.000 km', 'cars_attributes');?></option>
            <option value="250000"><?php $max_mileage = 250000; ?><?php _e('250.000 km', 'cars_attributes');?></option>
            <option value="300000"><?php $max_mileage = 300000; ?><?php _e('300.000 km', 'cars_attributes');?></option>
            <option value="350000"><?php $max_mileage = 350000; ?><?php _e('350.000 km', 'cars_attributes');?></option>   
            <option value="400000"><?php $max_mileage = 400000; ?><?php _e('400.000 km', 'cars_attributes');?></option>
            <option value="450000"><?php $max_mileage = 450000; ?><?php _e('450.000 km', 'cars_attributes');?></option>
            <option value="500000"><?php $max_mileage = 500000; ?><?php _e('500.000 km', 'cars_attributes');?></option>
            <option value="550000"><?php $max_mileage = 550000; ?><?php _e('550.000 km', 'cars_attributes');?></option>
            <option value="600000"><?php $max_mileage = 600000; ?><?php _e('600.000 km', 'cars_attributes');?></option>
            <option value="650000"><?php $max_mileage = 650000; ?><?php _e('650.000 km', 'cars_attributes');?></option>
            <option value="700000"><?php $max_mileage = 700000; ?><?php _e('700.000 km', 'cars_attributes');?></option>
            <option value="750000"><?php $max_mileage = 750000; ?><?php _e('750.000 km', 'cars_attributes');?></option>
            <option value="800000"><?php $max_mileage = 800000; ?><?php _e('800.000 km', 'cars_attributes');?></option>
            <option value="850000"><?php $max_mileage = 850000; ?><?php _e('850.000 km', 'cars_attributes');?></option>
            <option value="900000"><?php $max_mileage = 900000; ?><?php _e('900.000 km', 'cars_attributes');?></option>
            <option value="950000"><?php $max_mileage = 950000; ?><?php _e('950.000 km', 'cars_attributes');?></option>
            <option value="1000000"><?php $max_mileage = 1000000; ?><?php _e('1.000.000 km', 'cars_attributes');?></option>   
      </select>   
     
    </div>




And as conditions in the index.php

Quote
  case 'min_mileage':
                  if ((int)$value >= 0 && (int)$value < 1000000) {
                  Search::newInstance()->addConditions(sprintf("%st_item_car_attr.i_mileage >= '%s'", DB_TABLE_PREFIX, (int)$value));
                  $has_conditions = true;
               }
            break;
            case 'max_mileage':
               if ( (int)$value > 0 && (int)$value < 1000000 ) {
                  Search::newInstance()->addConditions(sprintf("%st_item_car_attr.i_mileage <= '%s'", DB_TABLE_PREFIX, (int)$value));
                  $has_conditions = true;
               }
            break;


After I press  Search button , during the process of searching i see being prepared for display for a very short time the item wich has the mileage in the interval submitted and and after page refresh instead of that filtered item  the search parametres dissapear and all other ads in the same categoy are displayed. I think i missed something
Modify message

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
For this you don't have to edit files. You make it from admin.
The only draw back is that it will show only if a category is selected.

ad.min

  • Newbie
  • *
  • Posts: 25
I tried with cars attributes plugin but i the search seems to work at the beginning and after refresh the results dissapear and all ads in that category are displayed...

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
What i told you is from core/admin,leaving aside plugins.
And it workes, i have tested it.
« Last Edit: August 31, 2017, 10:28:30 am by marius-ciclistu »

ad.min

  • Newbie
  • *
  • Posts: 25
What i must do ? Which files I must edit ?
« Last Edit: August 31, 2017, 10:32:02 am by ad.min »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Please read what I write..

DON'T EDIT FILES!

ADD AN ADDITIONAL FIELD FROM ADMIN.
MAKE IT MANDATORY.
ENABLE SEARCH WITH IT.
MAKE IT DROPDOWN.
Put in the values input something like
0-10000,10001-20000,20001-... Etc
« Last Edit: March 26, 2018, 07:29:31 pm by marius-ciclistu »

ad.min

  • Newbie
  • *
  • Posts: 25
Many thanks ! I will try :)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
And don't forget to select the categories in which you want this field to be available + to edit the items in order to have this field filled.