On my OpenCart website, I'm trying to display the recently viewed items by the current user. The current user can be either logged in or logged out.
I don't see any table in my database that would keep track of such data. Does anybody know what would be the best option to go about this? Should I be creating cookies to do this?
If I am not wrong you are saying current user (may not be logged in) and his recent viewed product, Here you dont have user id so you can set Cookie for this instead of using database.
If you want to keep track of recent viewed product for particular user only, you can store it in database like opencart does for wishlist/add to cart list etc so that when ever user logs in the last viewed products appears.
//library/customer login() and logout()
Related
I create an online store website
when user add some product to cart i save this information in session (if user not logged in)
and
when user logged in and select some product i insert them into table
is this true way?
can i store all information of user selected product in session?
I think the best way to go in this case is not using the database at all, but use cookies instead.
PHP Cookies
This way you don't have to query the database, and all data will be saved on the computer of the user. This will also keep the information for the people who are not logged in. Which will be more user friendly.
Better to store items in session (for both visitors or logged in people)
Only needeed of store them is only when they intend to buy the product.
On visit (even if user is loged in or not) you donot have to store them in db.
Further, use db only for values you have to refer in future.
I want to add a product in the cart for the guest user
I have created on session by inserting the guest user information in database as follows in my header file which is been including on every view as common
<?php $this->load->view('common/header'); ?>
Below it is what I used at the top of my header file
<?php if($this->session->userdata('user_id')=='')
{
$this->home_model->addguestUser();
}
$info = $this->home_model->productinfo($ProductID);
?>
Now this calls the information is used by my home model to create a session according to user_id from database
The first thing I want is to stop to interact with the database because whenever anybody visits my site the data is add as guest in the database which is very dangerous if the number of people visits on my site increased
I want to create session without making any major changes in my current code and I want to create a session with some random variables and then use it to every page
My current flow of data is as follows
Whenever any persons visits my site then the guest user is created automatically.
Then this session is used throughout the site in the static page also
If the user goes and adds product in the user cart it will automatically gets added in the cart as well as in the entry goes in database
If he is the guest user and adds the product in the cart then after he clicks on the checkout page he will first ask to login to his id if he is registered user .
What I want the flow should be
As of now the database interaction for the guest user should not be there i.e if he is guest user then the database use should be not there.
But the session should be created for the guest user also.
For guest user don't add selected product into database but just store in session. Save data in session for guest user. Once they click for checkout ask them for login or register. After login add their saved(saved in session) data in database.
If they don't register or login, session would automatically destroyed when they leave your site.
Hope this is what you want.
I am trying to show recently viewed items in my site in php.For which i was thinking to make use of cookies,according to which i want to store what user is clicking in a db with cookie values the users have.Now I dont know how to generate cookies dynamically for one pc or device,when user clicks items on my site while navigating through....
Please guide me on how to put cookie values in a db along with product details in database,so that later when they come to my site they should get recently visited products on basis of the cookie values in my db..
Currently I'm working on a Magento module that allows customers to upload files against their order at the product page.
So what I thought was to have the files saved in a folder created with the session id as the folder name, until they submit their order. But then I ran in to an issue with this solution, which is, when a customer uploads a file as a guest and if they logged in after, or if they create a new account, the session ID get change, and no way of back tracking previous session data or id.
I looked at visitor ID and that doesn't work either. coz for a new customers/visitors don't have a visitor id, so thats out too.
Any suggestion?
You can track such instances with a cookie & the right expiry time. The following documentation helped me out a lot when working with cookies:
http://www.quirksmode.org/js/cookies.html
Visitor ID doesn't change after login. It changes after logout, which is perfectly normal. Also, all visitors have visitor ID, whether they new or not or logged in or not.
I'm finalising my project, and I want to find how I can restore the users last page when he logs in. Do I need to have a function that save the game, or is there a way I can redirect the user to the room/page he was when he logs in. As I recall, sessions get destroyed as a user logs out.
You should store every user movement inside your website into a database with a filed like lastPageVisited and add an updater to every page of your website that update that field with the current page.
Then you could recover that field with a simple query.
But the question is: is it really worth something?