Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Help for integrating the Laravel package
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!
User avatar
peter69
Posts: 95
Joined: 09 Jun 2022, 19:31

Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Post by peter69 » 04 Jun 2023, 06:11

Hello Laravel Aimeos!

I am developing a "multishop" project. I have created two stores: shop1 and shop2.

The shop1 store is the default one, which should be displayed at https://mydomain.com, and shop2 should be displayed at https://shop2.mydomain.com.

I have followed the steps mentioned in the documentation and configured the routes as follows:

Code: Select all

'routes' => [
    'admin' => ['domain' => '{site}.mydomain.com', 'prefix' => 'admin', 'middleware' => ['web']],
    'jqadm' => ['domain' => '{site}.mydomain.com', 'prefix' => 'admin/jqadm', 'middleware' => ['web', 'auth']],
    'graphql' => ['domain' => '{site}.mydomain.com', 'prefix' => 'admin/graphql', 'middleware' => ['web', 'auth']],
    'jsonadm' => ['domain' => '{site}.mydomain.com', 'prefix' => 'admin/jsonadm', 'middleware' => ['web', 'auth']],
    'jsonapi' => ['domain' => '{site}.mydomain.com', 'prefix' => 'jsonapi', 'middleware' => ['web', 'api']],
    'account' => ['domain' => '{site}.mydomain.com', 'prefix' => 'profile', 'middleware' => ['web', 'auth']],
    'default' => ['domain' => '{site}.mydomain.com', 'prefix' => 'shop', 'middleware' => ['web']],
    'update' => ['domain' => '{site}.mydomain.com'],
],
In the router/web.php file, I have added the following:

Code: Select all

Route::group(['domain' => '{site}.mydomain.com', 'middleware' => ['web']], function () {
    Route::get('/', '\Aimeos\Shop\Controller\CatalogController@homeAction')
        ->name('aimeos_home')->where( ['site' => '[a-z0-9\-]+'] );
});
I have created two different themes for each store. In the shop.php configuration file, I have the following setting:

Code: Select all

        'mshop' => [
            'locale' => [
                'site' => 'default', // used instead of "default"
            ]
        ],
This causes the error: No item found for conditions: Array ( [locale.site.code] => default )


This error can be resolved by setting the code for one of the sites. However, when I do this, the home page always displays the template of the store with the configured code.

I noticed that in the themes, there is the mshop.php configuration file, and I added the following configurations:

packages/shop1/config/mshop.php

Code: Select all

<?php

return [
    'locale' => [
        'site' => 'shop1',
    ]
];
packages/shop2/config/mshop.php

Code: Select all

<?php

return [
    'locale' => [
        'site' => 'shop2',
    ]
];
However, this doesn't work, and it doesn't override the default configuration in config/shop.php.

While investigating, I noticed that in the file: vendor/aimeos/aimeos-laravel/src/Aimeos/Shop/Base/Locale.php, only the configuration from config/shop.php is being taken into account, and it doesn't consider the specific configurations of each theme:
aimeos default site code.png
aimeos default site code.png (85.89 KiB) Viewed 3832 times
I would greatly appreciate your assistance.

Best regards!

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

Re: Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Post by aimeos » 04 Jun 2023, 08:40

"mydomain.com" isn't a subdomain of itself, so your settings won't work. Use these instead:

Code: Select all

'routes' => [
    'admin' => ['domain' => '{site}', 'prefix' => 'admin', 'middleware' => ['web']],
    'jqadm' => ['domain' => '{site}', 'prefix' => 'admin/jqadm', 'middleware' => ['web', 'auth']],
    'graphql' => ['domain' => '{site}', 'prefix' => 'admin/graphql', 'middleware' => ['web', 'auth']],
    'jsonadm' => ['domain' => '{site}', 'prefix' => 'admin/jsonadm', 'middleware' => ['web', 'auth']],
    'jsonapi' => ['domain' => '{site}', 'prefix' => 'jsonapi', 'middleware' => ['web', 'api']],
    'account' => ['domain' => '{site}', 'prefix' => 'profile', 'middleware' => ['web', 'auth']],
    'default' => ['domain' => '{site}', 'prefix' => 'shop', 'middleware' => ['web']],
    'update' => ['domain' => '{site}'],
],
Furthermore, set the default site to "mydomain.com":

Code: Select all

        'mshop' => [
            'locale' => [
                'site' => 'mydomain.com', // used instead of "default"
            ]
        ],
And change the locale site codes in the admin backend to "mydomain.com" and "shop.mydomain.com" so both sites are matched by your route config.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
peter69
Posts: 95
Joined: 09 Jun 2022, 19:31

Re: Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Post by peter69 » 04 Jun 2023, 17:32

Thank you for the provided information. However, it seems that when I access https://shop2.mydomain.com, I still see the template of the theme configured for https://mydomain.com (shop1). The template/theme I have created and configured for shop2 doesn't appear.

Interestingly, on other pages such as shop, product detail, catalog list, etc., the appropriate theme is displayed.

Please let me know if there's any additional information or configuration I should consider to resolve this issue.

Thank you for your assistance!

Best regards!

User avatar
peter69
Posts: 95
Joined: 09 Jun 2022, 19:31

Re: Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Post by peter69 » 04 Jun 2023, 18:07

I have noticed that it only works if I access it in the following way: https://shop2.mydomain.com/?locale=es&s ... domain.com

Certainly, this is not a user-friendly URL.

What I want is for https://shop2.mydomain.com to correctly display the catalog-home component of the theme I have created for shop2.

I have followed the instructions in the documentation: https://aimeos.org/docs/2023.x/laravel/ ... /#homepage

However, it still doesn't work as expected.

Please provide any additional details or configuration steps that may help resolve this issue.

Thank you for your support!

Best regards!

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

Re: Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Post by aimeos » 05 Jun 2023, 06:23

The route for the home page needs to be adapted too:

Code: Select all

Route::group(['domain' => '{site}', 'middleware' => ['web']], function () {
    Route::get('/', '\Aimeos\Shop\Controller\CatalogController@homeAction')
        ->name('aimeos_home')->where( ['site' => '[a-z0-9\-]+'] );
});
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
peter69
Posts: 95
Joined: 09 Jun 2022, 19:31

Re: Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Post by peter69 » 05 Jun 2023, 06:39

Hello,

That's exactly how I have it configured but it doesn't work either:

routes/web.php:

Code: Select all

<?php

use Illuminate\Support\Facades\Request;
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!
|
*/

$params = [];
$conf = ['prefix' => '', 'where' => []];

if( env( 'SHOP_MULTILOCALE' ) )
{
    $conf['prefix'] .= '{locale}';
    $conf['where']['locale'] = '[a-z]{2}(\_[A-Z]{2})?';
    $params = ['locale' => app()->getLocale()];
}

if( $conf['prefix'] )
{
    Route::group(['domain' => '{site}', 'middleware' => ['web']], function () {
        Route::get('/', '\Aimeos\Shop\Controller\CatalogController@homeAction')
             ->name('aimeos_home')->where( ['site' => '[a-z0-9\-]+'] );
    });

}


Route::group($conf ?? [], function() {
    require __DIR__.'/auth.php';
});

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

Re: Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Post by aimeos » 05 Jun 2023, 07:00

If you don't have configured SHOP_MULTILOCALE=true, then you have to remove the "if( $conf['prefix'] )" condition.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
peter69
Posts: 95
Joined: 09 Jun 2022, 19:31

Re: Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Post by peter69 » 05 Jun 2023, 07:03

It is set to true. Since I have configured two languages (spanish and english)

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

Re: Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Post by aimeos » 05 Jun 2023, 07:06

Add a redirect to the default language, e.g. "/en" before the if condition in the ./routes/web.php file so the home page route can match.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
peter69
Posts: 95
Joined: 09 Jun 2022, 19:31

Re: Multishop Configuration Issue: Overriding Locale Settings in Laravel Aimeos

Post by peter69 » 05 Jun 2023, 07:26

It doesn't work either, I get a 404 error. I share with you my configurations:

config/shop.php

Code: Select all

$prefix = config( 'app.shop_multilocale' ) ? '{locale}/' : '';
$config = [
        'apc_enabled' => false, // enable for maximum performance if APCu is available
        'apc_prefix' => 'aimeos:', // prefix for caching config and translation in APCu
        'num_formatter' => 'Locale', // locale based number formatter (alternative: "Standard")
        'pcntl_max' => 4, // maximum number of parallel command line processes when starting jobs
        'version' => env( 'APP_VERSION', 1 ), // shop CSS/JS file version
        'routes' => [
            'admin' => ['domain' => '{site}', 'prefix' => $prefix . 'admin', 'middleware' => ['web']],
            'jqadm' => ['domain' => '{site}', 'prefix' => 'admin/jqadm', 'middleware' => ['web', 'auth']],
            'graphql' => ['domain' => '{site}', 'prefix' => 'admin/graphql', 'middleware' => ['web', 'auth']],
            'jsonadm' => ['domain' => '{site}', 'prefix' => 'admin/jsonadm', 'middleware' => ['web', 'auth']],
            'jsonapi' => ['domain' => '{site}', 'prefix' => 'jsonapi', 'middleware' => ['web', 'api']],
            'account' => ['domain' => '{site}', 'prefix' => $prefix . '/profile', 'middleware' => ['web', 'auth']],
            'default' => ['domain' => '{site}', $prefix . 'shop', 'middleware' => ['web']],
            'supplier' => ['domain' => '{site}', 'prefix' => $prefix . 's', 'middleware' => ['web']],
            'page' => ['domain' => '{site}', 'prefix' => $prefix . 'p', 'middleware' => ['web']],
            'home' => ['domain' => '{site}', 'prefix' => $prefix, 'middleware' => ['web']],
            'update' => ['domain' => '{site}'],
        ],
        ...
       // other settings
       ...
       'mshop' => [
            'locale' => [
                'site' => 'mydomain.com', 
            ]
        ],
];
routes/web.php:

Code: Select all

<?php

use Illuminate\Support\Facades\Request;
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!
|
*/

$params = [];
$conf = ['prefix' => '', 'where' => []];

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\.\-]+';
}

if( $conf['prefix'] )
{
    Route::group(['domain' => '{site}', 'middleware' => ['web']], function () {
        Route::get('/', '\Aimeos\Shop\Controller\CatalogController@homeAction')
             ->name('aimeos_home')->where( ['site' => '[a-z0-9\-]+'] );
    });

}


Route::group($conf ?? [], function() {
    require __DIR__.'/auth.php';
});

Post Reply