[SOLVED ✅ ]How can i redirect on Aimeos\Base\View\Iface?

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!
alababdiy
Posts: 40
Joined: 30 Apr 2023, 12:46

[SOLVED ✅ ]How can i redirect on Aimeos\Base\View\Iface?

Post by alababdiy » 30 Oct 2023, 14:58

I modified vendor/aimeos/ai-client-html/src/Client/Html/Checkout/Standard/Standard.php to force users to login before checkout, but I'm getting the error:

Aimeos\Client\Html\Checkout\Standard\Standard::data(): Return value must be of type Aimeos\Base\View\Iface, Illuminate\Http\RedirectResponse returned

Code: Select all

public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\Base\View\Iface
	{
		$context = $this->context();

		$basketCntl = \Aimeos\Controller\Frontend::create( $context, 'basket' );
		$view->standardBasket = $basketCntl->get();
		
		++if (!$context->user()){						
		++	return Redirect::to('login');
		++}
......
Last edited by alababdiy on 01 Nov 2023, 08:49, edited 1 time in total.

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

Re: How can i redirect on Aimeos\Base\View\Iface?

Post by aimeos » 31 Oct 2023, 09:00

You will burn in (developer) hell if you modify files from the ./vendor/ directory. This is strictly forbidden!

The correct solution is to implement a Laravel middleware which checks for the route including if the user is logged in and redirects the user to the login page if not:
https://laravel.com/docs/10.x/middleware#main-content
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

alababdiy
Posts: 40
Joined: 30 Apr 2023, 12:46

Re: How can i redirect on Aimeos\Base\View\Iface?

Post by alababdiy » 31 Oct 2023, 09:39

Thanks for reminding me about modifying files from the ./vendor/ directory.

I just modified the files for testing, and I will overwrite them again on extension.

I tried a regular Laravel redirect, but I'm still getting the same error:

Code: Select all

[2023-10-31 09:31:15] local.ERROR: Aimeos\Client\Html\Checkout\Standard\Standard::data(): Return value must be of type Aimeos\Base\View\Iface, Illuminate\Http\RedirectResponse returned
code:

Code: Select all

$context = $this->getContext();
if (!$context->user())
**    return redirect('login');**

alababdiy
Posts: 40
Joined: 30 Apr 2023, 12:46

Re: How can i redirect on Aimeos\Base\View\Iface?

Post by alababdiy » 01 Nov 2023, 08:48

Thanks

Post Reply