Error on line 540 of Ubercart Donation Products

mshepherd - February 20, 2009 - 14:27
Project:Ubercart Donation Products
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hi, I'm getting the error:

warning: Invalid argument supplied for foreach() in /home/server/websites/drupal/illuminate/live/drupal-6.9/sites/wayc.illuminateweb.org.uk/modules/uc_donation/uc_donation.module on line 540.

after adding a donation product to the cart.

Seems to be associated with the attributes uc module and the error message does disappear when I disable the attributes module. However, as I'm using the attributes to denote whether gift aid can be reclaimed on the donation (uk charities can reclaim tax paid on donations from uk tax payers), I really need the attributes module.

I'm using Drupal 6.9, version 1.2.4.15 of this module and 6.x-2.0-beta4 of ubercart.

If I comment out lines 538-544 as follows, the error message disappears and my cart link (http://wayc.illuminateweb.org.uk/cart/add/e-p42_q1_a1o1-ifrom_footer_lin...) apparently still works and the item is added to the cart along with it's attributes/options.

536   $element['remove'] = array('#type' => 'checkbox');
537   $op_names = '';
538   //if (module_exists('uc_attribute')){
539   //  $op_names = "<ul class=\"cart-options\">\n";
540   //  foreach ($item->options as $option){
541   //    $op_names .= '<li>'. $option['attribute'] .': '. $option['name'] ."</li>\n";
542   //  }
543   //  $op_names .= "</ul>\n";
544   //}
545   $element['options'] = array('#value' => $op_names);
546   $element['title'] = array(
547     '#value' => l($node->title, 'node/'. $node->nid),
548   );

Not sure how to proceed. Any ideas?

Matthew

#1

Sid_M - February 20, 2009 - 19:58

The problem occurs when the item has no options. This is standard "feature" of PHP: i.e. that it does not fail quietly when one tries to do a foreach on something other than an array. Thus what one needs to do is make sure it is an array before running the loop. I suggest modifying line 538 to read as follows:

if (module_exists('uc_attribute') && isset($item->options) && is_array($item->options)){

Obviously, I am assuming that there is no error involved when an item has no options.

#2

mshepherd - February 20, 2009 - 22:44

Hi,
Thanks for your reply.
In fact, the item does have attributes and options and these are correctly added to the cart.

??
Matthew

#3

greenSkin - March 12, 2009 - 22:48
Status:active» fixed

Code has been changed based on code from uc_product.module.

#4

System Message - March 26, 2009 - 22:50
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.