I just now upgraded from rc6 of Ubercart to rc7 and for some reason i'm getting this error.

[code]
* warning: Invalid argument supplied for foreach() in C:\websites\tlservices\ic\sites\all\modules\ubercart\uc_attribute\uc_attribute.module on line 472.
* warning: Invalid argument supplied for foreach() in C:\websites\tlservices\ic\sites\all\modules\ubercart\uc_attribute\uc_attribute.module on line 472.
[/code]

I haven't changed my php install in any way so I don't understand why something that was suppressed is now throwing a warning. as far as I can tell on that line, the $item->data['attribute'] is coming out as NULL, which is curious on why it didn't throw a warning previously but is now throwing 2 warnings.

I uninstalled and re-installed the module (i know this causes me to re-make my attributes and options, but I'm in development phase so i'm not worried), but the warnings are still there.

I'm putting an if statement to detect the null before the foreach and not run the foreach loop if it is null.

CommentFileSizeAuthor
#15 587958_item_attributes.patch596 bytesIsland Usurper

Comments

leon kessler’s picture

I'm getting the same error (although mine being on line 471 for some reason).

Is there a way to fix this or a patch coming out? Should I try an older version of Ubercart?

Island Usurper’s picture

What are you doing when this error shows up? I needs me some context.

leon kessler’s picture

It happens whenever the Attributes module is enabled, it appears as soon as I enable the module and on every page throughout the drupal site.

Thanks

Island Usurper’s picture

I bet the errors will go away if you empty out your cart. That's not a perfect solution, though, because the code should be making sure that items in the cart have at least an empty array of attributes first.

aaronbauman’s picture

Nope, emptying the cart, then clearing the cache, then re-adding doesn't fix it.

Island Usurper’s picture

If you look in the database table uc_cart_products, does the data column have the word "attributes" in it? What kind of gibberish comes right after it?

aaronbauman’s picture

there is no "attributes" index in the serialized array.
Here is the contents of the data column of a particular row:

a:10:{s:10:"ticket_sku";s:7:"Org-Reg";s:11:"ticket_name";s:32:"Registration for an Organization";s:11:"ticket_type";s:1:"1";s:12:"ticket_price";s:3:"195";s:12:"ticket_limit";s:2:"20";s:14:"ticket_enabled";s:1:"1";s:12:"ticket_start";s:1:"0";s:10:"ticket_end";s:1:"0";s:3:"nid";s:4:"9596";s:6:"module";s:10:"uc_product";}

(ticket_* indexes are from my own module).

In fact i'm not even *using* any attributes, which is partly why this is so disconcerting.

Island Usurper’s picture

Ah, but if the attributes module is enabled, there should at least be spot for it in the data array. That's why I told you to empty your cart. When you added the products back to the cart, the attribute module should have put an empty array there. I would review your ticket module to make sure it isn't overwriting the cart item's data array at any point. It should try to only add stuff to it.

torgospizza’s picture

I had the same issue; emptying the cart worked.

aaronbauman’s picture

My module is not overwriting the cart item's data array at any point,
but it is adding the item manually (I'm constructing my own data array without any "attribute" index).
Is there a method other than uc_cart_add_item I should be using to add my own item?
I thought I was doing this right before, so before I re-rtfm, can you point me to a good resource?
Thanks for your help, IU.

graper’s picture

I think the only reason mine was on a different line was I had gone in there to put in a line to output what was in the variable if anything to the watchdog.

Granville

graper’s picture

Island Usurper

My only problem with this statement is that this notice shouldn't be popping up just because the module is turned on. If having an item in the cart can product an object without the attribtues element shouldn't this be tested for and prevented? Think about like this. I have to turn on the module/upgrade UC on a live production site and I have to empty all the carts out there before customers get back to the site to see the message? that doesn't sit well with me and I don't think you want your customers being mad when the cart they just filled up and needed to come back to and finalize for purchase finds it gone.

Granville

Island Usurper’s picture

Assigned: Unassigned » Island Usurper

aaronbauman, when you use uc_cart_add_item(), the $data parameter should populated with module_invoke_all('add_to_cart_data', $form_state['values']). hook_add_to_cart_data() is where uc_attribute adds the attributes array. It does that based on the attribute fields in the add to cart form. Since you're putting the product into the cart manually, you can fake the form values with

  $form_values = array(
    'nid' => $nid,
    'qty' => $qty,
  );

graper, yeah, the easiest solution is just to not assume that the attributes will be in the data array. I'll write a patch up and post it.

tommeir’s picture

Hi there,

I get this error on a fresh install of drupal 6.14 and UC2rc7.
I have only one product node and even though attributes is enabled it has no say with it.
The error appears even if the cart is empty.

pls help this error is driving me crazy.

Island Usurper’s picture

Status: Active » Needs review
StatusFileSize
new596 bytes

Here's a patch.

fenstrat’s picture

Status: Needs review » Reviewed & tested by the community

That simple cast does the job.

Island Usurper’s picture

Status: Reviewed & tested by the community » Fixed

Great. Committed. Thanks.

Status: Fixed » Closed (fixed)

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