Laravel/Configure multiple shops

From Aimeos documentation

Other languages:
English 100%

2016.x version

Aimeos is multi-site capable and allows storing several shops in one database.

Create new site

Since version 1.1 of the Aimeos package, creating a new site is very easy. You only need to execute this command in the base directory of your Laravel application:

php artisan aimeos:setup <site code> [<template site>]

The value for "<site code>" can be either a new site code for creating a new site or an existing site code for updating a site. The "<template site>" code is optional and tells the setup command which site to use as reference when creating a new site (currently "default", "unittest" and "unitperf" are available as templates). If no value for "<template site>" is given, "default" is used.

If you update Aimeos from a previous version, you need to run the "aimeos:setup" command for all sites you've created! Otherwise, required records may be missing and existing data isn't migrated.

Don't forget to create the appropriate "locale" entries for your new site in the administration interface!

Adapt the routing

In order to tell your Laravel application which shop should be used, you have to use routes that include at least the "site" parameter. This is not necessary for the first shop (site: default).

The Aimeos shop package contains routes packaged into some route groups ("login", "admin", "account", "default", "confirm" and "update") that can be configured to support more than one shop. You have to add a "prefix" parameter with the value "{site}" in your config/shop.php:

  1. 'routes' => array(
  2. 	'account' => array('prefix' => '{site}', 'middleware' => ['web', 'auth']),
  3. 	'default' => array('prefix' => '{site}', 'middleware' => ['web']),
  4. 	'confirm' => array('prefix' => '{site}', 'middleware' => ['web']),
  5. ),

Then, the path of all routes additionally start with /{site}/ which contains the shop site code. There's no strict need to prefix the routes for "login", "admin" and "update", but you can give them a prefix as well. More details about the "prefix" setting including the possibility to add language and currency placeholders can be found in the article about custom routes.

The "web" middleware is only necessary for Laravel 5.2+ and it's not available in Laravel 5.0/5.1 so you have to remove it for these versions!