diff --git a/includes/commerce_coupon.checkout_pane.inc b/includes/commerce_coupon.checkout_pane.inc
index 47024c2..af34b08 100644
--- a/includes/commerce_coupon.checkout_pane.inc
+++ b/includes/commerce_coupon.checkout_pane.inc
@@ -47,92 +47,103 @@ function commerce_coupon_pane_settings_form($checkout_pane) {
* Checkout pane callback: coupon checkout form.
*/
function commerce_coupon_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
- // Allow to replace pane content with ajax calls.
- $pane_form = array(
- '#prefix' => '
',
- '#suffix' => '
',
- );
- // Store the payment methods in the form for validation purposes.
- $pane_form['coupon_code'] = array(
- '#type' => 'textfield',
- '#title' => t('Coupon Code'),
- '#description' => t('Enter your coupon code here.'),
- );
+ $query = new EntityFieldQuery();
+ // Get all active commerce coupons
+ $result = $query->entityCondition('entity_type', 'commerce_coupon')
+ ->propertyCondition('status', 1, "=")
+ ->execute();
- $pane_form['coupon_add'] = array(
- '#type' => 'button',
- '#value' => t('Add coupon'),
- '#name' => 'coupon_add',
- '#limit_validation_errors' => array(),
- '#ajax' => array(
- 'callback' => 'commerce_coupon_add_coupon_callback',
- 'wrapper' => 'commerce-checkout-coupon-ajax-wrapper',
- ),
- );
+ if(!empty($result)) {
+
+ // Allow to replace pane content with ajax calls.
+ $pane_form = array(
+ '#prefix' => '',
+ '#suffix' => '
',
+ );
+
+ // Store the payment methods in the form for validation purposes.
+ $pane_form['coupon_code'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Coupon Code'),
+ '#description' => t('Enter your coupon code here.'),
+ );
+
+ $pane_form['coupon_add'] = array(
+ '#type' => 'button',
+ '#value' => t('Add coupon'),
+ '#name' => 'coupon_add',
+ '#limit_validation_errors' => array(),
+ '#ajax' => array(
+ 'callback' => 'commerce_coupon_add_coupon_callback',
+ 'wrapper' => 'commerce-checkout-coupon-ajax-wrapper',
+ ),
+ );
- $error = '';
- if (isset($form_state['triggering_element']) && $form_state['triggering_element']['#name'] == 'coupon_add') {
- $code = $form_state['input']['commerce_coupon']['coupon_code'];
- if (!empty($code)) {
- $coupon = commerce_coupon_redeem_coupon_code($code, $order, $error);
+ $error = '';
+ if (isset($form_state['triggering_element']) && $form_state['triggering_element']['#name'] == 'coupon_add') {
+ $code = $form_state['input']['commerce_coupon']['coupon_code'];
+ if (!empty($code)) {
+ $coupon = commerce_coupon_redeem_coupon_code($code, $order, $error);
- if ($coupon) {
- // Clear the field value so that the coupon code does not get
- // resubmitted causing an error when user uses main "Continue to next
- // step" submit.
- $pane_form['coupon_code']['#value'] = '';
+ if ($coupon) {
+ // Clear the field value so that the coupon code does not get
+ // resubmitted causing an error when user uses main "Continue to next
+ // step" submit.
+ $pane_form['coupon_code']['#value'] = '';
- // Reload the order so it is not out of date.
- $order = commerce_order_load($order->order_id);
+ // Reload the order so it is not out of date.
+ $order = commerce_order_load($order->order_id);
- // Recalculate discounts.
- commerce_cart_order_refresh($order);
+ // Recalculate discounts.
+ commerce_cart_order_refresh($order);
+ }
+ }
+ else {
+ $error = t('Please enter a code.');
}
- }
- else {
- $error = t('Please enter a code.');
- }
- if (!$error) {
- // If a coupon was invalidated during the cart refresh (e.g. if its
- // discounts failed their conditions), an error message will have been
- // set.
- $error = &drupal_static('commerce_coupon_error_' . strtolower($code));
- }
+ if (!$error) {
+ // If a coupon was invalidated during the cart refresh (e.g. if its
+ // discounts failed their conditions), an error message will have been
+ // set.
+ $error = &drupal_static('commerce_coupon_error_' . strtolower($code));
+ }
- if (!$error) {
- // Allow modules/rules to act when a coupon has been successfully added
- // to the cart.
- rules_invoke_all('commerce_coupon_applied_to_cart', $coupon, $order);
+ if (!$error) {
+ // Allow modules/rules to act when a coupon has been successfully added
+ // to the cart.
+ rules_invoke_all('commerce_coupon_applied_to_cart', $coupon, $order);
+ }
+ else {
+ drupal_set_message($error, 'error');
+ }
}
- else {
- drupal_set_message($error, 'error');
+
+ // Extract the View and display keys from the cart contents pane setting.
+ $pane_view = variable_get('commerce_coupon_checkout_pane_view', 'order_coupon_list|checkout');
+ if ($pane_view != 'none') {
+ list($view_id, $display_id) = explode('|', $pane_view);
+ if (!empty($view_id) && !empty($display_id) && views_get_view($view_id)) {
+ $pane_form['redeemed_coupons'] = array(
+ '#type' => 'markup',
+ '#markup' => commerce_embed_view($view_id, $display_id, array($order->order_id)),
+ );
+ }
}
- }
- // Extract the View and display keys from the cart contents pane setting.
- $pane_view = variable_get('commerce_coupon_checkout_pane_view', 'order_coupon_list|checkout');
- if ($pane_view != 'none') {
- list($view_id, $display_id) = explode('|', $pane_view);
- if (!empty($view_id) && !empty($display_id) && views_get_view($view_id)) {
- $pane_form['redeemed_coupons'] = array(
+ // Display any new status messages added by this pane within the pane's area.
+ if (isset($form_state['triggering_element']) && $form_state['triggering_element']['#name'] == 'coupon_add'
+ && drupal_get_messages(NULL, FALSE)) {
+ $pane_form['status_messages'] = array(
'#type' => 'markup',
- '#markup' => commerce_embed_view($view_id, $display_id, array($order->order_id)),
+ '#markup' => theme('status_messages'),
+ '#weight' => -1,
);
}
+ } else {
+ $pane_form = '';
}
-
- // Display any new status messages added by this pane within the pane's area.
- if (isset($form_state['triggering_element']) && $form_state['triggering_element']['#name'] == 'coupon_add'
- && drupal_get_messages(NULL, FALSE)) {
- $pane_form['status_messages'] = array(
- '#type' => 'markup',
- '#markup' => theme('status_messages'),
- '#weight' => -1,
- );
- }
-
return $pane_form;
}