Posted - 07/28/2026 : 13:26:50
I was noticing unintended behavior in a discount behavior. I asked Claude to figure it out and gave this as a summary: quote:
Subject: Bug in inccart.php — automatic discount minimum quantity compared against price instead of quantity
Summary: For automatic discounts (not coupon codes) that are restricted to specific categories or products (cpnSitewide=3, also affects cpnSitewide=1), the minimum-quantity condition compares the discount's cpnQuantity against the dollar total of the qualifying items instead of their quantity. This makes quantity-based bundle discounts trigger far too easily.
Location: vsadmin/inc/inccart.php, in the automatic-discount eligibility check (~line 1471 in our copy). The four stacked conditions read:
if( (($rs2['cpnType']==0 && $rs2['cpnThreshold']<=$totprice_ship) || ($rs2['cpnType']!=0 && $rs2['cpnThreshold']<=$totprice_prods)) && (($rs2['cpnType']==0 && $rs2['cpnThresholdMax']>$totprice_ship) || ($rs2['cpnType']!=0 && $rs2['cpnThresholdMax']>$totprice_prods) || $rs2['cpnThresholdMax']==0) && (($rs2['cpnType']==0 && $rs2['cpnQuantity']<=$totquant_ship) || ($rs2['cpnType']!=0 && $rs2['cpnQuantity']<=$totprice_prods)) && // <-- BUG (($rs2['cpnType']==0 && $rs2['cpnQuantityMax']>$totquant_ship) || ($rs2['cpnType']!=0 && $rs2['cpnQuantityMax']>$totquant_prods) || $rs2['cpnQuantityMax']==0) ){
On the third line, the cpnType!=0 branch uses $totprice_prods (price) where it should use $totquant_prods (quantity). The surrounding lines confirm the intent: the two threshold checks correctly use the price variables, and the max-quantity check on the fourth line correctly uses $totquant_prods.
Fix: change $totprice_prods to $totquant_prods in the marked condition.
Changed it on my version, but thought I would put it out there for the next update. Thanks!
Edited by - atlend on 07/28/2026 13:27:06
|