Hello!
Please tell how to get the main product image url in database query or in PHP uniquely? What is the criteria to select it correctly and unambiguously? VM 3
On product page
<?php echo $this->product->images[0]->file_url ;?>
On category page
<?php echo $product->images[0]->file_url ;?>
select it from DB (by product id)
<?php function pmedia($pid){
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName('#__virtuemart_product_medias'));
$query->where('ordering=1');
$query->where($db->quoteName('virtuemart_product_id')." = ".$db->quote($pid) );
$db->setQuery($query);
$row = $db->loadAssoc();
$mid=$row['virtuemart_media_id'];
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName('#__virtuemart_medias'));
$query->where($db->quoteName('virtuemart_media_id')." = ".$db->quote($mid));
$db->setQuery($query);
$row2 =$db->loadAssoc();
$image=$row2['file_url'];
return $image ;
}
?>
<?php echo pmedia(PRODUCT-ID-HERE);?>
Thank you!
I've found that in my db the combination of virtuemart_product_id and ordering in a virtuemart_product_medias table is not unique. I suggest development team to create the unique index on that fields combination in future if it's not already done
but that is what the ordering is for....
and never do this
echo $this->product->images[0]->file_url_thumb
use the getFileUrlThumb function instead. The best teacher is anyway the code.
Quote from: borro on September 30, 2016, 09:07:19 AM
Thank you!
I've found that in my db the combination of virtuemart_product_id and ordering in a virtuemart_product_medias table is not unique. I suggest development team to create the unique index on that fields combination in future if it's not already done
Why must this be unique?