The uid field in uc_recurring_users table is saving the uid of the user that created the order and not the user that owns the fee.

That means that recurring fees will not show up in a user account if the order was purchased anonymously or created by an admin.

Comments

univate’s picture

Status: Active » Fixed

This is the fix which I've committed.

--- uc_recurring.module	13 Sep 2009 05:51:56 -0000	1.1.4.29
+++ uc_recurring.module	13 Sep 2009 08:47:21 -0000
@@ -305,6 +305,22 @@ function uc_recurring_product_feature() 
   return $features;
 }
 
+/**
+ * Implementation of hook_uc_checkout_complete().
+ *
+ * This function is require to complete recurring orders for anonymous
+ * purchases as the uid is not set until the order has completed checkout.
+ */
+function uc_recurring_uc_checkout_complete($order, $account) {
+  $fees = uc_recurring_get_fees($order);
+  foreach ($fees as $fee) {
+    if ($fee->uid == 0) { // check for anonymous uid
+      $fee->uid = $order->uid;
+      uc_recurring_fee_user_save($fee);
+    }
+  }
+}
+
 /*******************************************************************************
  * API functions
  ******************************************************************************/

vitis’s picture

thank you

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

fortis’s picture

sorry for my english.

It doesn't work for me, when anonymous purchase product then reccuring tab is not visible in profile after authorization. Because fee creates with uid == 0.

In univate patch:

+function uc_recurring_uc_checkout_complete($order, $account) {
+  $fees = uc_recurring_get_fees($order); // THERE uc_recurring_get_fees($order) get empty array :(

And in uc_recurring_order.module i see that in function uc_recurring_order_process_order $order->uid == 0

function uc_recurring_order_process_order($order, $recurring) {
  if (variable_get('uc_recurring_order_enabled', TRUE)) {
    $payment_method = !empty($order->payment_method) ? $order->payment_method : 'default';
    if (!($fee_handler = uc_recurring_get_recurring_info($payment_method))) {
      drupal_set_message(t('A handler for processing and renewing recurring fees cannot be found for the @payment-method payment method.', array('@payment-method' => $order->payment_method)), 'error');
      return FALSE;
    }

    // Create a new fee object.
    $fee = new stdClass();
    $fee->uid = $order->uid; // THERE, $order->uid is 0 ! =)

How can I force it work?

ps: i tried last version - 2.x

i think it's need to update uc_recurring_users with uid=0 by order_id when user creates in ubercart... now i know only uc_cart patch method ^^)

univate’s picture

This is issue was closed committed over a year ago, if you have a question or issue it would be best to create a new issue.

What you are seeing is absolutely correct, when the recurring fee is first created it will have a uid of 0 as there is no user in the system yet. When the order completes and the user has been created the ubercart hook in uc_recurring hook_uc_checkout_complete() is called and corrects this uid value.

shaundychko’s picture

Status: Closed (fixed) » Closed (duplicate)

Just a note that $fees in #1 is always NULL on anonymous checkout since uc_recurring hasn't yet saved the recurring fee for the $order at the time this function is called. I posted a patch here http://drupal.org/node/1423482#comment-5829842 to get the uid for anonymous checkout into the uc_recurring_users table.