The following code snipped integrates Virtuemart 3 product and media information into your articles - custom html.
This might be a viable alternative to the various extensions offered to achieve the same.
The code is "quick and dirty". Feel free to share your expert knowledge to optimize it.
The code is extracted right from the article text and it requires the Sourcerer plugin. I used the free version. Maybe someone knows how to prevent Joomla from stripping PHP even without Sourcerer. The text filtering settings do not achieve this for me.
The code is needed for a web solution where a roksprocket mosaic module is used to display product previews. The code retrieves the product by ID, which is hard-coded in the article.
{source 0}
<?php
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'config.php');
VmConfig::loadConfig();
if (!class_exists( 'VmModel' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'vmmodel.php');
if (!class_exists('VmMediaHandler')) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'mediahandler.php');
$productModel = VmModel::getModel('Product');
$mediaModel = VmModel::getModel('Media');
$product = $productModel->getProduct(628);
$media = $mediaModel->getFiles(true,true,$productModel->_id);
$index = 0;
/* Search the images of the product */
foreach($media as $key => $item)
{
if(strpos($item->getUrl(),'gruen') > 0) {
$index=$key;
break;
}
}
?>
<div class="sprocket-mosaic-image-container">
<a href="<?php echo $product->link;?>" style="font-weight: bold;">
<img src="<?php echo $media[$index]->getUrl();?>" alt=""/>
</a>
</div>
<div>
<center><br><?php echo $product->category_name; ?></center>
<center><br>ab €<?php echo number_format($product->prices,2,",","."); ?></center>
</div>
{/source}
Moderator von brandiware