How to Get the User’s Basket ID from the Session

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
Paulus-Ragnarr
Posts: 25
Joined: 15 Oct 2024, 07:02

How to Get the User’s Basket ID from the Session

Post by Paulus-Ragnarr » 04 Mar 2025, 10:29

Hi,

I’m trying to figure out how to get the user’s current basket ID from the session. Here’s the scenario:

We have a checkout process where a guest can log in(after products are added), and we noticed that the customerid is only set in the basket order object but doesn’t get saved to the database in this case. We want to handle a situation where the user doesn’t complete the checkout and logs out of the shop. In that case, we’d like to save the customerid (if it doesn’t already exist) to the database before they log out. This way, if the user logs in again later, their previous order data will still be available.

Right now, I’m using this query to fetch the user’s basket data:

Code: Select all

$basket = \Aimeos\MShop::create($this->getSessionContext(), 'order')->getSession();
ENV

Code: Select all

Aimeos version: Aimeos Headless 2024.10.*
PHP version: 8.2

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

Re: How to Get the User’s Basket ID from the Session

Post by aimeos » 05 Mar 2025, 09:11

It would be better to retrieve the current basket of the user during login, set the user ID and save the basket again instead of doing this on logout because users can also leave the site without logging out.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply