When I upgraded a buyer to add a new role on purchase i get two entries in the watchdog log.

Adding bill to role .
Adding bill to role subscriber.

The role being added is "subscriber", but it appears a blank watchdog entry gets added, cluttering up the log. I don't think there are any critical side effects from this.

Offending code starts around line 922:

   // If PAID - add user to role, else drop 'em
    if ($add_to_roles) {
      foreach($on_payment_roles as $rid => $rname) {
        if (!isset($u->roles[$rid])) {
          watchdog('ecommerce', t('Adding %name to role %role.', array('%name' => theme('placeholder', $u->name), '%role' => theme('placeholder', $roles[$rid]))));
          $u->roles[$rid] = '';
        }
      }
      user_save($u, array('roles' => $u->roles));
    }
CommentFileSizeAuthor
#1 store.module_1.patch804 bytesdvdweide

Comments

dvdweide’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new804 bytes

The empty 'role' is caused by the drupal variable "on_payment_roles" which is an array of all available roles with the roleid as key and the roleid or 0 as value. This array gets flipped (array_flip) which creates a key 0 if not all available roles were selected.

The result is that the buyer also gets added to the non-existing role 0.

A simple solution is checkin $rid for zero values. See attached patch!

Cheers, Danny

dvdweide’s picture

Version: 4.7.x-1.x-dev » master

BTW, it also occurs in cvs
Danny

sime’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @dvdweide, applied to CVS. Won't backport as it is not critical
http://drupal.org/cvs?commit=36360

Anonymous’s picture

Status: Fixed » Closed (fixed)