Role Assignment Not Happening Upon Order Completion

Posts: 48
Joined: 12/05/2007

I have the role assignment feature configured to assign a certain role upon order "Completion" status. I have the rule configuration activated in Workflow-ng to update the order status to "Completion" once the payment is received (balance equal to or less than $0.00). I have a product created that has the product feature. I fumble through a test transaction of that product using WPS in the PayPal sandbox. I am returned to the "Order completed" screen and given a username and password. I check the order status and see that it is "Pending" still and no role assignment was ever made.

Help! I am going live very soon and need to get a successful test of Ubercart. Thanks!

Posts: 46
Joined: 01/22/2008

It's because it's just "pending," right? You said that you have it set to assign the role at "completion." Those are two different states. Right?

Dan

Posts: 781
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

Sounds like that's the case. Make sure your Workflow-ng config for order completion is enabled.

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 48
Joined: 12/05/2007

That's what's even stranger ... Workflow-ng is enabled. Here is the export of that rule configuration.

array (
  'uc_payment_received' =>
  array (
    '#weight' => '0',
    '#altered' => true,
    '#type' => 'configuration',
    '#active' => 1,
    '#label' => 'Update order status on full payment',
    '#event' => 'payment_entered',
    '#module' => 'uc_payment',
    0 =>
    array (
      '#type' => 'condition',
      '#name' => 'uc_payment_condition_balance',
      '#argument map' =>
      array (
        'order' => 'order',
      ),
      '#settings' =>
      array (
        'balance_comparison' => 'less_equal',
      ),
      '#id' => 2,
    ),
    1 =>
    array (
      '#type' => 'action',
      '#name' => 'uc_order_action_update_status',
      '#argument map' =>
      array (
        'order' => 'order',
      ),
      '#settings' =>
      array (
        'order_status' => 'completed',
      ),
      '#id' => 3,
      '#label' => 'Update the order status',
    ),
    '#id' => 1,
    '#name' => 'uc_payment_received',
  ),
)

Posts: 48
Joined: 12/05/2007

My role assignment feature is set up to assign the role upon order "Complete" status. My Workflow-NG rule configuration for "Update order status on full payment" is set up and activated to update the order to "Complete" status upon $0.00 or less balance. I have a membership product which includes the role assignment feature.

When running tests of the purchase of the membership product, the order is successfully updated to "Complete" upon payment receipt however the role assignment is not automatically occurring. For some strange reason, I can get the role assignment to occur if I manually update an order from "Pending" to "Complete". So, seems there is an issue with the magic happening in the automatic role assignment.

Posts: 15
Joined: 01/12/2008

This is also the problem I'm now having.

Anybody have any suggestions on what to try?

WiSeOz, are you still having this problem, or were you able to fix it?

Posts: 48
Joined: 12/05/2007

This is still a problem for me and I am just 12 days from launching my site (April 1st target date).

I also have this issue open in the Drupal.org Uberacrt queue but it isn't getting any attention either: http://drupal.org/node/234781

I've tried creating my own Workflow-NG rules to force a role assignment for my membership product type but it's still not happening. I also tried using "Pending" as the trigger for the role assignment rather than "Complete" but still no luck.

Can anyone help?

Posts: 1595
Joined: 08/07/2007
AdministratoreLiTe!

I was able to set up a role product that granted the role when the order was completed. The credit card was processed through the Test gateway, and a Workflow-ng configuration updated the status when payment was received. The only difference I can see was that the condition about the balance was set to be equal to $0 instead of less than or equal. I don't really think that would cause it to not work, though.

Sorry, but I can't duplicate this bug.

Posts: 15
Joined: 01/12/2008

Hi Lyle,

Thank you for checking into it.

I am running Ubercart 5.x-1.0-beta6, can you tell me which version you are running?

Also, would it be possible for you to export your Workflow-ng configuration and post it here for us?

The only other variant for me that may factor in is the subscriptions contrib, which I also have installed and configured.

Cheers,

TC

Posts: 1595
Joined: 08/07/2007
AdministratoreLiTe!

I run on the bleeding edge of the code development, but roles shouldn't have changed too much since beta 7.

This was a custom configuration because I didn't see the one defined by uc_payment. That one was inactive, so it wouldn't have interfered, but I may have just duplicated what it does.

array (
  'cfg_10' =>
  array (
    '#type' => 'configuration',
    '#altered' => false,
    '#event' => 'payment_entered',
    '#label' => 'Complete order on even balance',
    '#active' => 1,
    '#module' => 'workflow-ng',
    0 =>
    array (
      '#type' => 'condition',
      '#name' => 'uc_payment_condition_balance',
      '#argument map' =>
      array (
        'order' => 'order',
      ),
      '#settings' =>
      array (
        'balance_comparison' => 'equal',
      ),
      '#label' => 'Balance is $0',
    ),
    1 =>
    array (
      '#type' => 'action',
      '#name' => 'uc_order_action_update_status',
      '#argument map' =>
      array (
        'order' => 'order',
      ),
      '#settings' =>
      array (
        'order_status' => 'completed',
      ),
    ),
    '#name' => 'cfg_10',
  ),
)

Posts: 48
Joined: 12/05/2007

I gave this another try by importing Lyle's configuration. Unfortunately, the results remain the same.

However, I'm not clear why we think the workflow-ng rule config is to blame. The rule is working as advertised. My orders are definitely being updated to "complete" status based on my rule configuration. Isn't the problem with uc_role instead? I've told uc_role (via the Product Settings -> Role Assignments) to assign a certain role upon the order being updated to "complete".

Lyle, did your test include a default expiration of "never"?

Posts: 1595
Joined: 08/07/2007
AdministratoreLiTe!

Yeah, I used the "never" expiration.

I wanted to look at the Workflow-ng part first because it seemed like it would be more likely to be the part that failed. The hook_order() in uc_roles looks like it should work because the workflow action would cause it to happen.

Posts: 3197
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Ok, on the Livetest I set roles to be added on the completed status and I adjusted the workflow configuration for payments received to move orders to completed. I received the role w/ a 1 year expiration just fine.

In other words, we can't replicate the bug. We'll need you to verify that you're on the latest code, and then if we're to debug it further we'll just have to get an inside look at your site. I'd double check your role product feature itself to make sure you selected the right role to add.

Posts: 48
Joined: 12/05/2007

Three screen shots attached to show my set up.

I have confirmed that I am on Ubercart Beta 7 and uc_roles shows as Beta 7 as well.

I can give you system access immediately. Do you need to access to just the site or the system directories as well? I can send access information to you as a private message.

AttachmentSize
Workflow-ngRule.PNG19.74 KB
ProductFeature.PNG26.5 KB
RoleAssignmentSetup.PNG24.64 KB
Posts: 15
Joined: 01/12/2008

I'll test this out later as well. I'll just update to the latest code first and see if that helps.

Thanks for all your hard work, it's greatly appreciated.

Cheers,

TC

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

Posts: 48
Joined: 12/05/2007

Okay. Updates ... I spent about 4 hours working on this problem this morning and believe I have a workaround to meet my needs but it does not resolve the true issue with uc_roles completing the role assignment successfully. Below is a summary of actions I've taken and the results found.

1. On Beta 7 ... Ran many, many tests with debug code applied in various ways. The debug code never really produced anything in the log beyond the array from the IPN transaction. Every test I ran successfully updated the order status to "complete" but failed to assign the role.

2. On Beta 7 ... I started to get creative and created my own custom rule configuration to assign the role. Through Devel, I found that my conditions for "uc_order_condition_has_products" and "uc_cart_condition_product_class" where always evaluating to FALSE when they should have been considered TRUE for my membership product that was being purchased. So, even my custom rule was not being processed correctly. An export of that rule configuration is below.


array (
'cfg_23' =>
array (
'#id' => 1,
'#module' => 'workflow-ng',
'#type' => 'configuration',
'#weight' => '0',
'#altered' => false,
'#active' => 1,
'#event' => 'checkout_complete',
'#label' => 'Assign Uber Membership Role',
0 =>
array (
'#type' => 'condition',
'#id' => 2,
'#name' => 'uc_order_condition_order_status',
'#settings' =>
array (
'order_status' => 'completed',
),
'#argument map' =>
array (
'order' => 'order',
),
),
2 =>
array (
'#type' => 'OR',
'#id' => 3,
0 =>
array (
'#type' => 'condition',
'#id' => 4,
'#name' => 'uc_order_condition_has_products',
'#settings' =>
array (
'required' => '',
'forbidden' => '0',
'products' =>
array (
368 => '368',
382 => '382',
),
),
'#argument map' =>
array (
'order' => 'order',
),
),
1 =>
array (
'#type' => 'condition',
'#name' => 'uc_order_condition_has_products',
'#argument map' =>
array (
'order' => 'order',
),
'#settings' =>
array (
'required' => '0',
'forbidden' => '',
'products' =>
array (
368 => '368',
382 => '382',
),
),
'#id' => 5,
),
2 =>
array (
'#type' => 'condition',
'#name' => 'uc_cart_condition_product_class',
'#argument map' =>
array (
'order' => 'order',
),
'#settings' =>
array (
'class' => 'membership',
),
),
),
1 =>
array (
'#type' => 'action',
'#id' => 6,
'#name' => 'workflow_ng_action_user_addrole',
'#settings' =>
array (
'roles' =>
array (
0 => 7,
1 => 4,
),
),
'#argument map' =>
array (
'account' => 'user',
),
),
'#name' => 'cfg_23',
),
)

3. I decided to upgrade to the latest Bizarre version.

4. On the Bazaar version ... I ran tests with my custom rule configuration disabled to test whether the Bazaar version of uc_role would actually assign the role. All tests produced the same results as #1 above.

5. On the Bazaar version ... I ran tests with my custom rule configuration activated to test whether my conditions would now be evaluated correctly with the Bazaar version. These tests were indeed successful! My custom rule configuration (shown above) was now being evaluated correctly with the Bazaar version installed.

So, all that said, my workaround is to use my custom rule configuration and not rely on uc_roles to handle the role assignment.

Let me know if there is anything more I can do to help you troubleshoot the uc_roles issue, however, I've got to be somewhat conservative with experiments given my go-live is one week away.

Posts: 15
Joined: 01/12/2008

Thanks for posting this info. I haven't had time to test yet on my server, but I'll take a look at it this week and see if I can get things working also.

Posts: 3197
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Also, in WiseOz's database there were duplicate rows for order statuses... this could have been causing some of the trouble. Puzzled Not entirely sure, but you might check your DB just to make sure this isn't the case.

Posts: 17
Joined: 03/27/2008

I am getting the exact same problem as WiseOz - where do I look to see if I have duplicate rows for oder statuses?

Tim

Posts: 17
Joined: 03/27/2008

Assuming this is in the 'uc_order-statuses' table - there are no duplicate records in there.....

Where do I go from here?

BTW I'm using Drupal 5.7 with Ubercart 5.x-1.0-beta7

Tim

Posts: 3197
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

Hey Tim, I'm pretty sure your issue is separate, so I'll respond in your other thread.

Posts: 15
Joined: 01/12/2008

Hi guys,

Today I upgraded Ubercart to the lastest version, and everything is working great.

I did a test with the credit cart test gateway and everything worked perfectly and the proper role was assigned.

I didn't change anything else with my configuration, so I guess there was some issue with the version I had installed previously, or the installation.

Cheers,

TC

Posts: 23
Joined: 11/01/2007

What version are you using?

Your issue seems similar to my file download issue, so perhaps it's a version issue. I am using Beta7.

Anne

Posts: 15
Joined: 01/12/2008

Hi Anne,

I updated with 5.x-1.0-rc2. http://drupal.org/project/ubercart

Cheers,

TC