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
Comments
Comment #1
Sid_M commentedThe 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:
Obviously, I am assuming that there is no error involved when an item has no options.
Comment #2
mshepherd commentedHi,
Thanks for your reply.
In fact, the item does have attributes and options and these are correctly added to the cart.
??
Matthew
Comment #3
greenskin commentedCode has been changed based on code from uc_product.module.