Guess you already know this, but .... this module works *exactly* like what I want, which is kind of surprising given the errors:

Notice: Undefined variable: bundle in _uc_field_attribute_nodeapi() (line 18 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).
Notice: Undefined property: stdClass::$options in _uc_field_attribute_nodeapi() (line 71 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).
Warning: Invalid argument supplied for foreach() in _uc_field_attribute_nodeapi() (line 71 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).
Notice: Undefined property: stdClass::$options in _uc_field_attribute_nodeapi() (line 95 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).
Warning: Invalid argument supplied for foreach() in _uc_field_attribute_nodeapi() (line 95 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).
Notice: Undefined property: stdClass::$options in _uc_field_attribute_nodeapi() (line 71 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).
Warning: Invalid argument supplied for foreach() in _uc_field_attribute_nodeapi() (line 71 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).
Notice: Undefined property: stdClass::$options in _uc_field_attribute_nodeapi() (line 71 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).
Warning: Invalid argument supplied for foreach() in _uc_field_attribute_nodeapi() (line 71 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).
Notice: Undefined property: stdClass::$options in _uc_field_attribute_nodeapi() (line 95 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).
Warning: Invalid argument supplied for foreach() in _uc_field_attribute_nodeapi() (line 95 of /var/www/<oursite>/modules/contrib/uc_field_attribute/uc_field_attribute.inc).

Might fix these myself later but just throwing them out there ...

Comments

miiimooo’s picture

Might be that my php.ini settings are quite lax. Patch welcome!

RumpledElf’s picture

Actually we figured out what caused the errors - if you have an item made using this module already in your cart, and then you edit the product type, you get those lovely warnings.

So not as exciting as it seems (also explains why everything seemed to work just fine, barring messages), but there's the way to make the warnings go away! File this one away for future reference if anyone else has the same problem :)

squarecandy’s picture

Nice tip..
Got these errors too.
Guess I just need to remember not to put things in the cart with the same browser as admin while in development...

squarecandy’s picture

some other admins got these with nothing in their cart...
hmmm, maybe I'll roll a patch later this week.

michlis’s picture

Assigned: Unassigned » michlis
Status: Active » Needs review
StatusFileSize
new981 bytes

Hi,
It looks like there are two issues. One is with $bundle variable, it's never set before the IF so it gives warning.

   if (!$bundle)
      $bundle = field_extract_bundle('node', $node);
      $instances = field_info_instances('node', $bundle);
    }

In my patch I simply removed this IF, because I can't see any purpose for it.


Next problem is when attribute is created, 'options' method is not initialised, so it gives error later on when it's referenced directly in FOREACH loops e.g. $product_attribute->options. Simply initialise it as empty array:

  if (!$attribute) {
      $attribute = $instance;
      $attribute->display = 1;
      $attribute->name = $instance->field_name;
      $attribute->options = array();   //FIX
      uc_attribute_save($attribute);
      $attribute = (object) $attribute;
      $field_attribute = array(
        "aid" => $attribute->aid,
        "nid" => $node->nid,
        "field_instance_id" => $instance->id,
      );

Please review, thanks.

miiimooo’s picture

@michlis: thanks for the patch. Committed to 7.x-1.x

miiimooo’s picture

Version: 7.x-1.x-dev » 7.x-1.0
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.