From b223cbf8b2947bc96a6cfd17b0a1138fc8b1d2f6 Mon Sep 17 00:00:00 2001
From: Mohammad AlQanneh <mqanneh@gmail.com>
Date: Sun, 6 Dec 2015 17:12:10 +0200
Subject: [PATCH] Issue #2629800 by mqanneh: PDOException: When trying to empty
 an empty cart.

---
 ui/includes/tmgmt_ui.pages.inc | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/ui/includes/tmgmt_ui.pages.inc b/ui/includes/tmgmt_ui.pages.inc
index 8cf4c49..b7ff46f 100644
--- a/ui/includes/tmgmt_ui.pages.inc
+++ b/ui/includes/tmgmt_ui.pages.inc
@@ -950,9 +950,14 @@ function tmgmt_ui_cart_remove_selected_form_submit($form, &$form_state) {
  * Custom form submit callback for tmgmt_ui_cart_cart_form().
  */
 function tmgmt_ui_cart_empty_cart_form_submit($form, &$form_state) {
-  entity_delete_multiple('tmgmt_job_item', array_keys(tmgmt_ui_cart_get()->getJobItemsFromCart()));
-  tmgmt_ui_cart_get()->emptyCart();
-  drupal_set_message(t('All job items were removed from the cart.'));
+  $cart_items = tmgmt_ui_cart_get()->getJobItemsFromCart();
+  if (!empty($cart_items)) {
+    entity_delete_multiple('tmgmt_job_item', array_keys($cart_items));
+    tmgmt_ui_cart_get()->emptyCart();
+    drupal_set_message(t('All job items were removed from the cart.'));
+  } else {
+    drupal_set_message(t('You don\'t have any jobs in your cart.'), 'error');
+  }
 }
 
 /**
-- 
1.9.1

