We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37286
    • 160 Posts
    I'm working on something similar to a shopping cart basket. I am dropping items into an array that is stored in a session. I then write to and get data from a table at key times. Everything is working well until a user adds items to the basket, then logs into the website. All data is still in session, but I have no event to move data to the database, so the data is lost when logging out.

    I have seen posts about pre and post hooks used with the login module, but this is something I hope to use on some other sites and it would be nice to have something I can drop in to use without having to go through a bunch of setup steps. Is there an event that fires when the session changes I can capture to transfer the data from the session to the database? [ed. note: insomnix last edited this post 14 years, 6 months ago.]
      • 37286
      • 160 Posts
      I posted this a while back and went on to work on something else. I'm now back to working on this part. In that time I have learned more about plugins and how they work and I think what I need is a plugin using the weblogin event to transfer my session data to a table.
      Anyone out there have a better idea? If not, anyone have a good example of how I should do this?
        • 22303 MODX Staff
        • 10,725 Posts
        I would a) store the cart data in a cookie outside of the session before a user logs in and b) copy that data to the session once they log in.
          • 37286
          • 160 Posts
          That would be a good idea, but I'm passing an xml file based on the session/table data to a 3rd party application. The application initiates the connection through a url I give it and that url will have to contain the userid to grab the data from the table, or session information so I can grab the data from the session array. I might add the cookie for redundancy after I work out these kinks, but the third party app can't grab the cookie.

          It took some searching and trial and error, but I did get the plugin to work at login to pass the data from the session to the table. For anyone else that might need this info, you can grab the user id with:
          $user_id = $user->id;

          Or the profile with:
          $profile = $user->getOne('Profile');