rsanchez / dynamo

Makes Dynamic Parameters behave more like the Search module.
http://devot-ee.com/add-ons/dynamo/
10 stars 2 forks source link

Using & seperator to search categories, you need to search both categories to get results. #31

Closed johnj24 closed 10 years ago

johnj24 commented 10 years ago

I have two dropdowns, each containing a different category group. Is there a method I'm missing that would allow searching for both groups combined, plus the ability to search for one or the other? The & separator works great for when you're searching for two categories, but it doesn't return any results if you only search one or the other.

My two groups are:

New Old

Motorhomes Fifth Wheels Toy Trailers

Here's my code:

{exp:dynamo:form return="/{segment_1}/search" search_id="{segment_3}" separator:category="&"}
    <div class="banner-dropdown">   
        <select name="category[]">
            <option>Choose Your Style</option>
            {exp:gwcode_categories group_id="1" parse="inward" style="linear"}
            <option value="{cat_id}"{if {exp:dynamo:selected value="{cat_id}" in="{category}"}} selected{/if}>{cat_name}</option>
            {/exp:gwcode_categories}
        </select>
    </div>

    <div class="banner-dropdown">   
        <select name="category[]">
            <option>Choose Your RV</option>
            {exp:gwcode_categories group_id="2" parse="inward" style="linear"}
            <option value="{cat_id}"{if {exp:dynamo:selected value="{cat_id}" in="{category}"}} selected{/if}>{cat_name}</option>
            {/exp:gwcode_categories}
        </select>
    </div>

    <div class="search-btn"><input type="submit" value="SEARCH &gt;&gt;"></div>
{/exp:dynamo:form}
rsanchez commented 10 years ago

Can you go into your database, in the exp_dynamo table, find the search that isn’t returning any results and post the value here from the parameters column of that table row? I’m not sure why it would fail when you only search one of those select dropdowns.

johnj24 commented 10 years ago

When searching only the New category, this is the parameter: YToxOntzOjg6ImNhdGVnb3J5IjtzOjE2OiIxJkNob29zZSBZb3VyIFJWIjt9

rsanchez commented 10 years ago
var_dump(unserialize(base64_decode('YToxOntzOjg6ImNhdGVnb3J5IjtzOjE2OiIxJkNob29zZSBZb3VyIFJWIjt9')));

yields

array(1) {
  'category' =>
  string(16) "1&Choose Your RV"
}

I think you’ll have to try this to keep the option's text from getting passed as the value.

<option value="">Choose Your Style</option>
johnj24 commented 10 years ago

That was it! I skipped right over the missing value attribute. Thanks Rob.

johnj24 commented 10 years ago

Side question: When I use the query string to send users to a specific search result, is there any way to put the search keywords on the page? Example: Search Results for New Motorhome. I'm using Dynamo to retrieve the listings if that helps.

rsanchez commented 10 years ago

That's gonna be a bit trickier, I'm afraid. In the {exp:dynamo:form} tag pair you'll get a {category} variable, but the value of that is gonna be something like 1&2. So you'd have to find a way to transform that string into something you can use to look up the category names. There's nothing built in to Dynamo to do that I'm afraid.

johnj24 commented 10 years ago

I'm noticing that I don't get the {category} variable to work when using the query string search. It just returns an unparsed {category} variable. But when I use the Dynamo form, it does indeed work. Is that normal behavior?

rsanchez commented 10 years ago

You're right. Bad advice on my part. It won't work in the query string way.

You can use Mo' Variables to enable {get:category}, which you can then feed into gwcode_categories.

johnj24 commented 10 years ago

GWCode Categories doesn't take & separators in the show="" parameter, so we had to whip up some PHP to handle it. Here's what we got to work:

{exp:gwcode_categories show="<?php echo str_replace(Array('&', ';'), Array('|', ''), '{get:category}'); ?>" style="linear"} {cat_name} {/exp:gwcode_categories}