How to connect an existing customer with a cart created with sales channel API?

Hello Michael,

I’m able to login the customer using sales channel API and create a cart which is automatically assigned to the customer. I can see this in the database with the sw-token-context of the logged in returned customer.

The problem is that when I’m trying to login into the shop storefront(without sales channel API) but the login form, a new token is generated and is not connected anymore with the cart I’ve created with sales channel API. If I’m setting the new generated token directly in database to that cart, I’m able to see it in storefront. 

Of course, using sales channel API we can create multiple carts for a user, but I don’t think there’s a mechanism when user logs in into sotrefront to get the last cart of a customer identified by customer id and load that cart(by setting the token of newly logged in storefront user to the last cart).

Are the carts persistent in storefront? I mean for example if I have a cart then log out, and log in again with another clean browser I’ll be able to see my last not ordered cart?

Based on function ‘loginWithPassword’ from Shopware\Core\Checkout\Customer\SalesChannel\AccountService seems a new token is always generated if the context changes:

 $newToken = $this-\>contextPersister-\>replace($context-\>getToken()); Function 'replace' loads only the cart from the current context.

Best regards,

Sorin