wonder32 / woocommerce-notification

woocommerce sound notification
1 stars 1 forks source link

Just stopped working #1

Open ghost opened 5 years ago

ghost commented 5 years ago

Hi, I just want to let you know that the plugin has just stopped working yesterday, out of the blue. No auto-updates, no changes, just new orders and notifications stopped appearing. I'm still trying to determine what's happened.

Regards

wonder32 commented 5 years ago

Hi Sirmacik. I have some maintenance/update planned towords wp5.0 and woocommerce updates. If you can send any errors (console/ wp debug) this would be helpfull looking into your issue. Could be your browser cache.. let me know.

ghost commented 5 years ago

After plugin reinstillation there was a warning, but I fixed it with setting the sound and saving new settings. There is nothing else. I can't be cache thing because it doesn't working in every browser I've tried. It's loaded with the orders page but doesn't do anything. I need to get it working ASAP but I'm out of the ways to debug the problem :/

ghost commented 5 years ago

It's like it stopped setting last_order in browser data.

ghost commented 5 years ago

looks like I got into a corner case, when order was deleted and no longer present on the screen, somehow it stopped updating.

You'll find attached currently working version of the order_notification.js

   function append_button() {
        jQuery('.subsubsub').before(
            "<div class='notification_container'>" +
            "<a class='button button-primary button-hero button-notification' href='#' id='stop_notification'><strong>Stop</strong></a>" +
            "</div>");

    }
    jQuery(document).ready(function (jQuery) {

        var playing = false;

        var cur_ord = window.localStorage.getItem('last_order');

        var first_order = jQuery('#the-list tr').first().attr('id').replace('post-', '');

        if (first_order != undefined && cur_ord != null && first_order > cur_ord) {
            var diff = (first_order - cur_ord);
            jQuery('embed').remove();
            if (notification.sound != undefined) {
                jQuery('body').append('<audio id="notification" src="' + notification.sound + '" preload="auto" loop="true"></audio>');
                playing = true;
                var sound = document.getElementById('notification');
                sound.play();
            }

            window.localStorage.setItem('last_order', cur_ord);
            append_button();

            for (var i = 0; i < diff; i++) {
                jQuery('#the-list tr[id="post-' + (first_order - i) + '"]').css('background-color', 'orange');
            }
        }

        if ((cur_ord == null) || (jQuery('#the-list tr[id="post-' + cur_ord + '"]').length == 0 )) {
            window.localStorage.setItem('last_order', first_order);
        }

        if (!playing) {
            setTimeout(function () {
                window.location.reload();
            }, 30000);
        }

        jQuery('.wrap').on('click', '#order_notification', function () {
            if (sound != undefined) {
                sound.pause();
            }

            if (diff != undefined && diff > 0) {

                var last_order = window.localStorage.getItem('last_order');

                for (var i = 0; i < diff; i++) {
                    var order_url = jQuery('#the-list tr[id="post-' + (last_order - i) + '"] td[class^="order_title"]').find('a').first().attr('href');
                    window.open(order_url);
                }
            }
            window.localStorage.setItem('last_order', first_order);
            jQuery('.notification_container').fadeOut('slow', function () {
                window.location.reload();
            });

        });

        jQuery('.wrap').on('click', '#stop_notification', function () {
            if (sound != undefined) {
                sound.pause();
            }
            window.localStorage.setItem('last_order', first_order);
            jQuery('.notification_container').fadeOut('slow', function () {
                window.location.reload();
            });

        });

    });
wonder32 commented 5 years ago

Thank you for your help!. I updated the plugin. It compares all last rows to the current. New orders will be highlighted. The script is better documentated. PLease backup your custom version if you decide to update.

wonder32 commented 5 years ago

https://www.puddinq.com/plugins/woocommerce-notification/

ghost commented 5 years ago

Great, thank you! I'll be able to test it this weekend and will let you know.