I'll have to double check my current settings and update you, but I was getting an error about a bad query statement as it was including a where clause that filters out node ids that are already in the cart. However, if there are no products in the cart the list of nids is empty leaving the where clause as "NID NOT IN ()" which mysql doesn't like...

Easy solution, add an if statement to determine if the $filter_query string is set or not... ~line 215 in uc_upsell_core.inc...

The existing:

      $randoms = db_query("SELECT `nid`
                  FROM {node}
                  WHERE `status` = 1
                  AND `type` IN ('". implode("','", uc_product_product_types()) ."')
                  AND NOT nid IN (". $filter_query .")
                  ORDER BY RAND()");

Should be changed to:

    if ($filter_query) {
      $randoms = db_query("SELECT `nid`
                  FROM {node}
                  WHERE `status` = 1
                  AND `type` IN ('". implode("','", uc_product_product_types()) ."')
                  AND NOT nid IN (". $filter_query .")
                  ORDER BY RAND()");
    } else {
      $randoms = db_query("SELECT `nid`
                  FROM {node}
                  WHERE `status` = 1
                  AND `type` IN ('". implode("','", uc_product_product_types()) ."')
                  ORDER BY RAND()");
    }
CommentFileSizeAuthor
#4 779004.patch2.87 KBtorgospizza
#3 uc_upsell_core.inc_.patch1.21 KBstroobl

Comments

webspring’s picture

Thanks, this worked for me

ericwongcm’s picture

Status: Active » Reviewed & tested by the community

My site have the same issue....in my news aggregator

http://www.hdmp4.com/aggregator/sources/

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 ') ORDER BY RAND()' at line 5 query: SELECT `nid` FROM node WHERE `status` = 1 AND `type` IN ('product') AND NOT nid IN () ORDER BY RAND() in /home/portabl/public_html/modules/ubercart/uc_upsell/uc_upsell_core.inc on line 215.

By using tcindie's code above, it fixed the issue.

Hopefully, torgosPizza (Upsell's author) will read this issue soon and fix it in the code.

Thanks

stroobl’s picture

StatusFileSize
new1.21 KB

Seems to work for me too.
I made a patch with the change.

torgospizza’s picture

StatusFileSize
new2.87 KB

Thanks for the patch!

I actually changed it a bit. Instead of just finding all product types in uc_product_product_types(), it needs to use the settings from Upsell itself. Here's the modified patch. Will commit this asap.

torgospizza’s picture

Status: Reviewed & tested by the community » Needs review
johnnymast’s picture

Has the module package been updated already ?.

torgospizza’s picture

No, not yet. I got sidetracked again. Will put out a dev release, at least, soon.

torgospizza’s picture

This change was commited to the 6.x-1.x-dev branch and will be in the next version (1.22 and 2.x)

torgospizza’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

sarjeet.singh’s picture

Status: Closed (fixed) » Fixed

Thanks for patch. I faced same problem.

torgospizza’s picture

Status: Fixed » Closed (fixed)

So I'll set this back to closed, then. (You did not need to change this issue's Status.) Thanks for letting me know.