Allow Aimeos Admin route to load

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!
rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Allow Aimeos Admin route to load

Post by rhand » 31 May 2024, 04:30

I now have a new admin route in `config/shop.php`:

Code: Select all

'admin' => ['prefix' => 'store-admin', 'middleware' => ['web']]
and that route works as I can see listing all routes and filtering by store. Also adding some more with the same prefix:

Code: Select all

php artisan route:list --path=store
....
GET|HEAD  store-admin ........................................................................................ aimeos_shop_admin › Aimeos\Shop › AdminController@indexAction
  POST      store-admin/{site}/jqadm/batch/{resource} .................................................... aimeos_shop_jqadm_batch › Aimeos\Shop › JqadmController@batchAction
  GET|POST|HEAD store-admin/{site}/jqadm/copy/{resource}/{id} .............................................. aimeos_shop_jqadm_copy › Aimeos\Shop › JqadmController@copyAction
  GET|POST|HEAD store-admin/{site}/jqadm/create/{resource} ............................................. aimeos_shop_jqadm_create › Aimeos\Shop › JqadmController@createAction
  POST      store-admin/{site}/jqadm/delete/{resource}/{id?} ........................................... aimeos_shop_jqadm_delete › Aimeos\Shop › JqadmController@deleteAction
  GET|POST|HEAD store-admin/{site}/jqadm/export/{resource} ............................................. aimeos_shop_jqadm_export › Aimeos\Shop › JqadmController@exportAction
  ...
  
But somehow in dashboard I am sent to login, guess via auth middleware and then to general dashboard index view:

Code: Select all

Redirect Response
302
Access-Control-Allow-Origin: *
Cache-Control: no-cache, private
Date: Fri, 31 May 2024 04:10:59 GMT
Location: https://site.test/dashboard
For dashboard in web.php I have

Code: Select all

Route::domain(config('name.app_domain'))->group(function () {
...
/*
    |--------------------------------------------------------------------------
    | Dashboard Routes
    |--------------------------------------------------------------------------
    */
    Route::prefix('dashboard')->middleware('auth')->group(function () {
        ....
    Route::get('/', [Dashboard\DashboardController::class, 'index'])->name('dashboard');
    ...
    });
    ...
// To allow loading of pages directly, not just via index or homepage
    Route::get('{any?}', [HomesController::class, 'index']);
    
});
I think

Code: Select all

Route::get('{any?}', [HomesController::class, 'index']);
may be overriding the Aimeos route for

Code: Select all

 'admin' => ['prefix' => 'store-admin', 'middleware' => ['web']],
 
Just need to think how I can get this Aimeos route to work without redirect. Seeing anything?

rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Re: Allow Aimeos Admin route to load

Post by rhand » 31 May 2024, 05:50

I think the issue is the catch all. And that gets me back to earlier post wondering if I cannot just move the shop routes to web.php where I can add them all to the Dashboard routes with auth middleware check. Probably can and am trying but routes like

Code: Select all

// Aimeos Routes
      Route::prefix('store-admin')->middleware('web')->group(function () {
      Route::get('admin', [\Aimeos\Shop\Controller\AdminController::class, 'indexAction']);
      });
still fails with

Code: Select all

URL: https://site.test/store-admin
URL: https://site.test/login?locale=en
URL: https://site.test/dashboard
Status: 200

rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Re: Allow Aimeos Admin route to load

Post by rhand » 02 Jun 2024, 05:04

I think the main issue is that the roles the user I am logged into the Laravel application do not work on Aimeos shop yet. Aimeos users are in another database and to Aimeos I am not logged in yet so that is why I get sent to login on trying the load the main shop. So I need to have at least an existing role like superadmin in application sync with Aimeos user role for it so that I am automatically logged into main store if I am logged in main application as superadmin. I also need to have the user and role created in Aimeos on logging in if it is not there.

I probably need a middleware to synchronize the user's roles from the main database with the Aimeos shop roles on login. This middleware will ensure that whenever a user logs in, their roles are updated in the Aimeos system. But I also would need to add the user if it is missing I think.

That makes me wonder. Should I have chosen a separate database or should I use just the main one? And two, does Aimeos just update the users table in Laravel and add roles or do the migrations overwrite all?

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

Re: Allow Aimeos Admin route to load

Post by aimeos » 03 Jun 2024, 07:49

rhand wrote: 02 Jun 2024, 05:04 That makes me wonder. Should I have chosen a separate database or should I use just the main one? And two, does Aimeos just update the users table in Laravel and add roles or do the migrations overwrite all?
If you configure a separate database for Aimeos tables, you must configure the "db-customer" connection in the ./config/shop.php to use the main database. The keys in section "db" and "db-customer" are the same, just the database and the credentials need to be for the appropriate database:
https://github.com/aimeos/aimeos-larave ... hp#L51-L66

Example:

Code: Select all

		'db' => [
			'adapter' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.driver', 'mysql' ),
			'host' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.host', '127.0.0.1' ),
			'port' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.port', '3306' ),
			'socket' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.unix_socket', '' ),
			'database' => env('DB_AIMEOS_DATABASE', 'aimeos_db'),
			'username' => env('DB_AIMEOS_USERNAME', 'aimeos'),
			'password' => env('DB_AIMEOS_PASSWORD', ''),
			'stmt' => config( 'database.default', 'mysql' ) === 'mysql' ? ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'"] : [],
			'limit' => 3, // maximum number of concurrent database connections
			'defaultTableOptions' => [
				'charset' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.charset' ),
				'collate' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.collation' ),
			],
			'driverOptions' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.options' ),
		],
		'db-customer' => [
			'adapter' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.driver', 'mysql' ),
			'host' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.host', '127.0.0.1' ),
			'port' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.port', '3306' ),
			'socket' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.unix_socket', '' ),
			'database' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.database', 'forge' ),
			'username' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.username', 'forge' ),
			'password' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.password', '' ),
			'stmt' => config( 'database.default', 'mysql' ) === 'mysql' ? ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'"] : [],
			'limit' => 3, // maximum number of concurrent database connections
			'defaultTableOptions' => [
				'charset' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.charset' ),
				'collate' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.collation' ),
			],
			'driverOptions' => config( 'database.connections.' . config( 'database.default', 'mysql' ) . '.options' ),
		],
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Re: Allow Aimeos Admin route to load

Post by rhand » 06 Jun 2024, 06:11

I did not adjust db-customer in shop configuration . I have

Code: Select all

<?php

return [

    'apc_enabled' => false, // enable for maximum performance if APCu is available
    'apc_prefix' => 'laravel:', // 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
    'roles' => ['admin', 'editor, smart-administrator'.'administrator'], // user groups allowed to access the admin backend
    'panel' => 'dashboard', // panel shown in admin backend after login

    'routes' => [
        // Docs: https://aimeos.org/docs/latest/laravel/extend/#custom-routes
        // Multi-sites: https://aimeos.org/docs/latest/laravel/customize/#multiple-shops
        // 'admin' => ['prefix' => 'admin', 'middleware' => ['web']],
        'admin' => ['prefix' => 'store-admin', 'middleware' => ['auth', 'web']],
        // 'jqadm' => ['prefix' => 'admin/{site}/jqadm', 'middleware' => ['web', 'auth']],
        'jqadm' => ['prefix' => 'store-admin/{site}/jqadm', 'middleware' => ['web', 'auth']],
        // 'graphql' => ['prefix' => 'admin/{site}/graphql', 'middleware' => ['web', 'auth']],
        'graphql' => false,
        // 'jsonadm' => ['prefix' => 'admin/{site}/jsonadm', 'middleware' => ['web', 'auth']],
        // 'jsonapi' => ['prefix' => 'jsonapi', 'middleware' => ['web', 'api']],
        'jsonadm' => ['prefix' => 'store-admin/{site}/jsonadm', 'middleware' => ['web', 'auth']],
        'jsonapi' => ['prefix' => 'store-jsonapi', 'middleware' => ['web', 'api']],
        // 'account' => ['prefix' => 'profile', 'middleware' => ['web', 'auth']],
        // 'default' => ['prefix' => 'shop', 'middleware' => ['web']],
        'default' => false,
        // 'confirm' => ['prefix' => 'shop', 'middleware' => ['web']],
        'confirm' => false,
        // 'supplier' => ['prefix' => 's', 'middleware' => ['web']],
        // 'page' => ['prefix' => 'p', 'middleware' => ['web']],
        // 'home' => ['middleware' => ['web']],
        'home' => false,
        // 'update' => [],
    ],

    'page' => [
        'account-index' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'account/profile', 'account/review', 'account/subscription', 'account/basket', 'account/history', 'account/favorite', 'account/watch', 'catalog/session'],
        'basket-index' => ['locale/select', 'catalog/tree', 'catalog/search', 'basket/standard', 'basket/bulk', 'basket/related'],
        'catalog-count' => ['catalog/count'],
        'catalog-detail' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'catalog/stage', 'catalog/detail', 'catalog/session'],
        'catalog-home' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'catalog/home'],
        'catalog-list' => ['locale/select', 'basket/mini', 'catalog/filter', 'catalog/tree', 'catalog/search', 'catalog/price', 'catalog/supplier', 'catalog/attribute', 'catalog/session', 'catalog/stage', 'catalog/lists'],
        'catalog-session' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'catalog/session'],
        'catalog-stock' => ['catalog/stock'],
        'catalog-suggest' => ['catalog/suggest'],
        'catalog-tree' => ['locale/select', 'basket/mini', 'catalog/filter', 'catalog/tree', 'catalog/search', 'catalog/price', 'catalog/supplier', 'catalog/attribute', 'catalog/session', 'catalog/stage', 'catalog/lists'],
        'checkout-confirm' => ['catalog/tree', 'catalog/search', 'checkout/confirm'],
        'checkout-index' => ['locale/select', 'catalog/tree', 'catalog/search', 'checkout/standard'],
        'checkout-update' => ['checkout/update'],
        'supplier-detail' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'supplier/detail', 'catalog/lists'],
        'cms' => ['cms/page', 'catalog/tree', 'basket/mini'],
    ],

    'resource' => [
        'db' => [
            'adapter' => config('database.connections.'.config('database.default', 'mysql').'.driver', 'mysql'),
            'host' => env('DB_AIMEOS_HOST', 'localhost'),
            'port' => env('DB_AIMEOS_PORT', '3306'),
            'socket' => config('database.connections.'.config('database.default', 'mysql').'.unix_socket', ''),
            'database' => env('DB_AIMEOS_DATABASE', 'aimeos'),
            'username' => env('DB_AIMEOS_USERNAME', 'forge'),
            'password' => env('DB_AIMEOS_PASSWORD', ''),
            'stmt' => config('database.default', 'mysql') === 'mysql' ? ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'"] : [],
            'limit' => 3, // maximum number of concurrent database connections
            'defaultTableOptions' => [
                'charset' => config('database.connections.'.config('database.default', 'mysql').'.charset'),
                'collate' => config('database.connections.'.config('database.default', 'mysql').'.collation'),
            ],
            'driverOptions' => config('database.connections.'.config('database.default', 'mysql').'.options'),
        ],
        'fs' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => public_path(),
            'baseurl' => rtrim(env('ASSET_URL', PHP_SAPI == 'cli' ? env('APP_URL') : ''), '/'),
        ],
        'fs-media' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => public_path('aimeos'),
            'baseurl' => rtrim(env('ASSET_URL', PHP_SAPI == 'cli' ? env('APP_URL') : ''), '/').'/aimeos',
        ],
        'fs-mimeicon' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => public_path('vendor/shop/mimeicons'),
            'baseurl' => rtrim(env('ASSET_URL', PHP_SAPI == 'cli' ? env('APP_URL') : ''), '/').'/vendor/shop/mimeicons',
        ],
        'fs-theme' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => public_path('vendor/shop/themes'),
            'baseurl' => rtrim(env('ASSET_URL', PHP_SAPI == 'cli' ? env('APP_URL') : ''), '/').'/vendor/shop/themes',
        ],
        'fs-admin' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => storage_path('admin'),
        ],
        'fs-export' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => storage_path('export'),
        ],
        'fs-import' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => storage_path('import'),
        ],
        'fs-secure' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => storage_path('secure'),
        ],
        'mq' => [
            'adapter' => 'Standard',
            'db' => 'db',
        ],
        'email' => [
            'from-email' => config('mail.from.address'),
            'from-name' => config('mail.from.name'),
        ],
    ],

    'admin' => [],

    'client' => [
        'html' => [
            'basket' => [
                'cache' => [
                    // 'enable' => false, // Disable basket content caching for development
                ],
            ],
            'common' => [
                'cache' => [
                    // 'force' => true // enforce caching for logged in users
                ],
            ],
            'catalog' => [
                'lists' => [
                    'basket-add' => true, // shows add to basket in list views
                    // 'infinite-scroll' => true, // load more products in list view
                    // 'size' => 48, // number of products per page
                ],
                'selection' => [
                    'type' => [ // how variant attributes are displayed
                        'color' => 'radio',
                        'length' => 'radio',
                        'width' => 'radio',
                    ],
                ],
            ],
        ],
    ],

    'controller' => [
        'frontend' => [
            'catalog' => [
                'levels-always' => 3, // number of category levels for mega menu
            ],
        ],
    ],

    'i18n' => [],

    'madmin' => [
        'cache' => [
            'manager' => [
                // 'name' => 'None', // Disable caching for development
            ],
        ],
        'log' => [
            'manager' => [
                // 'loglevel' => 7, // Enable debug logging into madmin_log table
            ],
        ],
    ],

    'mshop' => [
        'locale' => [
            // 'site' => '<custom site code>', // used instead of "default"
        ],
    ],

    'command' => [],

    'frontend' => [],

    'backend' => [],

];
Now. And that config/shop.php does not have settings for db-customer. Should I add or is my older Laravel 9 compatible version not going to work with it?

Reading https://aimeos.org/docs/2024.x/infrastr ... -databases some more..

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

Re: Allow Aimeos Admin route to load

Post by aimeos » 06 Jun 2024, 07:30

Multiple database for different data domains are supported since the beginning of Aimeos.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Re: Allow Aimeos Admin route to load

Post by rhand » 06 Jun 2024, 08:30

I see. Thanks for the replies so far. Learning a lot. Now I have this for `config/shop.php`:

Code: Select all

<?php

return [

    'apc_enabled' => false, // enable for maximum performance if APCu is available
    'apc_prefix' => 'laravel:', // 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
    'roles' => ['admin', 'editor, smart-administrator'.'administrator'], // user groups allowed to access the admin backend
    'panel' => 'dashboard', // panel shown in admin backend after login

    'routes' => [
        // Docs: https://aimeos.org/docs/latest/laravel/extend/#custom-routes
        // Multi-sites: https://aimeos.org/docs/latest/laravel/customize/#multiple-shops
        // 'admin' => ['prefix' => 'admin', 'middleware' => ['web']],
        'admin' => ['prefix' => 'store-admin', 'middleware' => ['auth', 'web']],
        // 'jqadm' => ['prefix' => 'admin/{site}/jqadm', 'middleware' => ['web', 'auth']],
        'jqadm' => ['prefix' => 'store-admin/{site}/jqadm', 'middleware' => ['web', 'auth']],
        // 'graphql' => ['prefix' => 'admin/{site}/graphql', 'middleware' => ['web', 'auth']],
        'graphql' => false,
        // 'jsonadm' => ['prefix' => 'admin/{site}/jsonadm', 'middleware' => ['web', 'auth']],
        // 'jsonapi' => ['prefix' => 'jsonapi', 'middleware' => ['web', 'api']],
        'jsonadm' => ['prefix' => 'store-admin/{site}/jsonadm', 'middleware' => ['web', 'auth']],
        'jsonapi' => ['prefix' => 'store-jsonapi', 'middleware' => ['web', 'api']],
        // 'account' => ['prefix' => 'profile', 'middleware' => ['web', 'auth']],
        // 'default' => ['prefix' => 'shop', 'middleware' => ['web']],
        'default' => false,
        // 'confirm' => ['prefix' => 'shop', 'middleware' => ['web']],
        'confirm' => false,
        // 'supplier' => ['prefix' => 's', 'middleware' => ['web']],
        // 'page' => ['prefix' => 'p', 'middleware' => ['web']],
        // 'home' => ['middleware' => ['web']],
        'home' => false,
        // 'update' => [],
    ],

    'page' => [
        'account-index' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'account/profile', 'account/review', 'account/subscription', 'account/basket', 'account/history', 'account/favorite', 'account/watch', 'catalog/session'],
        'basket-index' => ['locale/select', 'catalog/tree', 'catalog/search', 'basket/standard', 'basket/bulk', 'basket/related'],
        'catalog-count' => ['catalog/count'],
        'catalog-detail' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'catalog/stage', 'catalog/detail', 'catalog/session'],
        'catalog-home' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'catalog/home'],
        'catalog-list' => ['locale/select', 'basket/mini', 'catalog/filter', 'catalog/tree', 'catalog/search', 'catalog/price', 'catalog/supplier', 'catalog/attribute', 'catalog/session', 'catalog/stage', 'catalog/lists'],
        'catalog-session' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'catalog/session'],
        'catalog-stock' => ['catalog/stock'],
        'catalog-suggest' => ['catalog/suggest'],
        'catalog-tree' => ['locale/select', 'basket/mini', 'catalog/filter', 'catalog/tree', 'catalog/search', 'catalog/price', 'catalog/supplier', 'catalog/attribute', 'catalog/session', 'catalog/stage', 'catalog/lists'],
        'checkout-confirm' => ['catalog/tree', 'catalog/search', 'checkout/confirm'],
        'checkout-index' => ['locale/select', 'catalog/tree', 'catalog/search', 'checkout/standard'],
        'checkout-update' => ['checkout/update'],
        'supplier-detail' => ['locale/select', 'basket/mini', 'catalog/tree', 'catalog/search', 'supplier/detail', 'catalog/lists'],
        'cms' => ['cms/page', 'catalog/tree', 'basket/mini'],
    ],

    'resource' => [
        'db' => [
            'adapter' => config('database.connections.'.config('database.default', 'mysql').'.driver', 'mysql'),
            'host' => env('DB_AIMEOS_HOST', 'localhost'),
            'port' => env('DB_AIMEOS_PORT', '3306'),
            'socket' => config('database.connections.'.config('database.default', 'mysql').'.unix_socket', ''),
            'database' => env('DB_AIMEOS_DATABASE', 'aimeos'),
            'username' => env('DB_AIMEOS_USERNAME', 'forge'),
            'password' => env('DB_AIMEOS_PASSWORD', ''),
            'stmt' => config('database.default', 'mysql') === 'mysql' ? ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'"] : [],
            'limit' => 3, // maximum number of concurrent database connections
            'defaultTableOptions' => [
                'charset' => config('database.connections.'.config('database.default', 'mysql').'.charset'),
                'collate' => config('database.connections.'.config('database.default', 'mysql').'.collation'),
            ],
            'driverOptions' => config('database.connections.'.config('database.default', 'mysql').'.options'),
        ],
        'db-customer' => [
            'adapter' => 'mysql',
            'host' => 'localhost',
            'port' => '3306',
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'stmt' => ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED"],
            'limit' => 2,
            'opt-persistent' => 0
        ],
    
        'fs' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => public_path(),
            'baseurl' => rtrim(env('ASSET_URL', PHP_SAPI == 'cli' ? env('APP_URL') : ''), '/'),
        ],
        'fs-media' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => public_path('aimeos'),
            'baseurl' => rtrim(env('ASSET_URL', PHP_SAPI == 'cli' ? env('APP_URL') : ''), '/').'/aimeos',
        ],
        'fs-mimeicon' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => public_path('vendor/shop/mimeicons'),
            'baseurl' => rtrim(env('ASSET_URL', PHP_SAPI == 'cli' ? env('APP_URL') : ''), '/').'/vendor/shop/mimeicons',
        ],
        'fs-theme' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => public_path('vendor/shop/themes'),
            'baseurl' => rtrim(env('ASSET_URL', PHP_SAPI == 'cli' ? env('APP_URL') : ''), '/').'/vendor/shop/themes',
        ],
        'fs-admin' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => storage_path('admin'),
        ],
        'fs-export' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => storage_path('export'),
        ],
        'fs-import' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => storage_path('import'),
        ],
        'fs-secure' => [
            'adapter' => 'Standard',
            'tempdir' => storage_path('tmp'),
            'basedir' => storage_path('secure'),
        ],
        'mq' => [
            'adapter' => 'Standard',
            'db' => 'db',
        ],
        'email' => [
            'from-email' => config('mail.from.address'),
            'from-name' => config('mail.from.name'),
        ],
    ],

    'admin' => [],

    'client' => [
        'html' => [
            'basket' => [
                'cache' => [
                    // 'enable' => false, // Disable basket content caching for development
                ],
            ],
            'common' => [
                'cache' => [
                    // 'force' => true // enforce caching for logged in users
                ],
            ],
            'catalog' => [
                'lists' => [
                    'basket-add' => true, // shows add to basket in list views
                    // 'infinite-scroll' => true, // load more products in list view
                    // 'size' => 48, // number of products per page
                ],
                'selection' => [
                    'type' => [ // how variant attributes are displayed
                        'color' => 'radio',
                        'length' => 'radio',
                        'width' => 'radio',
                    ],
                ],
            ],
        ],
    ],

    'controller' => [
        'frontend' => [
            'catalog' => [
                'levels-always' => 3, // number of category levels for mega menu
            ],
        ],
    ],

    'i18n' => [],

    'madmin' => [
        'cache' => [
            'manager' => [
                // 'name' => 'None', // Disable caching for development
            ],
        ],
        'log' => [
            'manager' => [
                // 'loglevel' => 7, // Enable debug logging into madmin_log table
            ],
        ],
    ],

    'mshop' => [
        'locale' => [
            // 'site' => '<custom site code>', // used instead of "default"
        ],
    ],

    'command' => [],

    'frontend' => [],

    'backend' => [],

];
Still getting redirected to /dashboard via /login

Code: Select all

URL: https://site.test/store-admin
URL: https://site.test/login?locale=en
URL: https://site.test/dashboard
Status: 200
Source: Network
Address: 127.0.0.1:443
...
Redirect Response
302
Access-Control-Allow-Origin: *
Cache-Control: no-cache, private
Date: Thu, 06 Jun 2024 08:27:24 GMT
Location: https://site.test/login?locale=en

so auth middleware might still be interfering. Did add db-customer data and added settings for main database for that one.

For first call debugger shows this gate error:

Code: Select all

admin [▼
  "ability" => "admin"
  "result" => null
  "user" => 1
  "arguments" => """
    [
\n

      0 => Aimeos\Shop\Controller\AdminController, 
\n

      1 => [
\n

        0 => admin, 
\n

        1 => editor, 
\n

        2 => smart-administrator, 
\n

        3 => administrator
\n

      ]
\n

    ]
    """
]
and for query

Code: Select all

select * from `users` where `id` = 1 and `users`.`deleted_at` is null limit 1
1.08ms
main
EloquentUserProvider.php#59
with main being main database. Seems main application database is hit but I guess I need to add role or ability admin to user..?

Also, what is meant by data domain exactly?

rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Re: Allow Aimeos Admin route to load

Post by rhand » 07 Jun 2024, 01:46

Updated app/Providers/AuthServiceProvider.php with

Code: Select all

...
 Gate::define('admin', function (User $user) {
            $role = data_get($user->role, 'name');
            return in_array($role, [UserRole::EDITOR, UserRole::SUPER_ADMIN, 'admin']);
        });
...
based on config/shop.php
```

Code: Select all

...
'roles' => ['admin'], // user groups allowed to access the admin backend
...
and now /store-admin redirected to store-admin/default/jqadm/search/dashboard?locale=en but I get another error

Code: Select all

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'main-app.mshop_customer_group' doesn't exist: SELECT mcusgr."id" AS "customer.group.id", mcusgr."siteid" AS "customer.group.siteid", mcusgr."code" AS "customer.group.code", mcusgr."label" AS "customer.group.label", mcusgr."mtime" AS "customer.group.mtime", mcusgr."editor" AS "customer.group.editor", mcusgr."ctime" AS "customer.group.ctime" FROM "mshop_customer_group" mcusgr WHERE ( ( mcusgr."siteid" IN ('','1.') ) AND mcusgr."id" IN (NULL) ) ORDER BY mcusgr."id" ASC LIMIT 100 OFFSET 0
vendor/aimeos/aimeos-base/src/DB/Statement/DBAL/Simple.php#75
It seems the table is being retrieved from the main application not the Aimeos database. I did adjust matters to use main application for users data, but shop_customer_group should be gotten from aimeos database. What to do? Do I need to add another connection then? How ? I tried

Code: Select all

'db-customer-group' => [
            'adapter' => 'mysql',
            'host' => env('DB_AIMEOS_HOST', 'localhost'),
            'port' => env('DB_AIMEOS_PORT', '3306'),
            'database' => env('DB_AIMEOS_DATABASE', 'aimeos'),
            'username' => env('DB_AIMEOS_USERNAME', 'forge'),
            'password' => env('DB_AIMEOS_PASSWORD', ''),
            'stmt' => ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED"],
            'limit' => 2,
            'opt-persistent' => 0
        ],
But it did not work. I did php artisan config:cache and php artisan route:clear, but still the same error that the main application database was chosen to load the customer group table. But the data domains listed does not contain customer group either
In fact, there are 16 different data domains which can be stored in one database each.

Also added `resource.php` to `config` with

Code: Select all

<?php
return [
    'db-customer-group' => [
            'adapter' => 'mysql',
            'host' => env('DB_AIMEOS_HOST', 'localhost'),
            'port' => env('DB_AIMEOS_PORT', '3306'),
            'database' => env('DB_AIMEOS_DATABASE', 'aimeos'),
            'username' => env('DB_AIMEOS_USERNAME', 'forge'),
            'password' => env('DB_AIMEOS_PASSWORD', ''),
            'stmt' => ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED"],
            'limit' => 2,
            'opt-persistent' => 0
        ],
];
and emptied cache and re-cached config. No change. Clearly need to learn about data domains more.. or model scheme settings?

rhand
Posts: 23
Joined: 12 Apr 2024, 03:06

Re: Allow Aimeos Admin route to load

Post by rhand » 07 Jun 2024, 03:24

I commented out db-customer in shop.php. Reason I removed db-customer data domain is that customer group will then also get loaded from main database and that caused other issues. I also used:

Code: Select all

'roles' => ['admin', 'smart-administrator', 'administrator'], // user groups allowed to access the admin backend
for roles and kept gate added to app/Providers/AuthServiceProvider.php

Code: Select all

<?php

namespace App\Providers;

use App\Enums\UserRole;
use App\Models\Auth\User;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        \App\Models\Editor\Project::class => \App\Policies\ProjectPolicy::class,
        \App\Order::class => \App\Policies\OrderPolicy::class,
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        Gate::define('editor', function (User $user) {
            return data_get($user->role, 'name') === UserRole::EDITOR;
        });
        // superadmin role Aimeos access
        Gate::define('admin', function (User $user) {
            $role = data_get($user->role, 'name');
            return in_array($role, [UserRole::EDITOR, UserRole::SUPER_ADMIN, 'admin']);
        });
    }
}
Then I got the error:

Code: Select all

Aimeos\ Admin \ JQAdm \ 
Exception
PHP 8.2.15
9.52.16
Not allowed to access JQAdm "dashboard" client
So App auth with new gate allows user to pass but jQAdmin does not. Error seems based on

Code: Select all

if( $view->access( $config->get( 'admin/jqadm/resource/' . $path . '/groups', [] ) ) !== true ) {
throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Not allowed to access JQAdm "%1$s" client', $path ), 403 );
}

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

Re: Allow Aimeos Admin route to load

Post by aimeos » 07 Jun 2024, 10:01

That error message looks like you are using 2023.10 or before, not current 2024.04 (there's nothing wrong with that, just to make sure):

Code: Select all

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'main-app.mshop_customer_group' doesn't exist
When you configure "db-customer" connection to point to your main database, you also have to add the Aimeos admin accounts again because they are not in the "users" table of your main DB yet (only in the Aimeos DB):

Code: Select all

php artisan aimeos:account --super you@example.com
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply