From: Chuck Scott Date: Fri, 20 Oct 2017 20:08:54 +0000 (-0400) Subject: Fixed problems with clearing items from the cart that don't belong there. X-Git-Tag: v1.0.0^2~326 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=fd5657bc855b0a27fef5b13a9eb2a094b10d8c0d;p=WP-Plugins%2Fglm-member-db-registrations.git Fixed problems with clearing items from the cart that don't belong there. Fixed probelm with cart not being assigned to an account when it's a guest cart and the account just loggs in. Added "select other Carts" to cart widget. Other front-end cleanip. --- diff --git a/classes/data/dataRegRequest.php b/classes/data/dataRegRequest.php index fa8d9e1..8194654 100644 --- a/classes/data/dataRegRequest.php +++ b/classes/data/dataRegRequest.php @@ -329,13 +329,6 @@ class GlmDataRegistrationsRegRequest extends GlmDataAbstract 'use' => 'a' ), - // Any MagicForm data associated with registrant - 'mf_data' => array ( - 'field' => 'mf_data', - 'type' => 'text', - 'use' => 'a' - ), - // System operator's notes for this registration request 'notes' => array ( 'field' => 'notes', @@ -432,6 +425,40 @@ class GlmDataRegistrationsRegRequest extends GlmDataAbstract } + /** + * Get registration request list simplified + * + * @param string $where Where clause to filter list + * @param boolean $getStats Flag to get additional stats for cart + * + * @return object Class object + */ + public function getRegRequestListSimplified($where = false, $getStats = false) + { + + $savedFields = $this->fields; + $savedPostProcess = $this->postProcRegRequest; + + if ($getStats) { + $this->postProcRegRequest = true; + } + + $this->fields = array( + 'id' => $savedFields['id'], + 'account_fname' => $savedFields['account_fname'], + 'account_lname' => $savedFields['account_lname'], + 'status' => $savedFields['status'], + 'last_update' => $savedFields['last_update'] + ); + + $requestsSimplified = $this->getList($where); + $this->fields = $savedFields; + $this->postProcRegRequest = $savedPostProcess; + + return $requestsSimplified; + + } + } diff --git a/classes/data/dataRegRequestEvent.php b/classes/data/dataRegRequestEvent.php index d6e1774..ababa7a 100644 --- a/classes/data/dataRegRequestEvent.php +++ b/classes/data/dataRegRequestEvent.php @@ -151,14 +151,6 @@ class GlmDataRegistrationsRequestEvent extends GlmDataAbstract 'use' => 'lg' ), - // Selected Start Time - 'event_datetime' => array ( - 'field' => 'event_datetime', - 'type' => 'datetime', - 'required' => true, - 'use' => 'lgneud' - ), - // System operator's notes for this registration request 'notes' => array ( 'field' => 'notes', diff --git a/classes/regCartSupport.php b/classes/regCartSupport.php index f466ad0..27c16ea 100644 --- a/classes/regCartSupport.php +++ b/classes/regCartSupport.php @@ -104,11 +104,13 @@ class GlmRegCartSupport $res = $this->wpdb->insert( GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_request', array( - 'account' => $account, - 'validated' => false, - 'user_trace_info' => $_SERVER["REMOTE_ADDR"]." - ".date("m/d/Y H:i:s") + 'account' => $account, + 'validated' => false, + 'status' => $this->config['submission_status_numb']['CART'], + 'user_trace_info' => $_SERVER["REMOTE_ADDR"]." - ".date("m/d/Y H:i:s") ), array( + '%d', '%d', '%d', '%s' @@ -191,7 +193,7 @@ class GlmRegCartSupport return $this->cart; } - // Check if the person looking at this cart is permitted to do so + // Check if the person looking at this cart is not permitted to do so if (!$this->checkRequestingAccount($requestId)) { return $this->cart; } @@ -347,6 +349,7 @@ class GlmRegCartSupport $eventCharges = 0; $eventDiscounts = 0; $removeEvent = false; + $deleteEventNow = false; $haveClasses = false; $this->cart['events'][$eventKey]['removed'] = false; @@ -369,6 +372,7 @@ class GlmRegCartSupport $classCharges = 0; $classDiscounts = 0; $removeClass = false; + $deleteClassNow = false; $haveRates = false; $this->cart['events'][$eventKey]['classes'][$classKey]['removed'] = false; @@ -388,6 +392,7 @@ class GlmRegCartSupport $rateRegistrantCharges = 0; $rateDiscounts = 0; $removeRate = false; + $deleteRateNow = false; $haveRegistrants = false; $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['removed'] = false; @@ -459,6 +464,7 @@ class GlmRegCartSupport if (!$haveRegistrants) { $this->cart['messages'][] = 'Rate '.$rate['rate_name'].' has no registrants.'; $removeRate = true; + $deleteRateNow = true; } @@ -492,6 +498,10 @@ class GlmRegCartSupport } + if ($deleteRateNow) { + unset($this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]); + } + } // Each Rate } // Have rates @@ -500,6 +510,7 @@ class GlmRegCartSupport if (!$haveRates) { $this->cart['messages'][] = 'Class '.$class['class_name'].' has no rates.'; $removeClass = true; + $deleteClassNow = true; } // If class has been flagged for removal from cart, delete it from cart in database @@ -527,6 +538,10 @@ class GlmRegCartSupport } + if ($deleteClassNow) { + unset($this->cart['events'][$eventKey]['classes'][$classKey]); + } + } // Each class } // Have Classes @@ -535,6 +550,7 @@ class GlmRegCartSupport if (!$haveClasses) { $this->cart['messages'][] = 'Event '.$event['event_name'].' has no classes.'; $removeEvent = true; + $deleteEventNow = true; } // If has been flagged for removal from cart, delete it from cart in database @@ -562,6 +578,10 @@ class GlmRegCartSupport } + if ($deleteEventNow) { + unset($this->cart['events'][$eventKey]); + } + } // Each event } // Have events @@ -580,7 +600,7 @@ class GlmRegCartSupport // Check if Event Time exists in Events add-on -// echo "
".print_r($this->cart,1)."
"; + // echo "
".print_r($this->cart,1)."
"; // Check if no messages then cart validated if (count($this->cart['messages']) == 0) { @@ -662,22 +682,14 @@ class GlmRegCartSupport return false; } - // If the user is an WordPress administrator or we have contacts add-on and WordPress user with adequate permissions - if (current_user_can('administrator') && apply_filters('glm_members_menu_members', true)) { - return true; - } - // If there's no logged in registrations user if (!isset($_SESSION) || !isset($_SESSION['LoginAccount']) || !is_array($_SESSION['LoginAccount'])) { - // If it's a guest account and the request ID is in the current session - allow cart - if ($_SESSION['LoginAccount']['id'] == 0 && $_SESSION['glm_reg_cart_id'] == $requestId) { - return true; - } - } - echo "
".print_r($_SESSION,1).print_r($regRequest,1)."
"; - // If there's a logged in registrations user + + // echo "
".print_r($_SESSION,1).print_r($regRequest,1)."
"; + + // If there's a logged in registrations user (overrides any WordPress adminstrator or contact logins if (isset($_SESSION) && isset($_SESSION['LoginAccount']) && is_array($_SESSION['LoginAccount'])) { // If the registrations user owns the cart @@ -692,7 +704,7 @@ class GlmRegCartSupport $updated = $this->wpdb->update( GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX.'reg_request', array( - 'account' => $_SESSION['LogInAccount']['id'] + 'account' => $_SESSION['LoginAccount']['id'] ), array( 'id' => $requestId ), array( @@ -705,6 +717,20 @@ class GlmRegCartSupport } } + + // Otherwise no logged in registrations user + } else { + + // If the user is an WordPress administrator or we have contacts add-on and WordPress user with adequate permissions + if (!current_user_can('administrator') && apply_filters('glm_members_menu_members', true)) { + return true; + } + + // If it's a guest account and the request ID is in the current session - allow cart + if ($_SESSION['LoginAccount']['id'] == 0 && $_SESSION['glm_reg_cart_id'] == $requestId) { + return true; + } + } return false; @@ -939,6 +965,35 @@ class GlmRegCartSupport $RegRequest = new GlmDataRegistrationsRegRequest($this->wpdb, $this->config); $cartSummary = $RegRequest->getRegRequestSimplified($requestId, true); + $cartSummary['regRequests'] = false; + $cartSummary['haveOtherRequests'] = false; + + // If there's a logged in registrations user + if (isset($_SESSION) && isset($_SESSION['LoginAccount']) && isset($_SESSION['LoginAccount']['id'])) { + + $accountId = ($_SESSION['LoginAccount']['id'] - 0); + + // If it's a possibly valid account ID + if ($accountId > 0) { + + // Build where clause to get any other pending carts for this logged in registrations user + $where = " + T.account = $accountId + AND T.id != $requestId + AND T.status = ".$this->config['submission_status_numb']['CART']." + "; + + // Try to get the full list of pending carts for this user + $RegRequest = new GlmDataRegistrationsRegRequest($this->wpdb, $this->config); + $cartSummary['regRequests'] = $RegRequest->getRegRequestListSimplified($where); + + if ($cartSummary['regRequests'] && count($cartSummary['regRequests'])) { + $cartSummary['haveOtherRequests'] = true; + } + } + + } + return $cartSummary; } diff --git a/js/frontRegApp.js b/js/frontRegApp.js index fbcb3fe..455ae73 100644 --- a/js/frontRegApp.js +++ b/js/frontRegApp.js @@ -387,7 +387,7 @@ app.Views.Front.App = Backbone.View.extend({ }, events: { - 'click #glm-reg-cart-continue': 'continue', +// 'click #glm-reg-cart-continue': 'continue', }, continue: function(){ diff --git a/js/views/front/app.js b/js/views/front/app.js index 8eeb9cd..2f3c3ab 100644 --- a/js/views/front/app.js +++ b/js/views/front/app.js @@ -24,7 +24,7 @@ app.Views.Front.App = Backbone.View.extend({ }, events: { - 'click #glm-reg-cart-continue': 'continue', +// 'click #glm-reg-cart-continue': 'continue', }, continue: function(){ diff --git a/models/front/registrations/cart.php b/models/front/registrations/cart.php index 1ba6cd8..f086c89 100644 --- a/models/front/registrations/cart.php +++ b/models/front/registrations/cart.php @@ -134,7 +134,6 @@ class GlmMembersFront_registrations_cart extends GlmRegCartSupport } - $view = 'cart'; // Compile template data @@ -150,7 +149,7 @@ class GlmMembersFront_registrations_cart extends GlmRegCartSupport // echo "
".print_r($templateData,1)."
"; - // Return status, any suggested view, and any data to controller + // Return status, any suggested view, and any data to controller return array( 'status' => true, 'modelRedirect' => false, diff --git a/setup/databaseScripts/create_database_V0.0.15.sql b/setup/databaseScripts/create_database_V0.0.15.sql index 867f2eb..414f752 100644 --- a/setup/databaseScripts/create_database_V0.0.15.sql +++ b/setup/databaseScripts/create_database_V0.0.15.sql @@ -433,7 +433,7 @@ CREATE TABLE {prefix}reg_request_event ( reg_request INT NULL, -- Pointer to reg_request table reg_event INT NULL, -- Pointer to reg_event event_name TINYTEXT NULL, -- Name of Event so it will always be in the cart data - event_datetime DATETIME NULL, -- Date and time of event time selected so it will always be in the cart +-- event_datetime DATETIME NULL, -- Date and time of event time selected so it will always be in the cart -- mf_data TEXT NULL, -- Any MagicForm data associated with requested event notes TEXT NULL, -- System operator's notes for this registration request PRIMARY KEY (id), diff --git a/views/front/registrations/cart.html b/views/front/registrations/cart.html index 65a7ac8..7b4e060 100644 --- a/views/front/registrations/cart.html +++ b/views/front/registrations/cart.html @@ -20,7 +20,7 @@ -{if $haveCart} +{if $haveCart && $cart.haveEvents} {foreach $cart.events as $event} @@ -76,7 +76,7 @@ {else} - There was a problem locating the information for your request! + Your cart is empty. Please click "Register for Another Event" button above. {/if} diff --git a/views/front/registrations/cartLinkWidget.html b/views/front/registrations/cartLinkWidget.html index dec8427..f5d3a8b 100644 --- a/views/front/registrations/cartLinkWidget.html +++ b/views/front/registrations/cartLinkWidget.html @@ -2,7 +2,7 @@