Get the list of properties in media

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
AmzoooJibal
Posts: 35
Joined: 12 Mar 2021, 20:09

Get the list of properties in media

Post by AmzoooJibal » 22 Apr 2021, 10:43

Hello,
i need to get the list of properties in media domaine inside advanced section in catalog.

I have a catalog with list of media for the catalog i can do:

Code: Select all

$homeTree->getConfig()
Then to get the media:

Code: Select all

($mediaItems = $this->homeTree->getRefItems('media', 'stage', 'default'))->isEmpty())
Now for each mediaItem how i can get the config properties ?

User avatar
AmzoooJibal
Posts: 35
Joined: 12 Mar 2021, 20:09

Re: Get the list of properties in media

Post by AmzoooJibal » 22 Apr 2021, 11:12

Is Like this:

Code: Select all

   $this->homeTree->getListItem('media','default',$mediaItem->getId())->getConfig();

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

Re: Get the list of properties in media

Post by aimeos » 24 Apr 2021, 09:31

Media items doesn't have a configuration but you can attach property items to them (type, language, value pairs) in the admin backend. Then, you can get them using:

Code: Select all

foreach($this->homeTree->getRefItems('media','default') as $mediaItem) {
	print_r($mediaItem->getProperties('<type of the property>'));
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
AmzoooJibal
Posts: 35
Joined: 12 Mar 2021, 20:09

Re: Get the list of properties in media

Post by AmzoooJibal » 27 Apr 2021, 17:00

Thank you for you response.
It's a little complicated aimeos object.
With laravel Eloquent its easy to get child from parent even if the relation isnt loaded initially.
my question in home page i have a product object (Aimeos\MShop\Product\Item\Standard) and i need to access the variant product from this object how i can do that ?
i have tried but list empty:

Code: Select all

$product->getRefItems('attribute', null, 'variant')

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

Re: Get the list of properties in media

Post by aimeos » 01 May 2021, 16:09

AmzoooJibal wrote: 27 Apr 2021, 17:00 It's a little complicated aimeos object.
With laravel Eloquent its easy to get child from parent even if the relation isnt loaded initially.
That's one of the reasons we don't use Eloquent or something that offers that feature because this will load the related records on request. This turns into a performance nightmare if it's actually used because e.g. for a product list view with 100 products, 201 queries will be executed (one for all products, 100 for the relations and 100 for the attribute records) and people are complaining why it's so slow.

Contrary, in Aimeos you need to say upfront what should be loaded so there will be only three queries executed (one for the product, one for the relation and one for the attribute records).
AmzoooJibal wrote: 27 Apr 2021, 17:00 my question in home page i have a product object (Aimeos\MShop\Product\Item\Standard) and i need to access the variant product from this object how i can do that ?
i have tried but list empty:

Code: Select all

$product->getRefItems('attribute', null, 'variant')
Your code is correct but you need to configure that the product attributes should be loaded in the catalog/home component:
https://aimeos.org/docs/latest/config/c ... e/#domains
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply