Show cart info based on the logged in user

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
afoster009
Posts: 16
Joined: 03 May 2016, 21:07

Show cart info based on the logged in user

Post by afoster009 » 10 May 2016, 22:59

Hello there, I am trying to set up aimeos so that each user is assigned their own cart.

Id like it so if i logged in with user A it would show their items they had in there cart, and if i log in with user B it will show the items they have in their cart.

As of now...When i log in with any user associated with my application the cart is the same for each user, containing the same items across all users.

Right now you must sign up to reach the /list page so you must be logged in to use the shop.

Im not sure how to configure aimeos to store unique cart info between users.

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Show cart info based on the logged in user

Post by aimeos » 11 May 2016, 06:40

The cart is bound to the session of the user. Each user has an own session, regardless which login he is using. If you want to enable the same user to have different sessions for each login, you have to overwrite the getSession()/setSession() method of the order base manager and add the user ID from the context:
- https://github.com/aimeos/aimeos-core/b ... d.php#L907
- https://github.com/aimeos/aimeos-core/b ... d.php#L931
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

afoster009
Posts: 16
Joined: 03 May 2016, 21:07

Re: Show cart info based on the logged in user

Post by afoster009 » 11 May 2016, 23:17

What exactly would the code look after i added the user ID into the context. Im by no means a professional programmer, so even an example would be fantastic

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Show cart info based on the logged in user

Post by aimeos » 12 May 2016, 00:56

You can use something like this in the getSession*()/setSession*() methods:

Code: Select all

$key = 'aimeos/basket/content-' . $sitecode . '-' . $language . '-' . $currency . '-' . strval( $type ) . '-' . $context->getUserId();
Extend the class, overwrite the named methods and configure the new class name for usage.
Also, be aware that this only works flawlessly for the requested context. If customer don't have to login first, the basket will be empty after they do so.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

jossnaz
Posts: 46
Joined: 22 Jul 2016, 01:19

Re: Show cart info based on the logged in user

Post by jossnaz » 25 Jul 2016, 10:31

what aimeos is saying is that each user HAS his own cart. The thing you are doing is wrong, is for faking the customers, you use the same browser and no incognito mode. It is unlikely that users will use the same computer, with the same browser, to work with aimeos on different accounts, without logging out in between.

So for your testing case i guess it can work if you use a new incognito window for login
afoster009 wrote:Hello there, I am trying to set up aimeos so that each user is assigned their own cart.

Id like it so if i logged in with user A it would show their items they had in there cart, and if i log in with user B it will show the items they have in their cart.

As of now...When i log in with any user associated with my application the cart is the same for each user, containing the same items across all users.

Right now you must sign up to reach the /list page so you must be logged in to use the shop.

Im not sure how to configure aimeos to store unique cart info between users.

Post Reply