How to load media associated with an attribute?
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
How to load media associated with an attribute?
I have an attribute with code 'attr-code1'
I have a media entry defined and associated with that attribute. Everything in the admin panel looks fine. If I open that attribute and click on the media tab, I see the media. In the database, the appropriate stuff is in mshop_attribute_list, etc.
I try to load the referenced media in my code like this (might not be most efficient?):
The attribute loads just fine. The call get getListItems( 'media', 'default' ) returns an empty list. I also tried getListItems( 'media' ) and getListItems() - all return an empty list.
What am I doing wrong?
I have a media entry defined and associated with that attribute. Everything in the admin panel looks fine. If I open that attribute and click on the media tab, I see the media. In the database, the appropriate stuff is in mshop_attribute_list, etc.
I try to load the referenced media in my code like this (might not be most efficient?):
Code: Select all
$attributeManager = MShop_Factory::createManager( $context, 'attribute' );
$search = $attributeManager->createSearch( true );
$expr = array(
$search->getConditions(),
$search->compare( '==', 'attribute.code', 'attr-code1' ),
);
$search->setConditions( $search->combine( '&&', $expr ) );
$search->setSortations( array( $search->sort( '-', 'attribute.id' ) ) );
$dlAttrList = $attributeManager->searchItems( $search );
$downloadAttribute = reset( $dlAttrList );
foreach( $downloadAttribute->getListItems( 'media', 'default' ) as $media )
{
// do stuff
}
What am I doing wrong?
Re: How to load media associated with an attribute?
Found it. Forgot to add the media references to the searchItems so the references would get loaded. Need more coffee.
Re: How to load media associated with an attribute?
You have to tell the manager that it should load the referenced attributes to:swpierce wrote:Code: Select all
$dlAttrList = $attributeManager->searchItems( $search );
Code: Select all
$attributeManager->searchItems( $search, array( 'attribute' ) );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star