aimeos / aimeos-laravel

Laravel ecommerce package for ultra fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce
https://aimeos.org/Laravel
MIT License
7.26k stars 1.05k forks source link

Custom Domains with Multi-Vendor #448

Closed woodwardmatt closed 2 years ago

woodwardmatt commented 2 years ago

Environment

  1. Version (2021.10.5)
  2. Operating system (Ubuntu: 20.04)

Describe the bug I've setup two domains to point at the same instance. The outcome I'm trying to achieve here is to have two sites branded with their own theme, have their own shop / products and have their own homepages.

I've updated the routes in config/shop.php to:

    'routes' => [
        // Docs: https://aimeos.org/docs/latest/laravel/extend/#custom-routes
        // Multi-sites: https://aimeos.org/docs/latest/laravel/customize/#multiple-shops
        'admin' => ['domain' => '{site}', 'prefix' => 'admin', 'middleware' => ['web']],
        'jqadm' => ['domain' => '{site}', 'prefix' => 'admin/jqadm', '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}'],
    ],

I've appended the following to routes/web.php:

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

I've also updated the .env file to have the following configuration:

SHOP_MULTISHOP=true

It's also worth noting that the APP_URL in the .env file points at the url for the first domain.

I have left the first domain (e.g. local.shop.com) with a site code of default, and the second domains I have given a sitecode to match the domain (e.g. local.domain.com) .

I have the first domain using a custom theme and the second domain using the default (just so they look differently to test).

Expected behavior I'm expecting that if I go to the first domain I would see the theme and homepage content associated with the first / default domain. I'm also expecting that if I go to the second domain I would see the theme and homepage content associated with the second domain. Like wise for accessing the shops / products for each domain.

Observed behavior When I go to the first domain, I see the theme and homepage content of the first site (which is correct). When I try to go to the shop (or a product directly) of the first site I get an error (No item found for conditions: Array ( [locale.site.code] => local.shop.com ))

When I go to the second domain, I see the theme and homepage of the first site (which is incorrect). When I try to go to the shop (or a product directly) of the second site, I see the shop with the theme and content of the second site (which is correct)

Questions What configuration changes do I need to make to resolve the routing for the above setup with the two shops / domains.

woodwardmatt commented 2 years ago

Just to confirm that the full content under routes/web.php is:

/*
|--------------------------------------------------------------------------
| 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!
|
*/

Auth::routes(['verify' => true]);

Route::get('/', '\Aimeos\Shop\Controller\CatalogController@homeAction')->name('aimeos_home');

Route::get('{path?}', '\Aimeos\Shop\Controller\PageController@indexAction')->name('aimeos_page')->where( 'path', '.*' );

// custom domain: vendor1.com
Route::group(['domain' => '{site}', 'middleware' => ['web']], function () {
    Route::get('/', '\Aimeos\Shop\Controller\CatalogController@homeAction')->name('aimeos_home')->where( ['site' => '[a-z0-9\.\-]+'] );
});
woodwardmatt commented 2 years ago

For anyone else that comes across this, you need the following in your routes/web.php file:

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

Route::get('{path?}', '\Aimeos\Shop\Controller\PageController@indexAction')->name('aimeos_page')->where( 'path', '.*' );

The line from the above comment is removed:

Route::get('/', '\Aimeos\Shop\Controller\CatalogController@homeAction')->name('aimeos_home');