Locale select
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!
Locale select
Hello!
My site have 2 languages. When I use a filter in catalog, to filter, for example, by "color" - it shows me filtered products, but changes site language to language set in my "env.php" file at "APP_LOCALE=" line, instead of selected by user. Steps I’ve taken:
setting enabled at env.php file.
Added the allowed language currency combination in the Locale > Locale panel (2 lagguages\ 1 currency for both of them).
How can I fix that, I want language selected by user to be remembered when "filtering"?
My site have 2 languages. When I use a filter in catalog, to filter, for example, by "color" - it shows me filtered products, but changes site language to language set in my "env.php" file at "APP_LOCALE=" line, instead of selected by user. Steps I’ve taken:
Code: Select all
SHOP_MULTILOCALE=true
Added the allowed language currency combination in the Locale > Locale panel (2 lagguages\ 1 currency for both of them).
How can I fix that, I want language selected by user to be remembered when "filtering"?
Re: Locale select
Does the "locale" parameter gets lost in the target URL?
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: Locale select
If SHOP_MULTILOCALE is enabled, the locale parameter should be always part of the URL path, not the query string because those query parameters are removed by browsers when using GET form requests:
https://github.com/aimeos/aimeos/blob/m ... hp#L23-L28
Did you change anything in the ./route/web.php file?
https://github.com/aimeos/aimeos/blob/m ... hp#L23-L28
Did you change anything in the ./route/web.php file?
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: Locale select
Yes, I found it and fixed it.aimeos wrote: ↑02 May 2023, 17:36 If SHOP_MULTILOCALE is enabled, the locale parameter should be always part of the URL path, not the query string because those query parameters are removed by browsers when using GET form requests:
https://github.com/aimeos/aimeos/blob/m ... hp#L23-L28
Did you change anything in the ./route/web.php file?
For now my routes/web.php:
Code: Select all
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/ready', function() {
return 'OK';
});
$params = [];
$conf = ['prefix' => '', 'where' => []];
// Aimeos routes
if( env( 'SHOP_MULTILOCALE' ) )
{
$conf['prefix'] .= '{locale}';
$conf['where']['locale'] = '[a-z]{2}(\_[A-Z]{2})?';
$params = ['locale' => app()->getLocale()];
}
if( env( 'SHOP_MULTISHOP' ) )
{
$conf['prefix'] .= '/{site}';
$conf['where']['site'] = '[A-Za-z0-9\.\-]+';
}
// Custom routes
Route::group( $conf, function() {
Route::match( array( 'GET', 'POST' ), '/', array(
'as' => 'aimeos_home',
'uses' => 'Aimeos\Shop\Controller\CatalogController@listAction'
) )->where( ['locale' => '[a-z]{2}(\_[A-Z]{2})?', 'site' => '[A-Za-z0-9\.\-]+'] );
Route::match( array( 'GET' ), 'admin-aimeos', array(
'as' => 'aimeos_shop_admin',
'uses' => 'Aimeos\Shop\Controller\AdminController@indexAction'
) )->where( ['locale' => '[a-z]{2}(\_[A-Z]{2})?', 'site' => '[A-Za-z0-9\.\-]+'] );
})->middleware(['web']);
if( $conf['prefix'] )
{
Route::get('/', function () use ($params) {
return redirect(airoute('aimeos_home', $params));
});
}
Route::group($conf ?? [], function() {
require __DIR__.'/auth.php';
});
But all links from this page are still without {locale} prefix.
Example "Hot deals" button's URL: http://devshop.tm.ru/shop/hot-deals~63?locale=ru
If I try to type URL manually (http://devshop.tm.ru/ru/shop/hot-deals~63?locale=ru), I get an error:
aimeos-laravel:~2022.10
Illuminate\Routing\Exceptions\UrlGenerationException
PHP 8.1.14
9.52.7
"Missing required parameter for [Route: login] [URI: {locale}/login] [Missing parameter: locale]."
From this part of code: vendor/aimeos/aimeos-laravel/src/views/base.blade.php: 57
Code: Select all
@if (Auth::guest())
<li class="nav-item login"><a class="nav-link" href="{{ airoute( 'login' ) }}" title="{{ __( 'Login' ) }}"><span class="name">{{ __( 'Login' ) }}</span></a></li>
@else
Code: Select all
'routes' => [
'default' => ['prefix' => '{locale}/shop', ...],
resources/views/auth/login.blade.php: 5
"Missing required parameter for [Route: login] [URI: {locale}/login] [Missing parameter: locale]."
Code: Select all
<form method="POST" action="{{ route('login') }}">
Re: Locale select
The reason are your two custom routes you've added to the routes/web.php. They simply don't work because the first won't have any locale and the admin login requires a locale that's not there. If you remove that custom routes again, it should work as expected.
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: Locale select
I removed all custom code from routes/web.php. Still doesn't work with the same error. if I comment these lines, everything works:
Code: Select all
//Route::group($conf ?? [], function() {
require __DIR__.'/auth.php';
//});
Re: Locale select
There can be route conflicts with the auth routes. Can you please post the output of "composer show"?
A possible solution is to add a prefix like "auth" to all authentication routes so they are not matched by any other routes.
A possible solution is to add a prefix like "auth" to all authentication routes so they are not matched by any other routes.
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