Re: Re: Re: Re: Re: I run on the bleeding edge

Posts: 320
Joined: 08/07/2007
Administrator

Hmm, I think at this point Wise you should start dropping debug statements in the uc_roles_order in uc_roles.module. When the workflow condition triggers the order status change uc_roles_order should be triggered. This is what you'll see:

<?php
function uc_roles_order($op, $order, $status) {
  global
$user;

  switch (
$op) {
    case
'update':
     
$order_user = user_load(array('uid' => $order->uid));
      if (
$order->uid > 0 && $order_user !== FALSE) {
       
// Check each product for a product role.
       
foreach ($order->products as $product) {
         
$roles = db_query("SELECT * FROM {uc_roles_products} WHERE nid = %d", $product->nid);
          while (
$role = db_fetch_object($roles)) {
           
// Grant (or renew) role upon successful completion of payment
           
if ($role->model == $product->model || empty($role->model)) {
              if (
$status == variable_get('uc_roles_default_order_status', 'completed')) {
               
$existing_role = db_fetch_object(db_query("SELECT * FROM {uc_roles_expirations} WHERE uid = %d AND rid = %d", $order_user->uid, $role->rid));
                if (!
is_null($existing_role->expiration)) {
                 
$op = 'renew';
                 
$comment = t('Customer user role %role renewed.', array('%role' => _get_role_name($role->rid)));
                }
                else {
                 
$op = 'grant';
                 
$comment = t('Customer granted user role %role.', array('%role' => _get_role_name($role->rid)));
                }

               
$quantity = ($role->by_quantity) ? $product->qty : 1;
               
_role_action($op, $order_user, $role->rid, _get_expiration_date(($role->duration * $quantity), $role->granularity, $existing_role->expiration));

               
$new_expiration = db_fetch_object(db_query("SELECT * FROM {uc_roles_expirations} WHERE uid = %d AND rid = %d", $order_user->uid, $role->rid));
               
uc_order_comment_save($order->order_id, $user->uid, $comment);
               
_role_email_user($op, $order_user, $new_expiration, $order);
               
$order_user = user_load(array('uid' => $order->uid));
              }
            }
          }
        }
      }
      break;
  }
}
?>

Placing a drupal_set_message("Your message or variables"); on one of these lines will let you know that the code is being executed at this point. If you've reached the code past if ($status == variable_get('uc_roles_default_order_status', 'completed')) { you should have the role assigned. Insert a couple of these statements, run a couple of test purchases, and let us know the results.

--

-Shawn Conn: If the Name Don't Rhyme It Ain't Mine

Role Assignment Not Happening Upon Order Completion By: WiSeOz (24 replies) Sat, 03/08/2008 - 00:07