How to store an identity for guest user in laravel? - laravel

I am new to Laravel and for a starter learning project, I was developing an E-commerce website using Laravel. I want to develop the cart functionalities but got stuck at a point.If a logged in user clicks "Add to Cart" button for an item, it gets stored in the database and that item in cart gets related to the particular user ID and that's how I know what user have what items in cart. But how can I handle users who don't have an account? Not all users always create accounts when they use an Ecommerce platform. What relation can I use for guest users ?
P.s. I know there are several cart functionalities available on Github for handling cart but I wanted to implement that myself
Please help me with this

Related

web application cart implementation for non-logged users

I am working for implementing a spring-boot based shopping application, where a feature exist called ‘add to cart’ for product which works when users is only logged in. Meaning spring-boot back-end creates session when user logged in to make mapping to cart object.
I am trying to implementing a features like real world shopping application like amazon, where product can be added into ‘cart’ even user is not logged in. Then after user log-in user session can be managed / merged with previous non-logged user.
Can some please give me any typical design pattern idea in details or book reference or tutorial link where I can get details idea about such kind of implementation.
If user is anonymous, I would save cart on server and save cart ID in browser using a persistent cookie. When user logs in, server can retrieve the anonymous cart from its ID. Alternatively, you could store full cart in cookie.

Access to Auth or Request in Laravel Model

I have a shop-store project. This project starts with basic functionality and grow up on each software life-cycle. Recently tendency to deploy some customization for user and analytics grow. I wanted to add favorite capability to project. The project has guest mode which unauthenticated user can see products.
Each user may choose to add a product to his/her favorites(after Auth). so far so good. I decide to append favorite attribute to products.
Trouble comes when i try to return products from controller as response. If i use Auth middleware unauthenticated users redirected to login. If i use custom code, every API with product should be changed accordingly. If i try to append filed in product model, i don't have access to Auth class nor requestin product model.
What's the way to handle such a situation? I appreciate your help.
UPDATE:
There are many models in my project. Order, OrderProduct, Product, User, Payment, Category, Delivery, ....
I want to have a new table named Bookmark which has two column: user_id and product_id.
Product == One Many == Bookmark
User == One Many == Bookmark
You can use the blade #auth directive to check for user authentication.
Then for templating
{{auth()-> user -> bookmark -> all()}}
This should work if you have established a one to may relationship between user and bookmark in your model.

How to have products on front-end only viewable to admin?

We are trying to figure out if its possible to have the following logic on magento CE.
Admin adds products to Magento, but they are to be marked as admin viewable on the front-end only, which means customers will NOT be able to see those SPECIFIC products on the frontend.
Note: customers will still be able to view all the rest of the products on the site, except admin viewable products.
Some products by customization can be made available for some certain customer groups.
So using logic related to this you can achieve your goal.

Sales Representative

I have a question is about magento. i am making a webstore and getting 1 difficulty. i have created an attribute called SalesRep. for example if i register from the frontend. i will be in customer section at backend. their at backend admin will be able to select me as a sales rep or customer.
if admin select me as salesRep i will become sales rep. Now i want to shop from frontend on behalf of any customer. i should have facility for search customer name from the frontend. at frontend i should be able to shop using customer details. so i logged in and can select any customer who want to shop. and i will shop for this customer.
I hope i explain in full details if you looking for more information please let me know.
Is there any help. Thanks in Advance
Magento doesn't provide such functionality. Try this free plugin. With it installed you will be able to find a customer in backend, click a "login as a customer" button on customer view page and directly login as a customer in your frontend. Then you can do whatever you need on behalf of the customer, including shopping. However this plugin won't allow customers to pre-select admins who may login on their behalf, i.e. any admin would be able to login as any cusomer.
P.S.: I am not connected to the plugin developer in any other way than I am a happy user of this plugin :)

Magento Multi Store Customer Combined Login Credentials

I have just added another website to my Magento eCommerce site and I would like my existing customer bass to be able to login to the new website with the same username and password that they have registered with for the original site. I also need any customer who signs up in the future to be assigned to both websites.
When I go to edit a user there is a drop-down box to say which website they are associated with, but the field is disabled and doesn't look like a multi select drop-down. Which would suggest to me that Magento isn't set up to share details between websites.
Does anyone know if this is possible?
In the admin, under System > Configuration > Customers > Customer Configuration > Account Sharing Options, you'll be able to choose between sharing accounts per website or globally.

Resources