How to load media associated with an attribute?
Posted: 15 Dec 2015, 18:50
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?