Its a warning, not sure how or why, but something to do with weight:

After modifying a product:

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 'weight' at line 12 query: SELECT d.* FROM uc_discounts d LEFT JOIN uc_discounts_products dp ON d.discount_id=dp.discount_id LEFT JOIN uc_discounts_terms dt ON d.discount_id=dt.discount_id LEFT JOIN uc_discounts_skus ds ON d.discount_id=ds.discount_id LEFT JOIN uc_discounts_classes dcl ON d.discount_id=dcl.discount_id WHERE d.requires_code=0 AND (d.has_role_filter=0 OR d.discount_id IN(SELECT dr.discount_id FROM uc_discounts_roles dr, users_roles ur WHERE (dr.role_id=ur.rid AND ur.uid=1) OR dr.role_id=-1 OR dr.role_id=2)) AND (d.filter_type<>1 OR dp.product_id IN(-1,66)) AND (d.filter_type<>2 OR dt.term_id IN(-1,4)) AND (d.filter_type<>3 OR ds.sku IN('','esl-1')) AND (d.has_expiration=0 OR d.expiration>0) ORDER BY d.1255908631 weight in /var/www/vhosts/eventpolicy.com/httpdocs/sites/all/modules/ubercart/contrib/uc_discounts_alt/uc_discounts/uc_discounts.module on line 1641.

CommentFileSizeAuthor
#5 patch-v2.txt2.06 KBnoahlively
#4 patch.txt109.09 KBnoahlively

Comments

ezra-g’s picture

Status: Needs review » Active

Thanks for the bug report. I'm marking this as active, since there is no patch to review here.

noahlively’s picture

The bug is in the query defined on line 1626

$query = sprintf("SELECT d.* FROM {uc_discounts} d
		LEFT JOIN {uc_discounts_products} dp ON d.discount_id=dp.discount_id
		LEFT JOIN {uc_discounts_terms} dt ON d.discount_id=dt.discount_id
		LEFT JOIN {uc_discounts_skus} ds ON d.discount_id=ds.discount_id
		LEFT JOIN {uc_discounts_classes} dcl ON d.discount_id=dcl.discount_id
		WHERE d.requires_code=0
		AND (d.has_role_filter=0%s)
		AND (%s)
		AND (%s)
		AND (%s)
		AND (d.has_expiration=0 OR d.expiration>%d)
		ORDER BY d.%s %s", $roles_clause, $product_ids_clause, $term_ids_clause, $skus_clause, $classes_clause, time(),
    $sort_column, $sort_order_string
  );

There are 7 tokens in the sprintf template and 8 actual tokens passed. The missing token should be a 4th "AND (%S)" inside the query template, as follows:

AND (%s)

I tested with this change and it works.

ezra-g’s picture

Status: Active » Needs work

Thanks for pointing this out. Could you file a patch? http://drupal.org/patch

noahlively’s picture

StatusFileSize
new109.09 KB

ezra-g,

I've rolled a patch and attached. Unfortunately, it seems that my line indentation is different than what was used in the original file. So you are going to see a lot more changes in the patch than this bug fix.

What IDE did you build this in? Perhaps I can download a copy, re-format the code, and roll another patch.

Thanks,
Noah

noahlively’s picture

StatusFileSize
new2.06 KB

ezra-g,

Nevermind.... I was able to adjust Eclipse to indent with spaces rather than tabs. Attached is another patch.

Please note the following changes:

  • Line item processing code puts discount id in the "data" field of the line item record, which was previously unused in this module. This allows other modules to track what discount code was used in follow-up order processing routines.
  • Wrapped several array iterators in if statements, which prevents errors when the array doesn't exist.
  • Fixed the SQL code that prompted this thread.
DanielJohnston’s picture

Confirmed that patch at #5 removes error message.

ezra-g’s picture

Status: Needs work » Fixed

Looks good. Please be sure to mark issues as 'needs review' once you've re-rolled a patch. I missed this patch until just now ;). Committed. Thanks!

Status: Fixed » Closed (fixed)

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