Question

I have been developing a custom recurring order script for a client in x-cart, the problem I'm facing is when the recurring order (cron) triggers and loops the orders scheduled, the order doesn't appear to reset to nothing, it attempts to use the previous order's IDs. I thought I got around this, but now it uses the first order's details as the customer details for all orders following the daily process.

$orderids = func_place_order(stripslashes($payment_method), 'I', $order_details, @$customer_notes, array(), array(), @$delivery_notes, TRUE);

The last paramater is a custom one, here's the snippit on where it is used ($bol_ignore) - in func.order.php

$check_order = func_query_first("SELECT orderid FROM $sql_tbl[orders] WHERE userid='" . addslashes(@$userinfo['id']) . "' AND '" . XC_TIME . "'-date < '$mintime'");

    if ($bol_ignore == FALSE) // @custom ***** code, may prevent the order from being broken?
        if ($check_order) {
            func_unlock('place_order');

            return FALSE;
        }

After it has cheched whether the payment was successful or not, we call in func_change_order_status() to change the status respectively.

I assume that I must be missing something to 100% clear the order, cart and any session control that xcart may be using before it moves onto process the next one. I have even used x_session_reset() in the loop just in case, and reset all the vars at the beginning of the loop.

Thanks in advance.

Was it helpful?

Solution

After a few hours wasted and massive amounts of debug, I was missing a global variable that was needed. As the customer is not logged in, we need to manually set each of these global variables.

I was pulling the customer info from the database, but it was being saved in a different variable name.

$userinfo = func_userinfo($row['customerid'], 'C');

Just in case anyone wants to attempt this in the future, you must have these set for each loop as they are required for an order/cart to take place

# Change the "session" types 
$login_type   = 'C';
$current_area = 'C';
$cart         = NULL; // Clear the Cart

I know the question was pretty vague, but we thought that it came down to xcart's built in functions taking over.

The things you find out after a fresh cup of coffee..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top