Fixed problems with clearing items from the cart that don't belong there.
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 20 Oct 2017 20:08:54 +0000 (16:08 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 20 Oct 2017 20:08:54 +0000 (16:08 -0400)
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.

classes/data/dataRegRequest.php
classes/data/dataRegRequestEvent.php
classes/regCartSupport.php
js/frontRegApp.js
js/views/front/app.js
models/front/registrations/cart.php
setup/databaseScripts/create_database_V0.0.15.sql
views/front/registrations/cart.html
views/front/registrations/cartLinkWidget.html
views/front/registrations/checkout.html

index fa8d9e1..8194654 100644 (file)
@@ -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;
+
+    }
+
 
 }
 
index d6e1774..ababa7a 100644 (file)
@@ -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',
index f466ad0..27c16ea 100644 (file)
@@ -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 "<pre>".print_r($this->cart,1)."</pre>";
+        // echo "<pre>".print_r($this->cart,1)."</pre>";
 
         // 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 "<pre>".print_r($_SESSION,1).print_r($regRequest,1)."</pre>";
-        // If there's a logged in registrations user
+
+        // echo "<pre>".print_r($_SESSION,1).print_r($regRequest,1)."</pre>";
+
+        // 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;
 
     }
index fbcb3fe..455ae73 100644 (file)
@@ -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(){
index 8eeb9cd..2f3c3ab 100644 (file)
@@ -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(){
index 1ba6cd8..f086c89 100644 (file)
@@ -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 "<pre>".print_r($templateData,1)."</pre>";
 
-             // 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,
index 867f2eb..414f752 100644 (file)
@@ -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),
index 65a7ac8..7b4e060 100644 (file)
@@ -20,7 +20,7 @@
         </thead>
 
         <tbody>
-{if $haveCart}
+{if $haveCart && $cart.haveEvents}
         
   {foreach $cart.events as $event}
             <tr>
@@ -76,7 +76,7 @@
             </tfoot>
          
 {else}
-            <tr><td colspan="5" class="glm-reg-warning">There was a problem locating the information for your request!</td></tr> 
+            <tr><td colspan="5" class="glm-reg-warning glm-center">Your cart is empty. Please click "Register for Another Event" button above.</td></tr> 
 {/if}
         </tbody>
  
index dec8427..f5d3a8b 100644 (file)
@@ -2,7 +2,7 @@
 <a href="{$cartUrl}">
     <div id="registrations-cart-link-widget" style="width: 80px; height: 75px; padding: 5px; background-color: #ffffff; border: 1px black solid; position: relative">
         <img src="{$assetUrl}/registrationBlue.svg" width="50" style="position: absolute; z-index: 1;">
-        <div style="font-size: .5em; line-height: 1.1em; position: absolute; left: 14px; top: 65px; z-index: 2; font-style: italic;">REGISTRATION</div>
+        <div style="font-size: .5em; line-height: 1.1em; position: absolute; left: 14px; top: 63px; z-index: 2; font-style: italic;">REGISTRATION</div>
         <div style="font-size: .5em; line-height: 1.1em; position: absolute; left: 22px; top: 44px; z-index: 2;">
             {$numb_events} Event{if $numb_events == 0 || $numb_events > 1}s{/if}<br>
             {$numb_registrants} Registrant{if $numb_registrants == 0 || $numb_registrants > 1}s{/if}
     </div>
     
 {/if}
+{if $haveOtherRequests}
+<a id='glm-cart-select-action' href="" onClick="return false;">
+    <div id="registrations-cart-link-widget-requests" style="width: 80px; height: 1em; padding: 1px; background-color: #ffffff; border: 1px black solid; position: relative">
+        <div style="font-size: .55em; line-height: 1.1em; position: absolute; left:3px; top: 3px; z-index: 2;">
+        Select other Carts
+        </div>
+    </div>
+</a>
+<div id="glm-cart-select-dialog" title="" class="glm-hidden">
+        <center>
+            <h4>Your other pending registration requests</h4>
+            <table>
+                <thead>
+                    <tr><th>ID</th><th>Date request was created</th></tr>
+                </thead>
+                <tbody>
+            {foreach $regRequests as $rr}
+                    <tr>
+                        <td><a href="{$cartUrl}&cartId={$rr.id}">{$rr.id}</a></td>
+                        <td>{$rr.last_update.datetime}</td>
+                    </tr>
+            {/foreach}
+                </tbody>
+            </table>
+        </center>
+</div>      
+<script type="text/javascript">
+    jQuery(document).ready(function($) {
+
+        $("#glm-cart-select-action").click(function () {
+            $("#glm-cart-select-dialog").dialog({
+                autoOpen: true,
+                resizable: false,
+                modal: true
+            });
+        });
+                    
+    });
+</script>
+{/if}
+
 
index d69725c..9d922e6 100644 (file)
@@ -91,6 +91,7 @@
 
     </form>
 
+    <h4>Registration Summary</h4>
     <table class="glm-admin-table" width="100%">
 
         <thead>