How to implement new entity into Aimeos admin panel ?

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!
MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

How to implement new entity into Aimeos admin panel ?

Post by MikaelNazarenko » 14 Jul 2019, 19:04

Hi, everybody, thank you for help.
My environment is the following:
Laravel Framework 5.8.26
aimeos-laravel 2019.04
PHP Version 7.2.19-1+ubuntu18.04.1+deb.sury.org+1

I build a project with Laravel+Aimeos and here I need to make a lot of customizations with aimeos admin panel.

I have implemented file attachments for users. For this I have created new table 'media'. I already have added new tab to admin panel. In this tab I need to display all attachments of current logged in user. Attachments can be retrieved by getMedia() method.

Aimeos structure is still not clear for me. I mean to display data I need get some manager object and do some staff like this:

Code: Select all

$params = $this->storeSearchParams( $view->param(), 'media' );
$manager = \Aimeos\MShop::create( $context, 'media' );
 /** @var \Aimeos\MW\Criteria\SQL $search */
$search = $this->initCriteria( $manager->createSearch(), $params );

$view->items = $manager->searchItems( $search, ['media'], $total );
So how can I display all attachments of current logged in user ?

In the documentation I have found that there are some domains are part of the Aimeos core, I think firstly I need add my new domain to the aimeos core ?

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

Re: How to implement new entity into Aimeos admin panel ?

Post by aimeos » 15 Jul 2019, 13:01

The easiest way is to copy the product media subpanel (class + template) and rename every occurence of "Product" to "Customer" and "product" to "customer". Then, add "media" to the list of subparts in the customer panel configuration:
https://github.com/aimeos/ai-admin-jqad ... dm.php#L61

That should be all you need to get the media tab into the customer panel. The customer panel lists all customers if you haven't restricted it to the current logged in user ( $context->getUserId() should to the trick). For the customer, in the detail view only his media files will be listed in the new tab.

The manager code you mention can be used to retrieve media items from the database manually like this:

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'media' );
$search = manager->createSearch();
$total = 0;
$view->items = $manager->searchItems( $search, [], $total );
$view->total = $total;
The initCriteria() method only sets the conditions and the sorting automatically depending on the given parameters.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply