• Resolved ouija

    (@ouija)


    Hi there,

    I just wanted to report an issue that I’ve been experiencing with WC-Vendors for quite some time, that I actually mananaged to resolve today after a lot of debugging.

    Basically, I was having issues with the Dashboard Orders Page around the Date Range selection and this not properly showing results/orders for a specified start_date and end_date range when submitting the page with the date range filter. If you ran the filter / submitted it a second time, it usually would work and then show orders for this specified range, but sometimes it would not.

    This was driving me nuts so I started investigating, and it was like the $_POST['start_date'] and $_POST['end_date'] were NOT being passed properly, but indeed they were.

    Then while debugging I discovered that the $_POST['start_date'] and $_POST['end_date'] values are defined via the /classes/class-queries.php page, and that the logic for setting and getting these date range values is actually incorrect and is what was causing my issues.

    More speicifically, I has to reverse the logic for this orders_within_range function so that it would SET the wcv_order_start_date and wcv_order_end_date session variables BEFORE it would GET them.

    This is the updated function that has fixed the issue for me and is working BEAUTIFULLY:

    
    public static function orders_within_range() {
        global $start_date, $end_date;
        
        if ( ! empty( $_POST['start_date'] ) ) {
            WC()->session->set( 'wcv_order_start_date', strtotime( $_POST['start_date'] ) );
        }
    
        if ( ! empty( $_POST['end_date'] ) ) {
            WC()->session->set( 'wcv_order_end_date', strtotime( $_POST['end_date'] ) );
        }
    
        $start_date = WC()->session->get( 'wcv_order_start_date', strtotime( current_time( 'Y-M' ) . '-01' ) );
        $end_date   = WC()->session->get( 'wcv_order_end_date', current_time( 'timestamp' ) );
    
        
    
        $after  = date( 'Y-m-d', $start_date );
        $before = date( 'Y-m-d', strtotime( '+1 day', $end_date ) );
    
        return apply_filters(
            'wcvendors_orders_date_range',
            array(
                'after'  => $after,
                'before' => $before,
            )
        );
    }
    

    Hope this helps anyone else from pulling thier hair out trying to debug a similar issue!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Jamie

    (@digitalchild)

    Hi @ouija

    Can you outline exactly what your issue is so that I can try and repeat it on my end? You’re the first to have an issue with the date range in quite a while.

    Can you give me an example range so I can test it? Your code looks correct so I’d just like to know the testing parameters before I add this to our Github.

    thanks!

    Jamie.

    Thread Starter ouija

    (@ouija)

    Sure. Essentially the issue is that when you specify a range, it doesn’t always show orders the first time you submit for that range, because the original function is calling the WC()->session->set( ‘wcv_order_start_date’, strtotime( $_POST[‘start_date’] ) );
    and WC()->session->set( ‘wcv_order_end_date’, strtotime( $_POST[‘end_date’] ) ); AFTER it is GETTING that data, so because of this you actually end up needing to submit (filter) the data twice for it to work.

    Now, I should mention that I’m NOT using the original date-picker.php that ships with the plugin, but I’m still setting the values using $_POST[‘start_date’] and $_POST[‘end_date’] values on the orders page, and I had to reverse the order of the WC()->session->set and WC()->session->get definitions within the orders_within_range() function in this /classes/class-queries.php to fix the issue with having to submit the data twice in order for it to actually set the WC session values properly.

    Hopefully I explained that well enough! Maybe it works fine as is with the original datepicker, but for my method, having this logic reversed fixed issues with having to submit twice in order for data to appear.

    Jamie

    (@digitalchild)

    Hi @ouija

    I’ve just tried this on a couple of our demo environments and I can’t replicate it. Can test the original date picker to see if it works on your end?

    I still think your code is a better way to handle that function so I’ll do some more tests on my end with that new version.

    cheers,

    Jamie.

    Jamie

    (@digitalchild)

    Hi @ouija

    We’ve just merged this code into our master branch on GitHub. You can test it via our master here – https://github.com/wcvendors/wcvendors

    cheers,

    Jamie.

    Thread Starter ouija

    (@ouija)

    That is excellent! I’ll test it out as soon as I’m able to, appreciate you merging that change in as it will save me manually having to do the same with each update! ??

    Thanks again.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Vendor Orders Page – Date Query Bug’ is closed to new replies.