Here are the parts in pastebin Controller http://pastebin.com/q9sg4u3a
UserSession http://pastebin.com/5mDTu7dS OrderController http://pastebin.com/GdDejK0E Template http://pastebin.com/0MDbxPJg On Monday, October 29, 2012 1:59:47 PM UTC-4, Jeff P wrote: > > <cfset event.copyToScope( variables, "currentUser, currentCart, > userSession")> > <cfset me = variables.currentUser> > <cfset cart = variables.currentCart> > > <cfdump var="#userSession#"> shows the cart isn't in the session > > <cfdump var="#currentCart#" label="currentCart"> which comes from the > session as well, returns the object. > > I will give the direct calls a try. I had thought about always having the > cart exist but hadn't worked towards it yet. > > Thanks also for reminding me about pastebin. > > Jeff > > On Monday, October 29, 2012 1:45:00 PM UTC-4, Jared Rypka-Hauer wrote: >> >> Can you show the code you're using to get the cart from the event into >> the page's variables scope? It's possible that there's a structCopy() >> involved rather than a simple assignment. >> >> The difference is that doing a structCopy() would cause a separate >> instance of session.cart to be set to the event object and/or the variables >> scope of your template. If that's the case then the behavior you're seeing >> makes perfect sense. If this is the case, the byRef nature of structs that >> you're depending on isn't going to work because you have a discrete COPY of >> the objects in the event object and variables scope. For some reason this >> is ringing a bell in the back of my mind as far as MG's functionality and >> unexpected behaviors. >> >> You may be right, I may be crazy. But I just might be the lunatic you're >> looking for. Give it a try, see what happens. :) >> >> Just for shits and giggles, you could also try replacing your function >> calls with direct references to the relevant variable. I know it breaks >> encapsulation, but I'm not suggesting you do it for your production code, >> just remark out your calls to UserSession and CurrentCart and replace them >> with direct references to the variables. That will eliminate your machinery >> from the equation and tell you if you have a bug in your code or if there's >> something deeper going on. >> >> You could also try setting session.cart to "" rather than using >> structDelete(). Replace structKeyExists() with isStruct() and just have >> session.cart always exist... >> >> Man it's been a long time since I've responded to a community support >> request like this... feels good! >> >> Let us know what you find out! >> >> J >> >> PS - If you really want help with this you might be best off to post the >> code to the template in question, both controllers, your UserSession and >> your Cart to something like pastebin.com or nomorepasting.com and send >> us links to them all so we can see the whole codebase in a format that's >> familiar and easily readable. Both of those resources provide ColdFusion >> code support so they will color code highlight things correctly. >> >> http://pastebin.com >> http://www.nomorepasting.com/paste.php >> >> >> On Oct 29, 2012, at 12:26 PM, Jeff P <[email protected]> wrote: >> >> This is in a controller called OrderController Here is the code: >> >> <cffunction name="processOrder" access="public" returntype="void" >> output="false"> >> <cfargument name="event" type="any"> >> >> <!--- get the cart data ---> >> <cfset var cart = beans.UserSession.getCurrentCart()> >> >> <cfif returnCode eq "Y"> >> <!--- if payment is successful, ---> >> <!--- clear database tables for the cart ---> >> <cfset beans.cartService.removeCartFromDatabase(cart)> >> <!--- clear the cart session ---> >> <cfset beans.UserSession.clearCartSession()> >> <cfset beans.UserSession.clearCheckout()> >> <!--- delete the credit card temp stuff ---> >> <cfset beans.OrderService.deleteCreditCardData(myOrder)> >> <cfset arguments.event.setValue("publicOrderNumber", >> myOrder.getPublicOrderNumber())> >> <cfset arguments.event.addResult("paymentAccepted")> >> <cfelse> >> ..... >> </cfif> >> >> The code to clear the cart session and checkout in the UserSession cfc >> are: >> >> <cffunction name="clearCartSession" access="public" output="false"> >> <cflock timeout="3" type="exclusive" scope="session"> >> <cfset structDelete( session, "cart" )> >> </cflock> >> </cffunction> >> <cffunction name="clearCheckout" access="public" output="false"> >> <cflock timeout="3" type="exclusive" scope="session"> >> <cfset structDelete( session, "checkout" )> >> </cflock> >> </cffunction> >> >> Thank you Dan. >> >> On Monday, October 29, 2012 11:02:52 AM UTC-4, Dan Wilson - >> [email protected] wrote: >>> >>> Show the portion of code where you delete the cart after a successful >>> transaction. >>> >>> DW >>> On Oct 29, 2012 10:41 AM, "Jeff P" <[email protected]> wrote: >>> >>>> Hey everybody, >>>> >>>> I'm experiencing so strangeness with sessions and am hoping you folks >>>> could shed some light on on what's happening. I have a cart app in MG >>>> 3.1.299. When I complete an order and delete the cart from the session and >>>> show the order complete page a dump of the session shows the cart is no >>>> longer in the session scope. However, another call to the session on the >>>> same page shows the cart as a valid struct within the session. >>>> >>>> In my Controller.cfc I have an onRequestStart function that copies the >>>> cart and the user (if they exist) to the event scope. I also have it >>>> copying the entire session through the UserSession.cfc to try to figure >>>> this out. Here are the pertinent parts of my controller.cfc and >>>> userSession.cfc: >>>> >>>> *Controller.cfc* >>>> >>>> <cffunction name="onRequestStart" access="public" >>>> output="false"> >>>> <cfargument name="event" type="any"> >>>> <!--- copy the cart to the event scope if it exists. ---> >>>> <cfif beans.UserSession.cartExists()> >>>> <cfset arguments.event.setValue("currentCart", >>>> beans.UserSession.getCurrentCart())> >>>> </cfif> >>>> <!--- and for the user if they're logged in. ---> >>>> <cfif beans.UserSession.loggedIn()> >>>> <cfset arguments.event.setValue("currentUser", >>>> beans.UserSession.getCurrentUser())> >>>> </cfif> >>>> <!--- return the whole session for some testing ---> >>>> <cfset arguments.event.setValue("userSession", >>>> beans.UserSession.getSession())> >>>> </cffunction> >>>> >>>> *UserSession.cfc* >>>> >>>> <cffunction name="cartExists" access="public" output="false"> >>>> <cflock timeout="3" type="readonly" scope="session"> >>>> <cfreturn structKeyExists( session, "cart" )> >>>> </cflock> >>>> </cffunction> >>>> >>>> <cffunction name="getCurrentCart" access="public" >>>> output="false"> >>>> <cflock timeout="3" type="readonly" scope="session"> >>>> <cfreturn session.cart> >>>> </cflock> >>>> </cffunction> >>>> <cffunction name="getCurrentUser" access="public" output="false"> >>>> <cflock timeout="3" type="readonly" scope="session"> >>>> <cfreturn session.user> >>>> </cflock> >>>> </cffunction> >>>> <cffunction name="getSession" access="public" output="false"> >>>> <cflock timeout="3" type="readonly" scope="session"> >>>> <cfreturn session> >>>> </cflock> >>>> </cffunction> >>>> >>>> <cffunction name="loggedIn" access="public" output="false"> >>>> <cflock timeout="3" type="readonly" scope="session"> >>>> <cfreturn structKeyExists( session, "user" )> >>>> </cflock> >>>> </cffunction> >>>> >>>> In my template I have a chink of code that displays a link to the cart >>>> if it exists and has at least one item in it: >>>> >>>> If I use the currentCart variable set in Controller.cfc, it returns the >>>> cart from the session after the order is processed even though a cfdump of >>>> the session shows it isn't there. >>>> >>>> <cfif isStruct(variables.currentCart) and >>>> variables.currentCart.getItemCount() gte 1> >>>> <div class="row-fluid"> >>>> <div id="viewCart" class="span12"> >>>> <a href="#click_ViewCart#">Your cart: <span >>>> class="bold">#variables.currentCart.getItemCount()#</span> item<cfif >>>> variables.currentCart.getItemCount() neq 1>s</cfif></a> <a >>>> href="#click_ViewCart#"><img src="images/shoppingCart.png" alt="view >>>> cart"></a> >>>> </div> >>>> </div> >>>> </cfif> >>>> >>>> *The display section still shows up after the order is complete*. >>>> >>>> But, If I use the entire getSession function from the Controller.cfc it >>>> acts as it's supposed to: >>>> >>>> <cfif structKeyExists(variables.userSession, "cart") and >>>> variables.userSession.cart.getItemCount() gte 1> >>>> <div class="row-fluid"> >>>> <div id="viewCart" class="span12"> >>>> <a href="#click_ViewCart#">Your cart: <span >>>> class="bold">#variables.userSession.cart.getItemCount()#</span> item<cfif >>>> variables.userSession.cart.getItemCount() neq 1>s</cfif></a> <a >>>> href="#click_ViewCart#"><img src="images/shoppingCart.png" alt="view >>>> cart"></a> >>>> </div> >>>> </div> >>>> </cfif> >>>> >>>> *The display section doesn't show up after the order is complete.* >>>> >>>> How can one call to the session return that the cart doesn't exist and >>>> then a second, later call to the session on the same page return that it >>>> does? >>>> >>>> Thank you for looking at this, >>>> >>>> Jeff P. >>>> >>>> -- >>>> Model-Glue Sites: >>>> Home Page: http://www.model-glue.com >>>> Documentation: http://docs.model-glue.com >>>> Bug Tracker: http://bugs.model-glue.com >>>> Blog: http://www.model-glue.com/blog >>>> >>>> You received this message because you are subscribed to the Google >>>> Groups "model-glue" group. >>>> To post to this group, send email to [email protected] >>>> To unsubscribe from this group, send email to >>>> [email protected] >>>> For more options, visit this group at >>>> http://groups.google.com/group/model-glue?hl=en >>> >>> >> -- >> Model-Glue Sites: >> Home Page: http://www.model-glue.com >> Documentation: http://docs.model-glue.com >> Bug Tracker: http://bugs.model-glue.com >> Blog: http://www.model-glue.com/blog >> >> You received this message because you are subscribed to the Google >> Groups "model-glue" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/model-glue?hl=en >> >> >> -- Model-Glue Sites: Home Page: http://www.model-glue.com Documentation: http://docs.model-glue.com Bug Tracker: http://bugs.model-glue.com Blog: http://www.model-glue.com/blog You received this message because you are subscribed to the Google Groups "model-glue" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/model-glue?hl=en
