VM 3.0.10
J! 3.4.4
If a related product is unpublished the related product section is still shown (empty) in product details and in the FancyBox after 'Add to cart'
eg with default data I have added TS-large as a related product to TS-small and then unpublished TS-Large.
The attached screen shots illustrate the problem.
There is no problem with unpublished related categories.
Although only a cosmetic error this was annoying my sensibilities so I investigated.
Before displaying the section title for related products we need to know if there will actually be anything to display.
Here is my crude fix - I am sure there ought to be a better way but I am not sufficiently familiar with the api.
Two files to override in VM 3.0.10 - my amendments are commented with optmax
The product details uses the customfields sublayout
your-template/com_virtuemart/sublayout/customfields.php
<?php
/**
* sublayout products
*
* @package VirtueMart
* @author Max Milbers
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2014 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL2, see LICENSE.php
* @version $Id: cart.php 7682 2014-02-26 17:07:20Z Milbo $
*/
defined('_JEXEC') or die('Restricted access');
$product = $viewData['product'];
$position = $viewData['position'];
$customTitle = isset($viewData['customTitle'])? $viewData['customTitle']: false;;
if(isset($viewData['class'])){
$class = $viewData['class'];
} else {
$class = 'product-fields';
}
if (!empty($product->customfieldsSorted[$position])) {
/* optmax //http://forum.virtuemart.net/index.php?topic=131724.0
* Modification to prevent related products section title display when there are no related products
* Check if any related produc thas something to display
*/
$show_relatedproducts_title = false;
foreach ($product->customfieldsSorted[$position] as $field) {
if (!( $field->is_hidden || empty($field->display))) {
$show_relatedproducts_title = true; // optmax - found a related product to display
break; //optmax - so no need to look for any more
}
}
/* optmax
* Only carry on if there is something to display
*/
if($show_relatedproducts_title) {
?>
<div class="<?php echo $class?>">
<?php
if($customTitle and isset($product->customfieldsSorted[$position][0])){
$field = $product->customfieldsSorted[$position][0]; ?>
<div class="product-fields-title-wrapper"><span class="product-fields-title"><strong><?php echo vmText::_ ($field->custom_title) ?></strong></span>
<?php if ($field->custom_tip) {
echo JHtml::tooltip (vmText::_($field->custom_tip), vmText::_ ($field->custom_title), 'tooltip.png');
} ?>
</div> <?php
}
$custom_title = null;
foreach ($product->customfieldsSorted[$position] as $field) {
//var_dump($field);
if ( $field->is_hidden || empty($field->display)) continue; //OSP http://forum.virtuemart.net/index.php?topic=99320.0
?><div class="product-field product-field-type-<?php echo $field->field_type ?>">
<?php if (!$customTitle and $field->custom_title != $custom_title and $field->show_title) { ?>
<span class="product-fields-title-wrapper"><span class="product-fields-title"><strong><?php echo vmText::_ ($field->custom_title) ?></strong></span>
<?php if ($field->custom_tip) {
echo JHtml::tooltip (vmText::_($field->custom_tip), vmText::_ ($field->custom_title), 'tooltip.png');
} ?></span>
<?php }
if (!empty($field->display)){
?><div class="product-field-display"><?php echo $field->display ?></div><?php
}
if (!empty($field->custom_desc)){
?><div class="product-field-desc"><?php echo vmText::_($field->custom_desc) ?></div> <?php
}
?>
</div>
<?php
$custom_title = $field->custom_title;
} ?>
<div class="clear"></div>
</div>
<?php
/*optmax
* Finish the check
*/
}
} ?>
For the FancyBox popup
your-template/com_virtuemart/html/cart/padded.php
<?php
/**
*
* Layout for the add to cart popup
*
* @package VirtueMart
* @subpackage Cart
* @author Max Milbers
*
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2013 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: cart.php 2551 2010-09-30 18:52:40Z milbo $
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
echo '<a class="continue_link" href="' . $this->continue_link . '" >' . vmText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';
echo '<a class="showcart floatright" href="' . $this->cart_link . '">' . vmText::_('COM_VIRTUEMART_CART_SHOW') . '</a>';
if($this->products){
foreach($this->products as $product){
if($product->quantity>0){
echo '<h4>'.vmText::sprintf('COM_VIRTUEMART_CART_PRODUCT_ADDED',$product->product_name,$product->quantity).'</h4>';
} else {
if(!empty($product->errorMsg)){
echo '<div>'.$product->errorMsg.'</div>';
}
}
}
}
if(VmConfig::get('popup_rel',1)){
//VmConfig::$echoDebug=true;
if ($this->products and is_array($this->products) and count($this->products)>0 ) {
$product = reset($this->products);
$customFieldsModel = VmModel::getModel('customfields');
$product->customfields = $customFieldsModel->getCustomEmbeddedProductCustomFields($product->allIds,'R');
$customFieldsModel->displayProductCustomfieldFE($product,$product->customfields);
if(!empty($product->customfields)){
/* optmax //http://forum.virtuemart.net/index.php?topic=131724.0
* Modification to prevent related products section title display when there are no related products
* Check if any related produc thas something to display
*/
$show_relatedproducts_title = false;
foreach($product->customfields as $rFields){
if(!empty($rFields->display)) {
$show_relatedproducts_title = true; // optmax - found a related product to display
break; //optmax - so no need to look for any more
}
}
/* optmax
* Only carry on if there is something to display
*/
if($show_relatedproducts_title){
?>
<div class="product-related-products">
<h4><?php echo vmText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h4>
<?php
foreach($product->customfields as $rFields){
if(!empty($rFields->display)){
?><div class="product-field product-field-type-<?php echo $rFields->field_type ?>">
<div class="product-field-display"><?php echo $rFields->display ?></div>
</div>
<?php }
} ?>
</div>
<?php
/*optmax
* Finish the check
*/
}
}
}
}
?><br style="clear:both">