You are here:  » listing in chronological order from dates in title


listing in chronological order from dates in title

Submitted by paul1107 on Wed, 2014-05-07 07:47 in

Hi David,

I have a tickets site, and the plugin works really well, however I just wondered if there was a mod to display the tour dates chronology?

if you look at this page, it illustrates it quote well

{link saved}

Is there anything that can be done?

cheers

Paul

Submitted by support on Wed, 2014-05-07 08:19

Hi Paul,

Does your feed have a separate date (or date / time) column? You can check by looking at the sample data on Feed Registration Step 2. If so, can you post an example of the format?

If not, a filter could be used to extract the date from the product name using a regular expression...

Cheers,
David.
--
PriceTapestry.com

Submitted by paul1107 on Wed, 2014-05-07 11:59

Hi David,

sorry, I should have mentioned that, no it doesn't have a separate date field, it only appears in the "name" field which have allocated as "Product Name" in PT.

example:

Grand Ole Opry: Carrie Underwood, Charlie Daniels Band, Francesca Battistelli Tickets 2014-05-10 Na...

cheers

Paul

Submitted by support on Wed, 2014-05-07 12:30

Hi paul,

Ah OK, no problem - first step would be to add a new field - I would recommend `eventdate` as DATE is a reserved word in MySQL to your site based on the standard instructions, but using INT(11) as the type for the `eventdate` field on your products table, so your dbmod.php would be as follows:

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."feeds`
            ADD `field_eventdate` VARCHAR(255) NOT NULL"
;
  
database_queryModify($sql,$result);
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."products`
            ADD `eventdate` INT(11) NOT NULL"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Don't forget the mod to the $config_fieldSet array in config.advanced.php, so in the future you will be able to register a field if you subsequently add feeds that contain a specific date field.

Next step, is to add code to the import record handler to scan the product name for a date, and populate the field if found, with the final step being a call to strtotime() to make the date value an INT, so that it can be sorted...!

Firstly, edit the Price Tapestry file includes/admin.php and look for the following code at line 344:

  if (!$importRecord["merchant"]) return;

...and REPLACE with:

  if (!$importRecord["merchant"]) return;
  if (!$importRecord["eventdate"])
  {
    preg_match("/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/",$importRecord["name"],$matches);
    if (isset($matches[0]))
    {
      $importRecord["eventdate"] = $matches[0];
    }
  }
  $importRecord["eventdate"] = strtotime($importRecord["eventdate"]);

Finally, to make eventdate the default sort order, edit the plugin file pto.php and look for the following code at line 163:

  $pto_sort = (isset($pto_sort)?$pto_sort:"relevance");

...and REPLACE with:

  $pto_sort = (isset($pto_sort)?$pto_sort:"eventdate");

And finally, in pto_search.php look for the following code at line 308:

  $orderBy["rating"] = "rating DESC";

...and REPLACE with:

  $orderBy["eventdate"] = "eventdate ASC";
  $orderBy["rating"] = "rating DESC";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by paul1107 on Wed, 2014-05-07 13:39

Thanks David, works flawlessly!

****AMENDED****

sorry, now having a closer look, it works to a point... can't describe it, best share a link

{link saved}

however, just one amend if it is possible? with most searches for an artist, there is a result of "*Artists Name* Tickets", this allways used to appear at the top of the seatch, it now appears at the end of a search result.

Is there any way of reverting that search result back to the the top?

Sorry about that.

Paul

Submitted by support on Wed, 2014-05-07 13:43

Hi Paul,

No problem; where you made the modification in includes/admin.php, after the last line, add this line:

  if ($importRecord["eventdate"] < 0) $importRecord["eventdate"] = 0;

This will handle the case of strtotime() returning -1 on failure rather than FALSE, as this varies by PHP version. Re-import, and that should return the results without a valid date to the top of the results.

Cheers,
David.
--
PriceTapestry.com

Submitted by paul1107 on Wed, 2014-05-07 13:50

Thanks again David!

I was just going to reinstall the feed, and found that my /admin/ is returning a blank page?

can you hazard a guess why?sorry for the hassle

Regards

Paul

Submitted by support on Wed, 2014-05-07 13:56

Hi Paul,

Sorry about that - can you email me over your includes/admin.php and I'll check the changes in context...

Cheers,
David.
--
PriceTapestry.com

Submitted by alexnn on Wed, 2018-08-22 22:06

Hi David,
I saw that after adding a custom field "eventdate" it continues to combine duplicates only with the matching of the product name (Feed Utilities> Duplicate Names)
and does not consider different dates.
How can I make duplicates consider the product name + "eventdate"?
i.e to do it
product name1 eventdate1 - not a duplicate
product name1 eventdate1 - this is a duplicate
product name1 eventdate2 - not a duplicate...
But now its only one "product name1"

Submitted by support on Thu, 2018-08-23 06:26

Hi Alex,

To combine your custom field `eventdate` with the product name for duplicate prevention, edit includes/admin.php and look for the following code at line 482:

    $dupe_key .= tapestry_mb_strtolower($searchName);

...and REPLACE with:

    $dupe_key .= tapestry_mb_strtolower($searchName);
    $dupe_key .= $importRecord["eventdate"];

Cheers,
David.
--
PriceTapestry.com

Submitted by alexnn on Thu, 2018-08-23 13:23

Thanks David!
Is it possible to use Drop Record RegExp filter
and drop record if field "eventdate" < "Today" ?

Submitted by support on Thu, 2018-08-23 14:33

Hi Alex,

Rather than using a filter, if you're converting `eventdate` to a time() value using strtotime() as per the above;

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

...then you could REPLACE with:

    $importRecord["eventdate"] = strtotime($importRecord["eventdate"]);
    global $admin_time;
    if (!isset($admin_time)) $admin_time = time();
    if ($importRecord["eventdate"] && ($importRecord["eventdate"] < $admin_time)) return;

...and that will drop any records with an eventdate but in the past...

Cheers,
David.
--
PriceTapestry.com

Submitted by alexnn on Thu, 2018-08-23 17:35

Cool! Thank you for support!

Submitted by alexnn on Fri, 2018-08-24 09:12

Hi David,
Is this possible to add datePicker for searchform and for sidebar widget with "eventdate" to sort posts by date?

Submitted by support on Fri, 2018-08-24 10:44

Hi Alex,

Did you already make the changes above to add sort by eventdate?

Cheers,
David.
--
PriceTapestry.com

Submitted by alexnn on Fri, 2018-08-24 11:28

Yes, I did , all works well

Submitted by support on Fri, 2018-08-24 11:48

Hi Alex,

I'll follow this up with you first thing next week;

Support for a date picking form widget would be dependent on your theme and any libraries that it includes but if you are able to make a test post containing an HTML form with e.g.

<form>
  <input type='text' name='date' />
</form>

...and have that input element converted into a date picker then it should be straight forward to add from / to fields to the search filters widget.

In the meantime, I assume at the moment that as you are only importing `eventdate` as a UNIX time() value that you are not currently displaying it anywhere? I can easily help you with adding a special handler for %DB_eventdate% to have it displayed in any format you wish using PHP's date() function...

Cheers,
David.
--
PriceTapestry.com

Submitted by alexnn on Fri, 2018-08-24 12:43

I tried to add the code above to post and I got an empty form in the post. ???
>you are only importing `eventdate` as a UNIX time() value that you are not currently displaying it anywhere?
yes, `eventdate` only for datepicker.
>I can easily help...
yes, please any format, for example dd/mm/YYYY date picker for searshform

Submitted by support on Mon, 2018-08-27 08:26

Hello Alex,

I'm afraid there isn't a native date picker form type in HTML which is why you are getting an empty form, that is why it would be dependent on a library to convert a text input field into a date picker. If your theme includes (or you can include) jQueryUI (many do!) there is a Datepicker component...

In the meantime, to display the event date in the price comparison table (since I know that you are using date for de-duplication so you may have product pages with the same event for multiple dates) first edit the Prices / Before template (wp-admin > Settings > PriceTapestry.org) and where you have the following markup;

<th class='pto_ali-c'>Price</th>

...REPLACE with:

<th class='pto_ali-c'>Event Date</th>
<th class='pto_ali-c'>Price</th>

And in Prices / Each, where you have the following markup;

<td class='pto_ali-c'>%PRICE%</td>

...REPLACE with:

<td class='pto_ali-c'>%DB_EVENTDATE%</td>
<td class='pto_ali-c'>%PRICE%</td>

And finally edit the plugin file pto_product.php and look for the following code at line 112:

    $each = str_replace("%PRICE%",$pto_config_currencyHTML.$product->price,$each);

...and REPLACE with:

    $each = str_replace("%DB_EVENTDATE%",date("d/m/Y",$product->eventdate),$each);
    $each = str_replace("%PRICE%",$pto_config_currencyHTML.$product->price,$each);

Notice how the replacement of %DB_EVENTDATE% uses PHP's date() function so you can format the date however you like by editing "d/m/Y" according to the date() format options...

Cheers,
David.
--
PriceTapestry.com

Submitted by alexnn on Mon, 2018-08-27 09:30

Hello David,
but how to associate the datepicker (html code on link) to do query date from the database (when choose date in to search form) and i saw list of posts related to selected dates only?
where to find the search form code?

Thanks for the support!

Submitted by support on Tue, 2018-08-28 08:23

Hello Alex,

Did you successfully add the code to display the date in the price comparison table?

The first stage would be to add the date fields to the Search Filters widget which is constructed from the Main / Search Filters template (wp-admin > Settings > PriceTapestry.org) and the code in pto_search.php beginning at line 855 (pto_search_filters_html() function).

However before I can help you with that it would be necessary to get your test HTML form working with a datepicker widget that is compatible with your theme. Did you check whether jQuery / jQueryUI are included in your template? To check, you can simply view your home page and then use your browser's View > Source... function to look at the code and look for the includes...

(i'll follow up regarding the country filter once this is completed - it's much easier to have only one support request that involves guiding modifications on the go at any one time...!)

Cheers,
David.
--
PriceTapestry.com

Submitted by alexnn on Wed, 2018-08-29 04:08

Hello David,
>Did you successfully add the code
Yes, its Ok.
Could we continue writing by e-mail, please?

Submitted by support on Wed, 2018-08-29 09:37

Hello Alex,

Sure - if you could email me modified pto.php and pto_search.php for reference and let me know where you've got up to re: the above and I'll pick it up with you...

Cheers,
David.
--
PriceTapestry.com