Basket empty after login
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!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Basket empty after login
Version: 2022.10
I got the pages to fully show up, function, etc. However, I am having a small issue with retaining basket data. I cannot figure out why when the user logs in the basket and data is lost. Below you can see my "AuthenticatedSessionController.php":
Basically, if a user adds items to the basket, and logs in, the basket is emptied. Which is not the desired outcome. Is there something I am missing as a requirement?
I got the pages to fully show up, function, etc. However, I am having a small issue with retaining basket data. I cannot figure out why when the user logs in the basket and data is lost. Below you can see my "AuthenticatedSessionController.php":
Code: Select all
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Aimeos\Shop\Facades\Shop;
use Illuminate\Support\Facades\Response;
class AuthenticatedSessionController extends Controller
{
/**
* Display the login view.
*
* @return \Illuminate\View\View
*/
public function create()
{
$params = ['page' => 'page-index'];
foreach( app( 'config' )->get( 'shop.page.cms', ['cms/page', 'catalog/tree', 'basket/mini'] ) as $name )
{
$params['aiheader'][$name] = Shop::get( $name )->header();
$params['aibody'][$name] = Shop::get( $name )->body();
}
return Response::view( Shop::template( 'account.login' ), $params )
->header( 'Cache-Control', 'no-store, private' );
}
/**
* Handle an incoming authentication request.
*
* @param \App\Http\Requests\Auth\LoginRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(LoginRequest $request)
{
$request->authenticate();
$request->session()->regenerate();
return redirect()->intended(RouteServiceProvider::home());
}
/**
* Destroy an authenticated session.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Request $request)
{
Auth::guard('web')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect(airoute( 'aimeos_home' ));
}
}
Re: Auth pages using Aimeos views
This line may create a new session:
Code: Select all
$request->session()->regenerate();
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Auth pages using Aimeos views
It is the default implementation of the store handler.
Re: Basket empty after login
I was testing this on a clean install of the latest version of the stand-alone Laravel version. And the same is happening there. If you have anything in the basket and log in, the basket contents are lost and it is empty. Is it meant to be that way? Kinda illogical that person would lose the basket upon logging in.
Also additional while I was debugging I came across a couple of issues with the mini-basket not updating properly:
1. Open a new instance of a browser
2. Go to the product and add to the basket, once pops up, hit back. [mini-basket shows 1]
3. Click aimeos logo (goes to the first page), mini-basket shows 0
Works on https://laravel.demo.aimeos.org
1. Open a new instance of a browser
2. Go to the product and add to the basket, once pops up, hit back.
3. Switch to a different language, the basket becomes empty
Works on https://laravel.demo.aimeos.org
Am I missing some configuration somewhere to enable this logic? Or could I be pointed in the right direction to resolve this?
Also additional while I was debugging I came across a couple of issues with the mini-basket not updating properly:
1. Open a new instance of a browser
2. Go to the product and add to the basket, once pops up, hit back. [mini-basket shows 1]
3. Click aimeos logo (goes to the first page), mini-basket shows 0
Works on https://laravel.demo.aimeos.org
1. Open a new instance of a browser
2. Go to the product and add to the basket, once pops up, hit back.
3. Switch to a different language, the basket becomes empty
Works on https://laravel.demo.aimeos.org
Am I missing some configuration somewhere to enable this logic? Or could I be pointed in the right direction to resolve this?
Re: Basket empty after login
It's not the desired behavior and seems to be a side effect because Laravel changes the session ID after login (but keeps the session data). Aimeos uses the session ID to store the serialized basket in the database since 2022.10 and if it changes, the basket isn't found any more. We've changed the code in the Aimeos Laravel package slightly to store the original session ID in the Laravel session so it's stable as long as the session is available. Can you please test the new version using:snicto wrote: ↑07 Feb 2023, 20:16 I was testing this on a clean install of the latest version of the stand-alone Laravel version. And the same is happening there. If you have anything in the basket and log in, the basket contents are lost and it is empty. Is it meant to be that way? Kinda illogical that person would lose the basket upon logging in.
Code: Select all
composer req aimeos/aimeos-laravel:2022.10.x-dev
This is due to browser caching because the page can be cached up to 30 sec by the browser. Thus, it will show the page from the browser cache and don't ask the server:snicto wrote: ↑07 Feb 2023, 20:16 Also additional while I was debugging I came across a couple of issues with the mini-basket not updating properly:
1. Open a new instance of a browser
2. Go to the product and add to the basket, once pops up, hit back. [mini-basket shows 1]
3. Click aimeos logo (goes to the first page), mini-basket shows 0
Works on https://laravel.demo.aimeos.org
https://github.com/aimeos/aimeos-larave ... er.php#L91
We want to avoid loading each page from the server only for that reason because when leveraging browser caching, you handle 10 times more requests than without. A possible solution to mitigate the problem would be to store the current number of products in the basket within the browser and update it with a few lines of Javascript.
We can't reproduce the behavior in the Laravel demo every time and we have to investigate more. The problem seems to be that products are not always migrated to the new basket for the new language even if the product is available.snicto wrote: ↑07 Feb 2023, 20:16 1. Open a new instance of a browser
2. Go to the product and add to the basket, once pops up, hit back.
3. Switch to a different language, the basket becomes empty
Works on https://laravel.demo.aimeos.org
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Basket empty after login
Yes, this has resolved the losing basket on login and registration. Thanks!aimeos wrote: ↑09 Feb 2023, 09:13It's not the desired behavior and seems to be a side effect because Laravel changes the session ID after login (but keeps the session data). Aimeos uses the session ID to store the serialized basket in the database since 2022.10 and if it changes, the basket isn't found any more. We've changed the code in the Aimeos Laravel package slightly to store the original session ID in the Laravel session so it's stable as long as the session is available. Can you please test the new version using:snicto wrote: ↑07 Feb 2023, 20:16 I was testing this on a clean install of the latest version of the stand-alone Laravel version. And the same is happening there. If you have anything in the basket and log in, the basket contents are lost and it is empty. Is it meant to be that way? Kinda illogical that person would lose the basket upon logging in.
Code: Select all
composer req aimeos/aimeos-laravel:2022.10.x-dev
- VadimSaratov
- Posts: 8
- Joined: 09 May 2022, 15:27
Re: Basket empty after login
when you try to log in in another browser or on another device, the basket will be empty. I think this is expected behavior as the session ID and cookies are different, is there any update on this in the aimeos versions? Or I need to change this behavior by overwriting the getSession/setSession() methods in the order base manager
Re: Basket empty after login
In 2023.04, baskets are stored in the database by default now:
https://github.com/aimeos/aimeos-core/b ... #L125-L147
https://github.com/aimeos/aimeos-core/b ... #L125-L147
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Basket empty after login
I have the same problem. Any tips on modifying the order manager to solve this?when you try to log in in another browser or on another device, the basket will be empty. I think this is expected behavior as the session ID and cookies are different, is there any update on this in the aimeos versions? Or I need to change this behavior by overwriting the getSession/setSession() methods in the order base manager
Re: Basket empty after login
Overwrite the getSession()/setSession () methods and use the customer ID if available instead of the token:
- https://github.com/aimeos/aimeos-core/b ... hp#L69-L75
- https://github.com/aimeos/aimeos-core/b ... #L128-L134
In 2024.x+ it's in the Session trait but you have to overwrite the order manager class the same way:
https://github.com/aimeos/aimeos-core/b ... ession.php
You get the customer (ID) using "$context->user()".
- https://github.com/aimeos/aimeos-core/b ... hp#L69-L75
- https://github.com/aimeos/aimeos-core/b ... #L128-L134
In 2024.x+ it's in the Session trait but you have to overwrite the order manager class the same way:
https://github.com/aimeos/aimeos-core/b ... ession.php
You get the customer (ID) using "$context->user()".
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star