foreach() error after removing product from cart

Project: 
Ubercart
Category: 
bug report
Priority: 
normal
Status: 
active

I am not sure if this should be under Issue Tracker or Forum -> Bug Reports. I have posted it there as well. Please let me know if I have done this in error and feel free to delete one or the other if necessary. I will close this out when the issue is solved.

Re: foreach() error after removing product from cart

Hmm... not happening on the Livetest. Are you running Alpha 8, and are you using any contributed Ubercart modules that might affect this?

Re: Re: foreach() error after removing product from cart

Yesterday I upgraded to Alpha 8 and I have the following modules installed:

ubrowser-5.x-1.2
uc_coupon-5.x-1.2.tar.gz
uc_inventory_api_1.6.zip
uc_stats_0.zip

and

uc_catalog_grid with the following change

In uc_catalog_grid.module function theme_uc_catalog_grid_browse()
FROM
$catalog = uc_catalog_get_page($args);
TO
$catalog = uc_catalog_get_page($args[0]);

Thanks for the quick response!

Re: Re: Re: foreach() error after removing product from cart

I'd suspect one of your contributed modules, like uc_inventory_api, that may be performing some action based on the cart contents without checking for an empty cart first. Try disabling these one by one to find the culprit.

Re: Re: Re: Re: foreach() error after removing product from cart

I continue to narrow down this problem using the devel module and backtrace. To reproduce the problem I do the following:

1) login
2) add a product to my cart
3) remove the product from my cart
4) logout
5) login

This is the a portion of the backtrace I received

These calls

uc_cart_user UPDATE white_uc_cart_products SET cart_id = 1 WHERE cart_id = '9bdmnrvk4k8glk78j68ppm0nd5'

uc_cart_get_contents SELECT c.*, n.title, n.vid FROM white_node n INNER JOIN white_uc_cart_products c ON n.nid = c.nid WHERE c.cart_id = '1'

taxonomy_node_get_terms_by_vocabulary SELECT t.tid, t.* FROM white_term_data t INNER JOIN white_term_node r ON r.tid = t.tid WHERE t.vid = 2 AND r.nid = 13 ORDER BY weight

uc_cart_user DELETE FROM white_uc_cart_products WHERE cart_id = 1

produce these errors (Notice the strange cart_id in the first call. The backtrace shows where c.cart_id is set but not cart_id) Could this be a typo?

warning: Invalid argument supplied for foreach() in /var/www/users/rustridge/drupal/modules/node/node.module on line 521.
warning: implode() [function.implode]: Bad arguments. in /var/www/users/rustridge/drupal/modules/node/node.module on line 525.

with these calls to watchdog

watchdog INSERT INTO white_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (1, 'php', 'Invalid argument supplied for foreach() in /var/www/users/rustridge/drupal/modules/node/node.module on line 521.', 2, '', 'http://www.racehorsewhite.com/user/login?destination=node', 'http://www.racehorsewhite.com/', '64.81.145.219', 1194545822)

watchdog INSERT INTO white_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (1, 'php', 'implode() [<a href='function.implode'>function.implode</a>]: Bad arguments. in /var/www/users/rustridge/drupal/modules/node/node.module on line 525.', 2, '', 'http://www.racehorsewhite.com/user/login?destination=node', 'http://www.racehorsewhite.com/', '64.81.145.219', 1194545822)

This call

node_load SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM white_node n INNER JOIN white_users u ON u.uid = n.uid INNER JOIN white_node_revisions r ON r.vid = n.vid WHERE

produces this error message (Notice the missing n.nid = "some value" after the WHERE clause on the select statement above.)

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: node_load SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM white_node n INNER JOIN white_users u ON u.uid = n.uid INNER JOIN white_node_revisions r ON r.vid = n.vid WHERE in /var/www/users/rustridge/drupal/includes/database.mysql.inc on line 172

with this call to watchdog

watchdog INSERT INTO white_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (1, 'php', 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1\nquery: node_load\nSELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM white_node n INNER JOIN white_users u ON u.uid = n.uid INNER JOIN white_node_revisions r ON r.vid = n.vid WHERE in /var/www/users/rustridge/drupal/includes/database.mysql.inc on line 172.', 2, '', 'http://www.racehorsewhite.com/user/login?destination=node', 'http://www.racehorsewhite.com/', '64.81.145.219', 1194545822)

and these calls

drupal_lookup_path SELECT dst FROM white_url_alias WHERE src = 'erp/stock/cart_confirm'

uc_product_forms SELECT nid FROM white_uc_products

uc_product_kit_forms SELECT DISTINCT nid FROM white_uc_product_kits

produce this error

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'stock_add_to_cart' was given in /var/www/users/rustridge/drupal/includes/form.inc on line 217.

with this call to watchdog

watchdog INSERT INTO white_watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (1, 'php', 'call_user_func_array() [<a href='function.call-user-func-array'>function.call-user-func-array</a>]: First argument is expected to be a valid callback, 'stock_add_to_cart' was given in /var/www/users/rustridge/drupal/includes/form.inc on line 217.', 2, '', 'http://www.racehorsewhite.com/user/login?destination=node', 'http://www.racehorsewhite.com/', '64.81.145.219', 1194545822)

Since the product was removed from the cart before logout I would think the cart should be empty upon loging in again. Even if it is not I don't think this is being handled properly.

Much thanks to the developers of the devel package!

Any help in solving this would be appreciated.

Thanks