-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check all coupon that use the same code #1114
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,21 +57,21 @@ class wpsc_coupons { | |
* @param string code (optional) the coupon code you would like to use. | ||
* @return bool True if coupon code exists, False otherwise. | ||
*/ | ||
function wpsc_coupons($code = ''){ | ||
function wpsc_coupons($code = '') { | ||
global $wpdb; | ||
|
||
if ( empty( $code ) ) | ||
return false; | ||
|
||
$this->code = $code; | ||
|
||
$coupon_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_COUPON_CODES."` WHERE coupon_code = %s LIMIT 1", $code ) , ARRAY_A ); | ||
|
||
if ( ( $coupon_data == '' ) || ( $coupon_data == null ) || ( strtotime( $coupon_data['expiry'] ) < time() ) ) { | ||
$this->errormsg = true; | ||
wpsc_delete_customer_meta( 'coupon' ); | ||
return false; | ||
} else { | ||
$coupons_data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_COUPON_CODES."` WHERE coupon_code = %s", $code ) , ARRAY_A ); | ||
foreach($coupons_data as $key => $coupon_data) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing here, too. See http://make.wordpress.org/core/handbook/coding-standards/php/#space-usage |
||
|
||
if ( ( $coupon_data == '' ) || ( $coupon_data == null ) || ( strtotime( $coupon_data['expiry'] ) < time() ) ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be done with yoda conditionals. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, consider removing some of the unnecessary brackets: |
||
continue; | ||
$coupon_data = array_merge( array( | ||
'value' => '', | ||
'is-percentage' => '', | ||
|
@@ -95,10 +95,18 @@ function wpsc_coupons($code = ''){ | |
$this->every_product = $coupon_data['every_product']; | ||
$this->errormsg = false; | ||
$valid = $this->validate_coupon(); | ||
$items = $this->get_eligible_items(); | ||
|
||
return $valid; | ||
if ( empty( $items ) ) | ||
continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be wrapped with braces.
See http://make.wordpress.org/core/handbook/coding-standards/php/#brace-style. |
||
|
||
if($valid) | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here:
|
||
} | ||
|
||
|
||
$this->errormsg = true; | ||
wpsc_delete_customer_meta( 'coupon' ); | ||
return false; | ||
} | ||
|
||
/** | ||
|
@@ -758,4 +766,4 @@ function uses_coupons() { | |
|
||
|
||
} | ||
?> | ||
?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be spaced out a bit more:
$wpdb->prepare( 'SELECT * FROM
' . WPSC_TABLE_COUPON_CODES . 'WHERE coupon_code = %s', $code )