Datafeedr Support Forums  

Go Back   Datafeedr Support Forums > Current Version (V3) Forum > Questions
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Important - The support forums are now in "read-only" mode as we transition to an alternative help desk solution. Feel free to contact us here with any of your questions or search the forums for an existing solution.
 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 25th, 2011, 08:44 PM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default Autosubmit of category sorting resets other query variables

Hi Eric,

I'm very happily using the autosubmit for the products per page and sort by price code:
Code:
<div class="dffltrs">
  <form method="get">  
    <span class="dflside">
      Products per page:
      <select name="ppp" class="dfppp" onchange='this.form.submit()'>
        <option value="12"<?php if (@$_GET['ppp']=='12') {echo ' selected="selected"';}?>>12</option>
        <option value="24"<?php if (@$_GET['ppp']=='24') {echo ' selected="selected"';}?>>24</option>
        <option value="36"<?php if (@$_GET['ppp']=='36') {echo ' selected="selected"';}?>>36</option>
        <option value="48"<?php if (@$_GET['ppp']=='48') {echo ' selected="selected"';}?>>48</option>
      </select>
    </span>
    <span class="dfrside">
      Sort by:
      <select name="sort" class="dfsort" onchange='this.form.submit()'>
        <option value="price"<?php if (@$_GET['sort']=='price') {echo ' selected="selected"';}?>>Price (low to high)</option>
        <option value="-price"<?php if (@$_GET['sort']=='-price') {echo ' selected="selected"';}?>>Price (high to low)</option>
        <option value="name"<?php if (@$_GET['sort']=='name') {echo ' selected="selected"';}?>>Product Name (a - z)</option>    
        <option value="-name"<?php if (@$_GET['sort']=='-name') {echo ' selected="selected"';}?>>Product Name (z - a)</option>    
      </select>
      <input type="submit" value="Go" class="dfsbmt" />
    </span>
    <div class="clearingdiv">&nbsp;</div>
  </form>
</div>
However it appears that this code will reset any other search filters applied already...

Is there a way to keep existing search filters and keep autosubmit?

Thanks!
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #2  
Old January 25th, 2011, 11:02 PM
firstprod firstprod is offline
 
Join Date: Jul 2009
Posts: 71
Default

I had the same problem as you, so created a work around that does the job. (Eric asked me to post the solution here btw as I showed him the end result of my "botch job" a week or so ago)

This is how I did it:

Sample the page URL using $_SERVER['REQUEST_URI'] and extract the extra parameters appended to the URL by either the sorter, the search form or the filters (I'm probably going to redo it using "if (@$_GET['name'])" etc as I think it'll be more elegant)

Check that the extra parameters that need to be passed aren't either "ppp" or "sort" values (as they are what is changed by the autosorter so they are not needed).

Add EACH of the remaining sort parameters into the form as fixed hidden fields using

echo '<INPUT TYPE="HIDDEN" NAME="'.$parameter[1].'" Value="'.$value[1].'">';

... for all the parameters that need to be passed on - these fields then get submitted with the autosorter values when the autosorter submits the new parameters.

Works a treat with filters, search pages and so on, and seems very robust - ie it works whatever order the search+filter+sorting values are applied to the page.

Good luck.

I'd show you one of the sites it's working on, but then I'd have to kill you
  #3  
Old January 26th, 2011, 09:38 AM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default

Thanks firstprod! Much appreciated!

Do you have a snippet of working code you could publish here?

Of course I'd rather have a look at your working site, but I value my life even more ;-)
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #4  
Old February 2nd, 2011, 05:54 PM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default

Okay, so I've been messing around with this a bit, and got it working...

Code:
<?php
function search_word_value($word) {
    $word = strip_tags($word);
    return $word;
}
?>

<div class="dffltrs">
  <form method="get">
    <?php if (@$_GET['word']){ echo '<INPUT TYPE="HIDDEN" NAME="word" Value="'. search_word_value($_GET['word']).'"'; } ?>
    <span class="dflside">
      Products per page:
      <select name="ppp" class="dfppp" onchange='this.form.submit()'>
        <option value="12"<?php if (@$_GET['ppp']=='12') {echo ' selected="selected"';}?>>12</option>
        <option value="24"<?php if (@$_GET['ppp']=='24') {echo ' selected="selected"';}?>>24</option>
        <option value="36"<?php if (@$_GET['ppp']=='36') {echo ' selected="selected"';}?>>36</option>
        <option value="48"<?php if (@$_GET['ppp']=='48') {echo ' selected="selected"';}?>>48</option>
      </select>
    </span>
    <span class="dfrside">
      Sort by:
      <select name="sort" class="dfsort" onchange='this.form.submit()'>
        <option value="price"<?php if (@$_GET['sort']=='price') {echo ' selected="selected"';}?>>Price (low to high)</option>
        <option value="-price"<?php if (@$_GET['sort']=='-price') {echo ' selected="selected"';}?>>Price (high to low)</option>
        <option value="name"<?php if (@$_GET['sort']=='name') {echo ' selected="selected"';}?>>Product Name (a - z)</option>    
        <option value="-name"<?php if (@$_GET['sort']=='-name') {echo ' selected="selected"';}?>>Product Name (z - a)</option>    
      </select>
      <input type="submit" value="Go" class="dfsbmt" />
    </span>
    <div class="clearingdiv">&nbsp;</div>
  </form>
</div>
Will I have to add this for each possible filter attribute for my shop or is there an easier way to grab all search parameters in one go?
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #5  
Old April 27th, 2011, 01:44 AM
cjazz cjazz is offline
 
Join Date: Jul 2009
Posts: 8
Default

Ayorofrance,

Thanks for posting your code, it's a great help for a non-techie like me! A question for the more technical people out there.

I have a search that returns the following in the url:

...search/?name=widget&price=10-25

by using the autosubmit code above it still refreshes the search critera, I guess cause I'm also including the price! How do I amend the code to autosubmit with two peices of search critera?

thanks for your help and great tips people!
  #6  
Old April 27th, 2011, 02:43 AM
ayorofrance ayorofrance is offline
 
Join Date: Sep 2010
Posts: 430
Default

Hi cjazz,

You will have to store any search parameters you are using following the model given.

I know this can be a bit daunting if you're not used to looking at code, so here is the full code I am using for the category/search page:
Code:
<?php
function search_word_value($word) {
    $word = strip_tags($word);
    return $word;
}
?>

<!-- Pagination Links (Top) -->
<div class="pgr">
  Pages:
  [pager.first text='"&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt; First&nbsp;&nbsp;&nbsp;&nbsp;"' alt='"&lt;&lt; First&nbsp;&nbsp;&nbsp;&nbsp;"' ]
  [pager.prev text='"&lt; Previous&nbsp;&nbsp;&nbsp;&nbsp;"'  alt='"&lt; Previous&nbsp;&nbsp;&nbsp;&nbsp;"']
  [pager.pages]
  [pager.next text='"&nbsp;&nbsp;&nbsp;&nbsp;Next &gt;"' alt='"&nbsp;&nbsp;&nbsp;&nbsp;Next &gt;"']
  [pager.last text='"&nbsp;&nbsp;&nbsp;&nbsp;Last &gt;&gt;"' alt='"&nbsp;&nbsp;&nbsp;&nbsp;Last &gt;&gt;"']
</div>
<!-- /Pagination Links (Top) -->

<div class="dffltrs">
  <span class="dflside">
    <form method="get">
      <?php if (@$_GET['merchant']){ echo '<INPUT TYPE="HIDDEN" NAME="merchant" Value="'.search_word_value($_GET['merchant']).'" />'; } ; ?>
      <?php if (@$_GET['word']){ echo "<INPUT TYPE='HIDDEN' NAME='word' Value='".search_word_value($_GET['word'])."' />"; } ?>
      <?php if (@$_GET['price']){ echo '<INPUT TYPE="HIDDEN" NAME="price" Value="'.search_word_value($_GET['price']).'" />'; } ?>
      <?php if (@$_GET['sort']){ echo '<INPUT TYPE="HIDDEN" NAME="sort" Value="'.search_word_value($_GET['sort']).'" />'; } ?>
      Products per page:
      <select name="ppp" class="dfppp" onchange='this.form.submit()'>
        <option value="12"<?php if (@$_GET['ppp']=='12') {echo ' selected="selected"';}?>>12</option>
        <option value="24"<?php if (@$_GET['ppp']=='24') {echo ' selected="selected"';}?>>24</option>
        <option value="36"<?php if (@$_GET['ppp']=='36') {echo ' selected="selected"';}?>>36</option>
        <option value="48"<?php if (@$_GET['ppp']=='48') {echo ' selected="selected"';}?>>48</option>
      </select>
      <input type="submit" value="Go" class="dfsbmt" />
    </form>
  </span>
  <span class="dfrside">
    <form method="get">
      <?php if (@$_GET['merchant']){ echo '<INPUT TYPE="HIDDEN" NAME="merchant" Value="'.search_word_value($_GET['merchant']).'" />'; } ; ?>
      <?php if (@$_GET['word']){ echo "<INPUT TYPE='HIDDEN' NAME='word' Value='".search_word_value($_GET['word'])."' />"; } ?>
      <?php if (@$_GET['price']){ echo '<INPUT TYPE="HIDDEN" NAME="price" Value="'.search_word_value($_GET['price']).'" />'; } ?>
      <?php if (@$_GET['ppp']){ echo '<INPUT TYPE="HIDDEN" NAME="ppp" Value="'.search_word_value($_GET['ppp']).'" />'; } ?>
      Sort by:
      <select name="sort" class="dfsort" onchange='this.form.submit()'>
        <option value="name"<?php if (@$_GET['sort']=='-clicks') {echo ' selected="selected"';}?>>Most popular</option>
        <option value="name"<?php if (@$_GET['sort']=='name') {echo ' selected="selected"';}?>>Product Name (a - z)</option>    
        <option value="-name"<?php if (@$_GET['sort']=='-name') {echo ' selected="selected"';}?>>Product Name (z - a)</option>    
        <option value="price"<?php if (@$_GET['sort']=='price') {echo ' selected="selected"';}?>>Price (low to high)</option>
        <option value="-price"<?php if (@$_GET['sort']=='-price') {echo ' selected="selected"';}?>>Price (high to low)</option>
      </select>
      <input type="submit" value="Go" class="dfsbmt" />
    </form>
  </span>
  <div class="clearingdiv">&nbsp;</div>
</div>

<!-- Product List -->
<div class="pl">
  [product.each]
  <div class="t1 col3">
  <div class="bdr">
    <div class="thmb"><a href="[product.link]" title="[product.name]">[product.image tag='1']</a></div>
    <div class="prc"><strong>[product.currency mode="sign"][product.price]</strong></div>
    <br>
    <p class="desc" align="center">[product.brand]<br>[product.name]</p>
    <div class="prc">[product.merchant_logo]</div>
    <div class="btns">
    <a href="[product.url direct='0']" title="Buy [product.name]" class="dfbutton dforange dfmedium" target="_blank" onClick="_gaq.push(['_trackEvent', 'BuyButton', 'Click']);">Buy</a>
    <a href="[product.link]" title="View details of [product.name]" class="dfbutton dforange dfmedium">Details</a>
    </div>
    <div class="clearingdiv"> </div>
  </div>
  </div>
  [product.end]
  <div class="clearingdiv"> </div>
</div>
<!-- /Product List -->


<!-- Pagination Links (Bottom) -->
<div class="pgr">
  Pages:
  [pager.first text='"&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt; First&nbsp;&nbsp;&nbsp;&nbsp;"' alt='"&lt;&lt; First&nbsp;&nbsp;&nbsp;&nbsp;"' ]
  [pager.prev text='"&lt; Previous&nbsp;&nbsp;&nbsp;&nbsp;"'  alt='"&lt; Previous&nbsp;&nbsp;&nbsp;&nbsp;"']
  [pager.pages]
  [pager.next text='"&nbsp;&nbsp;&nbsp;&nbsp;Next &gt;"' alt='"&nbsp;&nbsp;&nbsp;&nbsp;Next &gt;"']

  [pager.last text='"&nbsp;&nbsp;&nbsp;&nbsp;Last &gt;&gt;"' alt='"&nbsp;&nbsp;&nbsp;&nbsp;Last &gt;&gt;"']
</div>
<!-- /Pagination Links (Bottom) -->
Note that you might have to add a line for name as well for yours to work.

And if you use any filters in widgets you will have to add some code there too...

Here is my price filter:
Code:
<?php
function search_price_value($word) {
    $word = strip_tags($word);
    return $word;
}
?>

<form method="get">
    <?php if (@$_GET['merchant']){ echo "<INPUT TYPE='HIDDEN' NAME='merchant' Value='".search_price_value($_GET['merchant'])."' />"; } ?>
    <?php if (@$_GET['word']){ echo "<INPUT TYPE='HIDDEN' NAME='word' Value='".search_price_value($_GET['word'])."' />"; } ?>
  <?php if (@$_GET['ppp']){ echo '<INPUT TYPE="HIDDEN" NAME="ppp" Value="'.search_price_value($_GET['ppp']).'" />'; } ?>
  <?php if (@$_GET['sort']){ echo '<INPUT TYPE="HIDDEN" NAME="sort" Value="'.search_price_value($_GET['sort']).'" />'; } ?>

  <select name="price" onchange='this.form.submit()' id='store_dropdown_box'>
<option value="1-50"<?php if (@$_GET['price']=='1-50') {echo ' selected="selected"';}?>>Less than 50</option>
<option value="50-100"<?php if (@$_GET['price']=='50-100') {echo ' selected="selected"';}?>>50 ~ 100</option>
<option value="100-150"<?php if (@$_GET['price']=='100-150') {echo ' selected="selected"';}?>>100 ~ 150</option>
<option value="150-200"<?php if (@$_GET['price']=='150-200') {echo ' selected="selected"';}?>>150 ~ 200</option>
<option value="200-250"<?php if (@$_GET['price']=='200-250') {echo ' selected="selected"';}?>>200 ~ 250</option>
<option value="250-"<?php if (@$_GET['price']=='250-') {echo ' selected="selected"';}?>>More than 250</option>

    </select>
    <input type="submit" value="Go" class="dfsbmt" />
</form>
  
<?php if (@$_GET['price']) { ?>
  <p><a href="[server.url type='fullpage' query='-price']">[X] Remove filter</a></p>
<?php } ?>
So basically any code that modified the search parameters will have to store any other search parameters you use before making modifications. In the case above the price filter makes changes to the price search parameter. It stores the merchant, word, ppp and sort variables before chaning price...

To add name use code like this:
Code:
  <?php if (@$_GET['name']){ echo '<INPUT TYPE="HIDDEN" NAME="name" Value="'.search_price_value($_GET['name']).'" />'; } ?>[/b]
Note also that search_price_value has to match the name of the corresponding function at the top of the code:
Code:
function search_price_value($word) {
And that if you have another filter widget on the page this function name has to be different, for exampe if you have a merchant filter you can use this code:
Code:
<?php
function search_merchant_value($word) {
    $word = strip_tags($word);
    return $word;
}
?>

<form method="get">
  <?php if (@$_GET['price']){ echo "<INPUT TYPE='HIDDEN' NAME='price' Value='".search_merchant_value($_GET['price'])."' />"; } ?>
  <?php if (@$_GET['word']){ echo "<INPUT TYPE='HIDDEN' NAME='word' Value='".search_merchant_value($_GET['word'])."' />"; } ?>
  <?php if (@$_GET['ppp']){ echo '<INPUT TYPE="HIDDEN" NAME="ppp" Value="'.search_price_value($_GET['ppp']).'" />'; } ?>
  <?php if (@$_GET['sort']){ echo '<INPUT TYPE="HIDDEN" NAME="sort" Value="'.search_merchant_value($_GET['sort']).'" />'; } ?>
This should get you on the way...
__________________
WordPress Security - Is your WordPress secure? Get our FREE checklist and find out.

Easy-Email - Access ALL your email accounts with one login & synchronize automatically on all your computers.
  #7  
Old April 27th, 2011, 03:07 AM
cjazz cjazz is offline
 
Join Date: Jul 2009
Posts: 8
Default

Thanks Ayorofrance, I'll go through this, that will keep me busy today!

thanks for your quick reply!
  #8  
Old May 31st, 2011, 08:10 AM
euroads euroads is offline
 
Join Date: May 2011
Posts: 6
Default

I have a problem when using the sorting code described above. When I click either the "Products per page" or "Sort by" dropdown box I'm being redirected to the frontpage of the shop.

http://myshopfashion.com/?q=store%2Fcategory%2Ft-shirts

What am I doing wrong?
  #9  
Old May 31st, 2011, 08:26 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

I think you should probably enable Permalinks. It should work then.

Eric
  #10  
Old June 8th, 2011, 08:11 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Quote:
Originally Posted by euroads View Post
I have a problem when using the sorting code described above. When I click either the "Products per page" or "Sort by" dropdown box I'm being redirected to the frontpage of the shop.

http://myshopfashion.com/?q=store%2Fcategory%2Ft-shirts

What am I doing wrong?
Your issue has been moved here: http://www.datafeedr.com/forums/showthread.php?t=4623
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:04 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.