Skip to content

Commit

Permalink
fix: query to find coupon is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
lelinhtinh committed Nov 29, 2022
1 parent b7f5d87 commit 681161c
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions public/class-coupon-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,16 @@ public function save_coupon()
global $wpdb;

$findOne = $wpdb->get_row($wpdb->prepare(
"
SELECT
c.ID, c.limit,
COUNT(cu.user_id) AS number_of_uses, GROUP_CONCAT(cu.user_id SEPARATOR ',') AS used_by_id
"SELECT c.ID, c.limit,
COUNT(cu.user_id) AS number_of_uses, GROUP_CONCAT(cu.user_id SEPARATOR ',') AS used_by_id
FROM {$wpdb->prefix}oms_coupons AS c
LEFT JOIN {$wpdb->prefix}oms_coupons_user AS cu ON cu.oms_coupon_id = c.ID
LEFT JOIN {$wpdb->prefix}oms_coupons_user AS cu ON cu.oms_coupon_id = c.ID
WHERE
c.ID = %d AND c.active = 1
AND ( ( c.activated_at IS NOT NULL AND c.activated_at < '%s' ) OR c.activated_at IS NULL )
AND ( ( c.expired_at IS NOT NULL AND c.expired_at > '%s' ) OR c.expired_at IS NULL )
c.ID = %1\$d AND c.active = 1
AND ( ( c.activated_at IS NOT NULL AND c.activated_at < '%2\$s' ) OR c.activated_at IS NULL )
AND ( ( c.expired_at IS NOT NULL AND c.expired_at > '%2\$s' ) OR c.expired_at IS NULL )
GROUP BY c.ID, c.limit
HAVING c.limit > number_of_uses
",
HAVING c.limit > number_of_uses",
$coupon_id,
$now,
), OBJECT);
Expand Down

0 comments on commit 681161c

Please sign in to comment.