You are here:  » Filters Date

Active Forum Topics


Filters Date

Submitted by Greg on Mon, 2013-08-19 10:59 in

Hello David,

After using your search box with the keyword "filters date" i can't find a post related to my question.

Let's say in my pt_product i have a field with the release date of my products like : date = 19/08/2013

what i have to do for have in the search.php a filter for order my price with the release date.

Old filters :

Order by: Relevance | Price: Low to High, High to Low

New filter i wish :

Order by: Relevance | Price: Low to High, High to Low | release date : Low to High, High to Low

Thx you for your help.

Submitted by support on Mon, 2013-08-19 11:26

Hi Greg,

The best thing to do is probably to store the release date as a PHP time() value rather than a string, which makes it much easier to sort. To try this, assuming your custom field is called "releasedate" (simply adjust in the code examples below if not) then first of all to convert the field to a numeric type run the following dbmod.php script:

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."products`
            CHANGE `releasedate` `releasedate` INT(11)"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Next, the field needs to be converted during import which can be done with the strtotime() function. In includes/admin.php look for the following comment around line 312:

  /* check product record for minimum required fields */

...and insert the following new code at that point:

  $importRecord["releasedate"] = strtotime($importRecord["releasedate"]);

Before coming back to the sort, with that in place and following the next import, wherever you display the releasedate field needs to be modified to use the reverse function - date() - to re-format it back to normal date display. To do this, within your html/ files wherever you currently use the variable:

$product["releasedate"]

(the actual variable name may be slightly different in different files but ["releasedate"] will always be the same)

...REPLACE with:

date("d/m/Y",$product["releasedate"])

Now to add a sort case, edit search.php and look for the following code around line 67:

  $orderByFullText["priceDesc"] = "minPrice DESC";

...and REPLACE with:

  $orderByFullText["priceDesc"] = "minPrice DESC";
  // new for releasedate sort
  $orderByFullText["releasedateDesc"] = "releasedate DESC";
  $orderByFullText["releasedateAsc"] = "releasedate ASC";
  $orderByDefault["releasedateDesc"] = "releasedate DESC";
  $orderByDefault["releasedateAsc"] = "releasedate DESC";

Finally, to add the links, look for the following code around line 313:

$banner["h3"] = translate("Order by").": ".$sortRelevance.$sortRating." | ".translate("Price").": ".$sortPriceAsc.", ".$sortPriceDesc;

...and REPLACE with:

$sortReleasedateAsc = ($sort=="releasedateAsc"?"<strong>".translate("Low to High")."</strong>":"<a href='".$sortHREF."releasedateAsc'>".translate("Low to High")."</a>");
$sortReleasedateDesc = ($sort=="releasedateDesc"?"<strong>".translate("High to Low")."</strong>":"<a href='".$sortHREF."releasedateDesc'>".translate("High to Low")."</a>");
$banner["h3"] = translate("Order by").": ".$sortRelevance.$sortRating." | ".translate("Price").": ".$sortPriceAsc.", ".$sortPriceDesc." | Release Date: ".$sortReleasedateAsc.", ".$sortReleasedateDesc;

Cheers,
David.
--
PriceTapestry.com

Submitted by Greg on Mon, 2013-08-19 13:12

Thx for this great help David, it work very good.

I have one more question :[

I would like dont show the price = 0 in the searchresults...

i have add this in searchresults.php :

<?php
  if (file_exists("html/user_searchresults_before.php")) require("html/user_searchresults_before.php");
?>
<div class='searchresults'>
  <table>
    <?php foreach($searchresults["products"] as $product): ?>
<strong><?php if ($product["price"]=="0.00") continue; ?></strong>

But it dont work like in price.php :(

Thx for your help David.

Submitted by support on Mon, 2013-08-19 13:20

Hi Gregg,

If you don't want zero price items featured on your site at all, it's probably best to drop them at import time. If you wanted to try this, in includes/admin.php look for the following comment at line 314:

  /* check product record for minimum required fields */

...and then add the following line to drop all zero price products:

  if ($importRecord["price"]=="0.00") return;

Don't forget to re-import after making the changes. This way, you don't need to worry about the main product information being displayed from a zero price record for the product...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Greg on Mon, 2013-08-19 13:26

Thx for your answer.

I dont use the import part of your system ...so i can't apply what you say.

In price.php you gave me this tip for dont show price = 0

<?php foreach($prices["products"] as $product): ?>
   <?php if ($product["price"]=="0.00") continue; ?>

Do you have something similar that work with searchresults.php ?

Thx you so much.

Submitted by support on Mon, 2013-08-19 13:46

Hi Greg,

Sure - the equivalent line in html/searchresults.php is (around line 6):

  <?php foreach($searchresults["products"] as $product): ?>

...so REPLACE with:

  <?php foreach($searchresults["products"] as $product): ?>
  <?php if ($product["minPrice"]=="0.00") continue; ?>

- note how it's "minPrice" that needs to be used in the case of search results rather than "price".

Cheers,
David.
--
PriceTapestry.com

Submitted by Greg on Mon, 2013-08-19 14:16

Oh well i'm so sorry to disturb you so much with stupid question but it's important for me.

Products 1 ( category 1 )

price1 = 0euro
price2 = 0euro
price3 = 10 euro

Products 2 ( category 1 )

price1 = 0euro
price2 = 0euro
price3 = 5 euro

Products 3 ( category 1 )

price1 = 0euro
price2 = 1euro
price3 = 7euro

when i applay your code :

<?php
 
foreach($searchresults["products"] as $product):
php if ($product["minPrice"]=="0.00") continue; 
?>

I do a search with category = 1 and then i get the following result : Product search results for category:fps: (showing 1 to 3 of 3)
But nothing show up , no image , no price nothing

If i dont use this line :

<?php
 
if ($product["minPrice"]=="0.00") continue; 
?>

I have

from 0.00
Compare Prices

from 0.00
Compare Prices

from 0.00
Compare Prices

I hope i m clear and you understand what problem i meet...

Thx you David.

Submitted by support on Mon, 2013-08-19 14:25

Hi Greg,

If it's not possible to drop 0.00 prices from your import process then for search results it might actually be better to exclude them via the search SQL rather than in code - because that could result in the condition you describe where there are no results to display...

In search.php, look for the following code at line 49:

  if ($q)

...and REPLACE with:

  $priceWhere .= " AND price > '0.00'";
  if ($q)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Greg on Mon, 2013-08-19 14:51

David you deserve a MEDAL.

Great respect for your work and your help.

Thx you again :)