Support

Home Forums Event Espresso Premium EE3 to EE4 upgrade, replicate tickets on sale info

EE3 to EE4 upgrade, replicate tickets on sale info

Posted: August 30, 2015 at 11:32 pm


Jade

August 30, 2015 at 11:32 pm

I am testing the upgrade to EE4 and trying to replicate the information we presented using EE3.

I want to display different info if tickets sales are open, closed or upcoming.

This is EE3 version: http://test.southgatemelbourne.com.au/southgate-cinema/
New EE4 test version: http://dev.southgatemelbourne.com.au/southgate-cinema/

If you hover on the cinema listing, the screening and booking information is displayed.

How do I get the start and end dates/times for ticket sales in EE4 in order to do this?


Lorenzo Orlando Caum

  • Support Staff

August 31, 2015 at 12:30 pm

Hi Jo, Event Espresso 4 has a status option banner (e.g. upcoming) that can be turned on through Event Espresso –> Events –> Templates. However, I see you are presenting that information differently.

There is a template tag available that can be used to check the status of an event (https://eventespresso.com/wiki/ee4-themes-templates/):

espresso_event_status()


Lorenzo


Jade

August 31, 2015 at 4:40 pm

Hi Lorenzo

Thanks for the suggestion, but this doesn’t really give me the info that users want.

We need to be able to tell users when bookings go on sale or if they are already closed. The cinema screenings usually book out within minutes so the earlier we can present this info the better (ie before clicking through to a single event).

I was hoping I could at least query the database directly for the start/end dates & times. I’ve looked through all the tables and can’t actually find this data. Can you assist?

thanks


Tony

  • Support Staff

September 1, 2015 at 5:21 am

Hi Jade,

So right now with EE3 are you using the ‘Registration start date’ for those details?

With EE4 how are you listing the shows currently? I’m assuming your doing a custom query and have post objects to loop over but are you using the EE Models to pull in the info?

http://developer.eventespresso.com/docs/model-querying/

You mention the event start date (which would be the datetime dates) which can be used to output the Event Start and End dates/times, when using the models to get the info you’d use something like:

$datetime->start_date_and_time();
$datetime->end_date_and_time();

However I don’t think you need those details, but rather the ticket ‘Sale Starts’ date and the ticket status. The start doesn’t matter if its sold out you just need to show its now sold out using either the ticket status or event status, so far does that make sense?


Jade

September 2, 2015 at 1:47 am

Hi Tony,

Yep we were using a bunch of meta fields for presenting the data with EE3
eg
$event_registration_start = get_post_meta($post->ID, ‘event_registration_start’, true);
$event_registration_start = date(“D j M”, strtotime($event_registration_start));
$event_registration_startT = get_post_meta($post->ID, ‘event_registration_startT’, true);
$event_registration_startT = date(“g.ia”, strtotime($event_registration_startT));

Yes that’s right with EE4 we’re doing a custom query — No we’re not using these models. I haven’t seen this documentation before. Thank you, I’ll have a read over this.

And yes, I meant the start/end dates for ticket sales (not the event itself).

Thanks!


Jade

September 6, 2015 at 10:09 pm

Hi Tony,

I’ve started working with the EE Models now.

I’m not sure if there’s a more efficient way of doing it, but I’ve managed to get all the pieces of data I need to work with…

$events = EEM_Event::instance()->get_all(
				array(
					array('Term_Taxonomy.Term.term_id' => 112, 'Datetime.DTT_EVT_start' => array( '>', current_time())),
					'order_by' => array( 'Datetime.DTT_EVT_start' => 'ASC' )
				)	
			);

					
			foreach( $events as $event ) {
    			echo $event->name()."<br>";
				$eventid = $event->ID();
						
				$datetime = EEM_Datetime::instance()->get_one( 
					array( 
						array( 'EVT_ID' => $eventid )
						)
					);
				echo "start date and time = ".$datetime->start_date_and_time();
						
				$datetimeid = $datetime->ID();
						
				$ticket = EEM_Ticket::instance()->get_one( 
					array( 
						array('Datetime_Ticket.DTT_ID' => $datetimeid) 
					)
				);
						
				echo '<br /><br />';
						
				echo "ticket sales open = ".$ticket->get('TKT_start_date');
						
				echo '<br /><br />';
						
				echo get_the_post_thumbnail( $eventid, 'cinema-landing');
						
			}

Thanks!


Tony

  • Support Staff

September 7, 2015 at 8:43 am

Awesome! I’m glad the models worked for you.

I have a couple of pointers for your code, first one is a quick one:

current_time() is missing its 1st aregument for type, use – current_time(‘timestamp’, true)

Your also repeating yourself a few times and pulling information that you can get from the models.

Try this:

$events = EEM_Event::instance()->get_all(
	array(
		array(
			'Term_Taxonomy.Term.term_id' => 16, 
			'Datetime.DTT_EVT_start' => array( '>', current_time('timestamp', true))),
			'order_by' => array( 'Datetime.DTT_EVT_start' => 'ASC' )
		)	
);

		
foreach( $events as $event ) {
	echo $event->name()."
"; //d($event); //Grab the primary datetime from the event. $datetime = $event->primary_datetime(); //Check we got an EE Datetime. if( $datetime instanceof EE_Datetime ) { echo "start date and time = " . $datetime->start_date_and_time(); //d($datetime); //Grab all tickets for the event $tickets = $datetime->tickets(); //Shift the first ticket from the returned array //This works as there is only one ticket, if you need a specific ticket, //use another method to either pull that or all tickets and loop through. $ticket = reset( $tickets ); //Check we did actually get a EE Ticket if( $ticket instanceof EE_Ticket ) { d($ticket); echo ''; echo "ticket sales open = ".$ticket->start_date(); echo ''; echo get_the_post_thumbnail( $event->ID(), 'cinema-landing'); } } }

Notice the debugging sections I currently have commented out? That’s using Kint (which is awesome!) you might want to install Kint using something like:

https://wordpress.org/plugins/kint-php-debugger/

Then un-comment out one of those lines (or all of them) and view the kind of information you can pull with the models. For example on the ticket object you have the start_date() method which does all the work for you, there is 160 different methods on the ticket alone, so you’ll usually find a method to get what you want – http://take.ms/LyChf

I removed the ID variables and just used the object directly, and also added in some instance checks to make sure we did not try to run methods if nothing is returned.

There’s nothing wrong with the code you posted btw! It works just fine (assuming you always have one datetime and ticket) but the above just does more of the work for you πŸ™‚

  • This reply was modified 8 years, 8 months ago by  Tony. Reason: Updated datetime code


Tony

  • Support Staff

September 7, 2015 at 9:44 am

Hi Jade,

One of our developers mentioned that there is a problem with the above query, I’ve update my example but just wanted to make you aware of it.

The timestamp passed to the query must be UTC+0 (GMT) or ‘normal’ unix timestamps, this means you can’t use just current_time(‘timestamp’) as that will include the timezone offset that WP adds.

So when passing a timestamp simply use:

current_time(‘timestamp’, true)

Which tells the function to pass back a GMT timestamp.

(Note the developer docs will be updated to reflect this to)


Jade

September 8, 2015 at 3:45 am

Really appreciate your pointers Tony! This is much more efficient πŸ™‚

I have the page displaying now as it was before in EE3. Very happy.

http://www.southgatemelbourne.com.au/southgate-cinema/

Thanks for your help.


Tony

  • Support Staff

September 8, 2015 at 5:07 am

You’re most welcome, Jade.

I like what your doing there btw, it’s a nice implementation of the ‘events’ πŸ™‚

The support post ‘EE3 to EE4 upgrade, replicate tickets on sale info’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso