Advertisement:

Author Topic: Search by currency  (Read 845 times)

ad.min

  • Newbie
  • *
  • Posts: 25
Search by currency
« on: August 25, 2017, 01:47:37 pm »
Hello ! Any ideas how to add a menu to select the currency in the search bar  so  to possible a search by currency ? I tried the currency select menu from the publish item but does not work for search... Thanks

frosticek

  • Hero Member
  • *****
  • Posts: 3948
Re: Search by currency
« Reply #1 on: August 25, 2017, 11:58:29 pm »
Use multi-currency plugin instead.

ad.min

  • Newbie
  • *
  • Posts: 25
Re: Search by currency
« Reply #2 on: August 26, 2017, 07:26:37 pm »
Hi i m looking to add in search form next to the price the currency menu so the user could search all prices in the selected currency Thanks

ad.min

  • Newbie
  • *
  • Posts: 25
Re: Search by currency
« Reply #3 on: August 28, 2017, 10:25:16 am »
I need to insert a currency selector in search page so it will be possible to search and  display ads in certain currencies

calinbehtuk

  • Sr. Member
  • ****
  • Posts: 450
Re: Search by currency
« Reply #4 on: August 28, 2017, 12:24:23 pm »
You can do this easy.
This code is for bender theme but you can modify to match your theme.
Add this in your theme functions.php file
Code: [Select]
function search_by_currency(){
        if (Params::getParam('currency') != '') {
            $value = Params::getParam('currency');
            Search::newInstance()->addConditions(sprintf("%st_item.fk_c_currency_code = '%s' ", DB_TABLE_PREFIX, $value));
        }
}


osc_add_hook('search_conditions', 'search_by_currency');

And now the code for search-sidebar from your theme
Code: [Select]
            <fieldset>
                <?php
                $currency_check 
osc_get_currencies();
                
$number_of_currency count($currency_check);
                if (
$number_of_currency 1) {
                    
?>

                <h3><?php _e('Select currency''bender'); ?></h3>
                    <select name="currency" >
                        <option value=""><?php _e('All currency''bender'); ?></option>
                        <?php foreach ($currency_check as $curr) { ?>
                        <option value="<?php echo $curr['pk_c_code']; ?>" <?php if(Params::getParam('currency') == $curr['pk_c_code']){ echo 'selected';}?>><?php echo $curr['pk_c_code']; ?></option>
                        <?php ?>
                    </select>
                <?php ?>
            </fieldset>
« Last Edit: August 28, 2017, 12:44:28 pm by calinbehtuk »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search by currency
« Reply #5 on: August 28, 2017, 12:30:30 pm »
Thank you calinbehtuk. I was interested in this for a while now but couldn't figure it out by my self.
I'll give it a try.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search by currency
« Reply #6 on: August 28, 2017, 12:40:16 pm »
The only thing is that the field does not remember the previous currency selected, after hitting apply filters.

Couldn't it be resolved in a similar way like the region is?

Code: [Select]
value="<?php echo osc_esc_html(Params::getParam('sRegion'));?>

calinbehtuk

  • Sr. Member
  • ****
  • Posts: 450
Re: Search by currency
« Reply #7 on: August 28, 2017, 12:45:22 pm »
No. Copy the code for search sidebar again, and now will work.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Search by currency
« Reply #8 on: August 28, 2017, 12:54:18 pm »
No. Copy the code for search sidebar again, and now will work.

I rezolved it like this:

<select name="currency" >
                        <option value="<?php Params::getParam('currency');?>"><?php if(Params::getParam('currency')=='') echo 'Select'; else echo Params::getParam('currency'); ?></option>


Thank you verry much:)
EDIT
But this doesn't enable me to select all again. I'll give it a try with your new code.

It works perfect. Thank you.
« Last Edit: August 28, 2017, 01:00:40 pm by marius-ciclistu »

ad.min

  • Newbie
  • *
  • Posts: 25
Re: Search by currency
« Reply #9 on: August 28, 2017, 08:42:35 pm »
Thank you it works perfect!!!  :) Many thanks!