For the related products, I needed something different than the basic default Product image and name, so I have an override which pulls through the name, price and View Product Details button.
The only thing that I need now is to pull through the product image.
Here is my override code:
<?php
/**
*
* Show the product details page
*
* @package VirtueMart
* @subpackage
* @author Max Milbers, Valerie Isaksen
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* @version $Id: default_relatedproducts.php 6431 2012-09-12 12:31:31Z alatak $
*/
// Check to ensure this file is included in Joomla!
defined ( '_JEXEC' ) or die ( 'Restricted access' );
$model = new VirtueMartModelProduct();
$calculator = calculationHelper::getInstance();
$currency = CurrencyDisplay::getInstance();
?>
<div id="related-products">
<h3><?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h3>
<?php
foreach ($this->product->customfieldsRelatedProducts as $field) {
if(!empty($field->display)) {
?>
<div class="related-product">
<!--<span class="product-field-display"><?php echo $field->display ?></span>-->
<?php
$product = $model->getProductSingle($field->custom_value,false);
echo "<h4><a href='$product->link'>$product->product_name</a></h4>";
$price = $calculator -> getProductPrices($product);
echo "<div class='PricesalesPrice'>";
echo $currency->priceDisplay($price['salesPrice']);
echo "</div>";
echo "<a class='view-product-details' href='$product->link'><label>View Product Details</label></a>";
?>
</div>
<?php }
} ?>
</div>
Any ideas of how to pull through? I'm using Joomla 2.5.24 and VM 2.6.6.
Kind regards
Liam
$model->addImages($products); ?
Quote from: GJC Web Design on September 09, 2014, 09:26:16 AM
$model->addImages($products); ?
Thank you, the image url is now getting pulled through but I'm having an issue trying to display the image. If I put this code (below) it pulls through the url and displays it as text on the page:
echo $this->product->images[0]->file_url_thumb;
However if I try to put it within an img tag, it doesn't work and errors the PHP
echo "<img src='$this->product->images[0]->file_url_thumb' alt='$product->product_name' />";
Any ideas?
can only be a simple syntax error
as I don't know what $this->product->images[0]->file_url_thumb looks like I can't help
escape a " etc in the url?
Quote from: GJC Web Design on September 09, 2014, 11:54:15 AM
can only be a simple syntax error
as I don't know what $this->product->images[0]->file_url_thumb looks like I can't help
escape a " etc in the url?
Sorry I was talking rubbish, it was pulling through the thumbnail for the product that you were looking at (not the related product).
So I've added $model->addImages($products); to the page, what else should I do to actually display the product image?
Cheers
then it should be in your $products object - echo it out to check
I've been looking for this too!
You where very helpfull, I took your code and added the "missing" code (by quering the db) and show up the photos for each related product.
Also I've added this (http://www.gmarwaha.com/jquery/jcarousellite/#install) to make it spin..
<?php
/**
*
* Show the product details page
*
* @package VirtueMart
* @subpackage
* @author Max Milbers, Valerie Isaksen
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* @version $Id: default_relatedproducts.php 6431 2012-09-12 12:31:31Z alatak $
*/
// Check to ensure this file is included in Joomla!
defined ( '_JEXEC' ) or die ( 'Restricted access' );
$model = new VirtueMartModelProduct();
$calculator = calculationHelper::getInstance();
$currency = CurrencyDisplay::getInstance();
?>
<script type="text/javascript" src="<?php echo JURI::root () . "templates/ja_social/js/jquery1.js"; ?>"></script>
<script type="text/javascript" src="<?php echo JURI::root () . "/templates/ja_social/js/jcarousellite.js"; ?>"></script>
<script>
$.noConflict();
jQuery(document).ready(function($){
$(".related-products").jCarouselLite({
btnNext: ".slider-next",
btnPrev: ".slider-prev"
});
});
</script>
<div class="related-products">
<div class="rel_title">
<h3><?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h3>
<div class="movebtns">
<div class="slider-next"></div>
<div class="slider-prev"></div>
</div>
</div>
<div class="inner_ul">
<ul>
<?php
foreach ($this->product->customfieldsRelatedProducts as $field) {
if(!empty($field->display)) {
?>
<li class="li_car">
<div class="related-products-item">
<?php
$product = $model->getProductSingle($field->custom_value,false);
$pr_descr = mb_substr($product->product_name, 0, 20);
$qr = strlen($pr_descr);
if ($qr >= 20) {
$pr_descr1 = $pr_descr.".."; } else {
$pr_descr1 = $product->product_name;
}
?>
<h4><a href='<?php echo $product->link; ?>'><?php echo $pr_descr1 ?></a></h4>
<?php
//Load image path
$db = JFactory::getDBO();
$query = "SELECT file_url_thumb FROM #__virtuemart_medias WHERE virtuemart_media_id = (SELECT virtuemart_media_id FROM #__virtuemart_product_medias WHERE virtuemart_product_id =".$product->virtuemart_product_id.")";
$db->setQuery($query);
$img = $db->loadAssocList();
foreach ($img as $i) {
?>
<div class="img_rel"> <a href='<?php echo $product->link; ?>'><img src="<?php echo JURI::root () . $i['file_url_thumb'] ?>" /> </a> </div>
<?php
}
echo "<div><a class='view-product-details' href='$product->link'><label>Περισσότερα..</label></a></div>";
?>
</div>
</li>
<?php }
} ?>
</ul>
</div>
<?php $model->addImages($products);
?>
</div>
Hope you like it!
looks good
did u try
$product = $model->getProductSingle($field->custom_value,false);
// Load Images
$model->addImages($product);
?
saves the sql
Quote from: GJC Web Design on September 13, 2014, 22:45:54 PM
looks good
did u try
$product = $model->getProductSingle($field->custom_value,false);
// Load Images
$model->addImages($product);
?
saves the sql
I've just give it a try and yes you where correct..
posting the complete code below without sql code (commented out) and with "$model->addImages($product);" code.
Thanks!
<?php
/**
*
* Show the product details page
*
* @package VirtueMart
* @subpackage
* @author Max Milbers, Valerie Isaksen
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* @version $Id: default_relatedproducts.php 6431 2012-09-12 12:31:31Z alatak $
*/
// Check to ensure this file is included in Joomla!
defined ( '_JEXEC' ) or die ( 'Restricted access' );
$model = new VirtueMartModelProduct();
$calculator = calculationHelper::getInstance();
$currency = CurrencyDisplay::getInstance();
?>
<script type="text/javascript" src="<?php echo JURI::root () . "templates/ja_social/js/jquery.js"; ?>"></script>
<script type="text/javascript" src="<?php echo JURI::root () . "/templates/ja_social/js/jcarousellite.js"; ?>"></script>
<script>
$.noConflict();
jQuery(document).ready(function($){
$(".related-products").jCarouselLite({
btnNext: ".slider-next",
btnPrev: ".slider-prev"
});
});
</script>
<div class="related-products">
<div class="rel_title">
<h3><?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h3>
<div class="movebtns">
<div class="slider-next"></div>
<div class="slider-prev"></div>
</div>
</div>
<div class="inner_ul">
<ul>
<?php
foreach ($this->product->customfieldsRelatedProducts as $field) {
if(!empty($field->display)) {
?>
<li class="li_car">
<div class="related-products-item">
<?php
//$product = $model->getProductSingle($field->custom_value,false);
$product = $model->getProductSingle($field->custom_value,false);
// Load Images
$model->addImages($product);
$pr_descr = mb_substr($product->product_name, 0, 20);
$qr = strlen($pr_descr);
if ($qr >= 20) {
$pr_descr1 = $pr_descr.".."; } else {
$pr_descr1 = $product->product_name;
}
?>
<h4><a href='<?php echo $product->link; ?>'><?php echo $pr_descr1 ?></a></h4>
<?php
//Load image path
// $db = JFactory::getDBO();
// $query = "SELECT file_url_thumb FROM #__virtuemart_medias WHERE virtuemart_media_id = (SELECT virtuemart_media_id FROM #__virtuemart_product_medias WHERE virtuemart_product_id =".$product->virtuemart_product_id.")";
// $db->setQuery($query);
// $img = $db->loadAssocList();
// foreach ($img as $i) {
?>
<div class="img_rel"> <a href='<?php echo $product->link; ?>'><img src="<?php echo $product->images[0]->file_url_thumb; ?>" /> </a> </div>
<?php
// }
echo "<div><a class='view-product-details' href='$product->link'><label>Περισσότερα..</label></a></div>";
?>
</div>
</li>
<?php }
} ?>
</ul>
</div>
<?php $model->addImages($products);
?>
</div>