summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPedro Cambra2012-10-26 10:30:45 (GMT)
committer Pedro Cambra2012-10-26 10:30:45 (GMT)
commit25d18499e216d0482b696141adb141097fef6aed (patch)
tree3a7370b4fcad6b01d365103749b32a761b91e7cc
parent7532fc1d5f2504dd09319d4c0a71884b49b3da87 (diff)
Issue #1780290 by idflood, krlucas: Fixed Coupons with duplicate codes can be created.
-rw-r--r--commerce_coupon_ui.module9
-rw-r--r--includes/commerce_coupon_ui.forms.inc8
2 files changed, 10 insertions, 7 deletions
diff --git a/commerce_coupon_ui.module b/commerce_coupon_ui.module
index 6565730..9a3dee7 100644
--- a/commerce_coupon_ui.module
+++ b/commerce_coupon_ui.module
@@ -40,9 +40,8 @@ function commerce_coupon_ui_menu() {
$items['admin/commerce/coupons/add/' . strtr($type, array('_' => '-'))] = array(
'title' => 'Create !name',
'title arguments' => array('!name' => $coupon_type->label),
- 'page callback' => 'drupal_get_form',
'page callback' => 'commerce_coupon_ui_coupon_form_wrapper',
- 'page arguments' => array(commerce_coupon_create($type)),
+ 'page arguments' => array(commerce_coupon_create($type), 'add'),
'access callback' => 'commerce_coupon_access',
'access arguments' => array('create', $type),
);
@@ -53,7 +52,7 @@ function commerce_coupon_ui_menu() {
$items['admin/commerce/coupons/%commerce_coupon'] = array(
'title' => 'Edit',
'page callback' => 'commerce_coupon_ui_coupon_form_wrapper',
- 'page arguments' => array(3),
+ 'page arguments' => array(3, 'edit'),
'access callback' => 'entity_access',
'access arguments' => array('update', 'commerce_coupon', 3),
'weight' => 0,
@@ -247,14 +246,14 @@ function theme_commerce_coupon_ui_add_list($variables) {
* @param $coupon
* The coupon object being edited by this form.
*/
-function commerce_coupon_ui_coupon_form_wrapper($coupon) {
+function commerce_coupon_ui_coupon_form_wrapper($coupon, $op = NULL) {
// Add the breadcrumb for the form's location.
commerce_coupon_ui_set_breadcrumb();
// Include the forms file from the Coupon module.
module_load_include('inc', 'commerce_coupon', 'includes/commerce_coupon_ui.forms');
- return drupal_get_form('commerce_coupon_form', $coupon);
+ return drupal_get_form('commerce_coupon_form', $coupon, $op);
}
/**
diff --git a/includes/commerce_coupon_ui.forms.inc b/includes/commerce_coupon_ui.forms.inc
index 4a5bd90..1ffb855 100644
--- a/includes/commerce_coupon_ui.forms.inc
+++ b/includes/commerce_coupon_ui.forms.inc
@@ -52,12 +52,16 @@ function commerce_coupon_form_validate(&$form, &$form_state) {
form_set_error('is_active', t('You can\'t enable a coupon of a coupon type that is disabled'));
}
- if ($form_state['op'] == 'add') {
+ if ($form_state['op'] == 'add' || $form_state['op'] == 'edit') {
$lang_code = field_language('commerce_coupon', $form_state['commerce_coupon'], 'commerce_coupon_code');
if (isset($form_state['values']['commerce_coupon_code'][$lang_code][0]['value'])) {
$coupon_code = $form_state['values']['commerce_coupon_code'][$lang_code][0]['value'];
if (!empty($coupon_code) && commerce_coupon_code_exists($coupon_code)) {
- form_set_error('commerce_coupon_code][' . $lang_code, t('This coupon code is already in use.'));
+ // Don't invalidate duplicate code if we are simply updating one.
+ if ($form_state['op'] == 'add' || (isset($coupon->commerce_coupon_code) &&
+ $coupon->commerce_coupon_code[$lang_code][0]['value'] != $coupon_code)) {
+ form_set_error('commerce_coupon_code][' . $lang_code, t('This coupon code is already in use.'));
+ }
}
}
}