5

I am using Drupal 7 and ubercart roles where I have given the role expiration period of 1 day, and with that role the user can create one node. I want that as soon as the new node is created the role expiration should be deleted.

I am able to remove the role through rules but as the expiration period is still set, it cannot be re-assigned the role the same role if the user purchases the same role again,

Is there any way to remove the role expiration of ubercart?

thanks for any help.

1
1

It seems that you are removing the role through the drupal standard rules. Try calling the own uc_ubercart function to better compatibility.

/**
 * Deletes an expiration using user id or user id and rid.
 *
 * This function deletes expirations associated with users and roles. If
 * no role ID is passed, the function deletes all role expirations associated
 * with the given user. Otherwise, the function only deletes expirations whose
 * user and role IDs match. If any roles were actually deleted, the function
 * notifies the user. The menu cache is then flushed, as privileges to view
 * menu items may have been lost in the process.
 *
 * @param $account
 *   A Drupal user object.
 * @param $rid
 *   A Drupal role ID.
 * @param $silent
 *   When set to TRUE will suppress any Drupal messages from this function.
 */
uc_roles_delete($account, $rid = NULL, $silent = FALSE) {}

An example with custom module (without rules):

https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_insert/7

/**
 * Implements hook_node_insert().
 */
function mymodule_node_insert($node) {

  if ($node->type == 'customtype') {
    $rid = 3; //@TODO: set rol ID
    $account = user_load($node->uid);
    // Delete UC Role!
    uc_roles_delete($account, $rid, TRUE);
  }

}

You can also use this code on the rules action PHP but I prefer the hook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.