Ticket QTY Picker Disappears

This topic contains 13 replies, has 2 voices, and was last updated by  Paul Oaten 6 years, 11 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #26334

    Hi Stephen,

    I have a weird issue which has just been discovered on the event booking form.

    Basically, the QTY picker appears and then immediately disappears once the page has loaded. Example here: https://www.panary.co.uk/craft-baking-courses/1-day-basic/

    I have checked all settings but they really haven’t changed for ages. The problem only seems to occur if I’m logged out. When logged-in, I see the qty picker ok but only if I go into the event editor and re-save the event.

    Versions installed:

    Event Organiser: 3.1.7
    Event Organiser Pro: 1.11.9

    I’ve done a bit more checking in the Chrome Dev Tools and the console shows the following error:

    Uncaught TypeError: Cannot read property ‘tickets’ of undefined
    at occurrence-picker.min.js?ver=1.11.9:2
    at Function.m.each.m.forEach (underscore.min.js?ver=1.8.3:5)
    at n.each (backbone.min.js?ver=1.2.3:1)
    at n.set_ticket_event_availability (occurrence-picker.min.js?ver=1.11.9:2)
    at n.initialize (occurrence-picker.min.js?ver=1.11.9:2)
    at n.e.Model (backbone.min.js?ver=1.2.3:1)
    at new n (backbone.min.js?ver=1.2.3:1)
    at occurrence-picker.min.js?ver=1.11.9:2

    Does that help?

    Grateful for any assistance

    Paul Oaten
    #26335

    Hi Paul,

    Could you enable SCRIPT_DEBUG in your wp-config.php. That will use the non-minifed version of the javascript files, and will give a better indication of where the error is coming from.

    Stephen Harris
    #26336

    Stephen,

    here is the output from console with script_debug enabled:

    Uncaught TypeError: Cannot read property ‘tickets’ of undefined
    at occurrence-picker.js?ver=1.11.9:628
    at Function.m.each.m.forEach (underscore.min.js?ver=1.8.3:5)
    at n.each (backbone.min.js?ver=1.2.3:1)
    at n.set_ticket_event_availability (occurrence-picker.js?ver=1.11.9:622)
    at n.initialize (occurrence-picker.js?ver=1.11.9:504)
    at n.e.Model (backbone.min.js?ver=1.2.3:1)
    at new n (backbone.min.js?ver=1.2.3:1)
    at occurrence-picker.js?ver=1.11.9:937

    Paul Oaten
    #26337

    Hi Paul,

    It appears to be working for me, with SCRIPT_DEBUG enabled. Have you done anything else other than enable script debug?

    Stephen Harris
    #26338

    It just seems unpredictable.

    Do you see the qty field on this page?

    https://www.panary.co.uk/craft-baking-courses/2-day-french-with-sourdough/

    Paul Oaten
    #26339

    Yes, and no error in the console. (I had previously seen in the issue before you enabled script debug).

    The two scripts should be functionally identical. One is just a compressed version of the other. So I’m surprised that the issue is still not there.

    Stephen Harris
    #26341

    Which browser are you using? I’m on Chrome

    Paul Oaten
    #26342

    I haven’t taken any other action except enabling SCRIPT_DEBUG

    I just tried loading the original page: https://www.panary.co.uk/craft-baking-courses/1-day-basic/

    and I’m now seeing the error again – ie. the field is missing.

    Paul Oaten
    #26345

    I’m using chrome too, and firefox. It’s still working for me.

    Based on the error message, it’s clearly having trouble retrieving the occurrence which contains a list of tickets for that occurrence. Try adding:

        console.log( parseInt( id, 10 ) );
        console.log( this.get('occurrences') );
        console.log( result );
    

    To line 416 (line above the return in the get_occurrence()). That will give us a bit more information to work with.

    Stephen Harris
    #26348

    Hi Stephen,

    I have added those lines.

    If you click a few courses from the course calendar page, at some point the qty field should appear and then disappear.

    It’s behaving like that on this page for me:
    https://www.panary.co.uk/craft-baking-courses/1-day-nordic-germanic/

    Paul Oaten
    #26352

    I was able to find an event where I could see this issue, and I’ve determined what is causing it. One some of the events the occurrence IDs, in the json data, are strings not integers.

    It’s not clear to me exactly why that is happening for some events, but as a quick fix you can add the following to line 639 of event-organiser-pro/includes/booking-tickets.php:

    foreach ( $remaining_tickets as $occurrence_id => $ticket ) {
        $remaining_tickets[ $occurrence_id ][ 'id' ] = (int) $ticket['id'];
    }
    

    To give some context, it should then look like::

    //Extract the occurrences we're interested in
    $remaining_tickets = array_intersect_key( $remaining_tickets , array_flip( $occurrence_ids  ) );
    foreach ( $remaining_tickets as $occurrence_id => $ticket ) {
        $remaining_tickets[ $occurrence_id ][ 'id' ] = (int) $ticket['id'];
    }
    return $remaining_tickets;
    

    This should fix the issue (though I’ve not been able to replicate it on a test install), but doesn’t explain why some IDs are strings not integers. So I’ll be in touch, if that’s ok, to see if we can some (non-disruptive) investigation the site to establish exactly what’s happening.

    Stephen Harris
    #26354

    Hi Stephen,

    thanks for that.
    I have added the code and spot-checked a few pages and all looks normal.
    I also notice that the page loads somewhat faster. Not sure if that’s significant?

    Very happy to investigate further. I’ll wait to hear from you.
    Thanks for the support to get the fix in place.

    Paul Oaten
    #27283

    Hi Stephen,

    I have this same issue again. Probably because I updated the plugin recently and forgot to add the line of code mentioned before to the plugin.

    Are you still planning to investigate further?

    Paul Oaten
    #27284

    I’ve added the extra lines of code back and it’s fixed for now but only until the next update, obviously.

    Paul Oaten
Viewing 14 posts - 1 through 14 (of 14 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.