I have a site which uses Commerce Subscription Products to sell upgraded membership roles. The module functions properly when a subscription is purchased, and I have rules set to grant and revoke roles based on subscription expiration. The only problem arises when a non-subscribing (or expired subscriber) saves their profile.

My error logs flag the following: "Notice: Uninitialized string offset: 0 in entity_metadata_field_property_get() (line 432 of /(site-name)/sites/all/modules/entity/modules/callbacks.inc)". and "Warning: Illegal string offset 'value' in entity_metadata_field_property_get() (line 432 of /(site-name)/sites/all/modules/entity/modules/callbacks.inc)".

If there are any existing user photos, they are deleted as well.

There are no problems whatsoever if a value is present in the field-commerce-sp-validity field (even if that date is expired). Once I run cron and the field is subsequently set to null, the issues appear.

I have seen multiple similar issue threads, but no resolutions which I could identify that work in this case. The symptoms are same as https://drupal.org/node/1760994 which is closed as duplicate of https://drupal.org/node/1554050. The resolution indicated is that applying weight=3 to the "Apply bought subscription time" rule resolves, but this patch is applied and the "Uninitialized string offset: 0 in entity_metadata_field_property_get() (line 432" and above log errors still exist whenever a user without subscription is updated.

For a temporary workaround, I have disabled photos for user profiles and disabled error reporting to keep them from seeing the errors, but since this is a straightforward and readily duplicated problem, it seems there must be a resolution which I have not been able to locate.

Any advice would be greatly appreciated.

Comments

scflmark’s picture

Priority: Normal » Major
Issue summary: View changes
scflmark’s picture

Issue summary: View changes
m42’s picture

I fell into the same issue and I finally found a workaround : redefine a part of the field (the callback in charge of fetching the value) in order to remove the unnecessary array part that makes the field "partly-empty" when it is supposed to be totally empty.

<?php
/**
 * Implements hook_entity_property_info_alter()
 * 
 * @param string $info
 */
function my_module_entity_property_info_alter(&$info) {
  if(isset($info['user']['bundles']['user']['properties']['field_commerce_sp_validity'])){
    $info['user']['bundles']['user']['properties']['field_commerce_sp_validity']['getter callback'] = 'my_module_entity_metadata_field_property_get';
  }
}

/**
 * Rewrite of entity_metadata_field_property_get()
 * 
 * @param type $entity
 * @param array $options
 * @param type $name
 * @param type $entity_type
 * @param type $info
 * @return type
 */
function my_module_entity_metadata_field_property_get($entity, array $options, $name, $entity_type, $info){
  $field = field_info_field($name);
  $langcode = isset($options['language']) ? $options['language']->language : LANGUAGE_NONE;
  $langcode = entity_metadata_field_get_language($entity_type, $entity, $field, $langcode, TRUE);
  if (isset($entity->{$name}[$langcode])) {
    $firstChild = reset($entity->{$name}[$langcode]);
    if(empty($firstChild)){
      $entity->{$name}[$langcode] = array();
    }
  }
  
  return entity_metadata_field_property_get($entity, $options, $name, $entity_type, $info);
}
?>