Drupal ubercart uc_order_load() function returns same payment details

on

While i work in drupal 6 ubercart module, I faced some strange issue. Ubercart provides a function uc_order_load() to load order details from order id. Let’s see the problem and solution below.

uc_order_load() function usage

uc_order_load() is used to get the order details in a single object.

Syntax :-

  • uc_order_load($order_id);
  • parameter : $order_id = > We need to pass the order_id as the parameter, It returns the single order details at a time. when dynamic the order id to get the multiple order details. we need to use `while loop` or for each to fetch  the results at that time while passing the order id into that uc_order_load() function, we get the all the order details as per the order id’s. But it returns the payments details as duplicate for each order.

 

Reason Behind the issue

The uc_order_load() function hooks the multiple modules while returning the product data, payment details, line item listing and etc.Each dataset are coming under the modules `Invoke hook_order() in enabled modules like (uc_credit,uc_payment etc).

While invoke the uc_credit hook it calls uc_credit(‘load’, $order, $null);

Here ‘load’ is an another hook to invoke the uc_credit_cache() function. This function stores the array of payment dates for the uc_credit function. uc_credit_cache() function store the data but it does not reset it self or overwrite itself, without using the `clear` hook.

SOLUTION :
We need to use the unset() and uc_credit_cache(‘clear’) functions within the `while` or `foreach` loop to reset the data with in the function.

while ($result_variable=db_fetch_object($result_data_variable)) {																								
    uc_credit_cache('clear');											
    unset($order_datas_here);
    $order_datas_here = uc_order_load($result_variable->order_id);
    }

Hope it saves your time.

ZMYBYFKAC6MK