Hello,
I am using version 3.6.2 10159 and just noticed some errors in the default.php of the productdetails and hope that some nice and friendly coder here can help me to get rid of them.
The notice or error:
QuoteCategories:
Notice: Undefined variable: field in /home/public_html/templates/mytemplate/html/com_virtuemart/productdetails/default.php on line 216
Line 216 shows this:
$skip[]=$field->customfield_value;
The whole PHP section is this:
<?php
$i=0;
$tt=0;
foreach ($this->product->categoryItem as $category){
if ($category['published']==0)continue;
$caturl = JRoute::_ ( 'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category['virtuemart_category_id'] );
$catname=$category['category_name'];
$categoriescombineds[]= array($caturl,$catname,$category['virtuemart_category_id']);
$tt++;
$skip[]=$field->customfield_value;
}
foreach ($categoriescombineds as $y => $categoriescombined){
if (!empty($skip)){ if (in_array($categoriescombined[2],$skip, TRUE)){
continue;
} }
$html.=' <a href="'.$categoriescombined[0].'"title="'.$categoriescombined[1].'" > '.$categoriescombined[1].'</a>';
if($y != (count($categoriescombineds)-1)) $html.= ',';
$i++;
if ($i==5 && $tt>5);
}
echo $html;
?>
Thank you very much for your help.
Joomla! 3.9.12
VirtueMart 3.6.2 10159
Is this custom code ?
Take away the line, the code you showed makes no sense.
Jörgen @ Kreativ Fotografi
yes -- its in your over ride .. whats it supposed to do? skip unpublished cats? produce a list of cats for the product?
surely the core does this already?
as the notice says .. $field is undefined .. define it
is it a new object?
try $field = new stdClass();
Quote from: Jörgen on October 01, 2019, 07:10:04 AM
Is this custom code ?
I would say yes. I bought a theme a little bit over one year ago.
Quote from: GJC Web Design on October 01, 2019, 11:08:59 AM
produce a list of cats for the product
Correct. The categories are showing, but so that this notice. It was not there before the latest update, so I think something changed with the update.
Have You updated PHP recently ? Have You tried version 7.1 ?
Jörgen
Quote from: Jörgen on October 01, 2019, 14:36:39 PM
Have You updated PHP recently ? Have You tried version 7.1 ?
Jörgen
Yes. Updated to 7.2x because Joomla told me to do. :-\
Does it work with PHP 7.1 ? The error seems to be in the override.
Jörgen
No, still the same error with PHP version 7.1.30.
When I remove the line
$skip[]=$field->customfield_value;
I get this note or error:
QuoteNotice: Undefined variable: html in /home/public_html/templates/mytemplate/html/com_virtuemart/productdetails/default.php on line 223
223 is either this one:
$html.=' <a href="'.$categoriescombined[0].'"title="'.$categoriescombined[1].'" > '.$categoriescombined[1].'</a>';
or this one:
if($y != (count($categoriescombineds)-1)) $html.= ',';
The whole block:
<span class="posted_in">
<?php echo vmText::_( 'COM_VIRTUEMART_CATEGORIES' ).': '; ?>
<?php
$i=0;
$tt=0;
foreach ($this->product->categoryItem as $category){
if ($category['published']==0)continue;
$caturl = JRoute::_ ( 'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category['virtuemart_category_id'] );
$catname=$category['category_name'];
$categoriescombineds[]= array($caturl,$catname,$category['virtuemart_category_id']);
$tt++;
//$skip[]=$field->customfield_value;
}
foreach ($categoriescombineds as $y => $categoriescombined){
if (!empty($skip)){ if (in_array($categoriescombined[2],$skip, TRUE)){
continue;
} }
$html.=' <a href="'.$categoriescombined[0].'"title="'.$categoriescombined[1].'" > '.$categoriescombined[1].'</a>';
if($y != (count($categoriescombineds)-1)) $html.= ',';
$i++;
if ($i==5 && $tt>5);
}
echo $html;
?>
</span>
You are missing something in Your override. I would guess some file that should be included in the template override. Use default template and see if it goes away.
Jörgen @ Kreativ Fotografi
Can I hire you to fix this? :)
You probably just need to add
$html = '';
somewhere higher up. The code snippet is too small to tell where.
Regards
Stefan
Here is the complete code. Wanted to avoid a blown up post.
<?php
/**
*
* Show the product details page
*
* @package VirtueMart
* @subpackage
* @author Max Milbers, Eugen Stranz, Max Galt
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2014 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.php 9292 2016-09-19 08:07:15Z Milbo $
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
/* Let's see if we found the product */
if (empty($this->product)) {
echo vmText::_('COM_VIRTUEMART_PRODUCT_NOT_FOUND');
echo '<br /><br /> ' . $this->continue_link_html;
return;
}
echo shopFunctionsF::renderVmSubLayout('askrecomjs',array('product'=>$this->product));
if(vRequest::getInt('print',false)){ ?>
<body onload="javascript:print();">
<?php } ?>
<div class="product product-container productdetails-view productdetails single-product-entry" >
<div class="row">
<div class="col-xs-12 col-md-5">
<?php echo $this->loadTemplate('images'); ?>
</div>
<div class="col-xs-12 col-md-7">
<div class="single-product-title">
<?php // Product Title ?>
<h1 itemprop="name" class="product_title entry-title"><?php echo $this->product->product_name ?></h1>
<?php // Product Title END ?>
<?php // afterDisplayTitle Event
echo $this->product->event->afterDisplayTitle ?>
<?php
// Product Navigation
if (VmConfig::get('product_navigation', 1)) {
$product_model = VmModel::getModel('product');
?>
<div class="product-next-previous">
<?php
if (!empty($this->product->neighbours ['previous'][0])) {
$prev_link = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->neighbours ['previous'][0] ['virtuemart_product_id'] . '&virtuemart_category_id=' . $this->product->virtuemart_category_id, FALSE);
$neighbours_id_prev = $this->product->neighbours ['previous'][0] ['virtuemart_product_id'];
$neighbours_id_p = array();
$neighbours_id_p[] = $neighbours_id_prev;
$prods_neighbours_p = $product_model->getProducts($neighbours_id_p);
$product_model->addImages($prods_neighbours_p);
?>
<div class="product-prev">
<a href="<?php echo $prev_link; ?>">
<span class="product-navbar"><i class="fa fa-chevron-left"></i></span>
</a>
<div class="product-prev-popup">
<div class="product-thumb">
<?php
foreach($prods_neighbours_p as $product) {
echo $product->images[0]->displayMediaThumb("",true,"rel=''",true,$product->images[0]->file_description);
}
?>
</div>
<div class="product-title-price">
<span class="ptitle"><?php echo $this->product->neighbours ['previous'][0] ['product_name']; ?></span>
</div>
</div>
</div>
<?php
}
if (!empty($this->product->neighbours ['next'][0])) {
$next_link = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->neighbours ['next'][0] ['virtuemart_product_id'] . '&virtuemart_category_id=' . $this->product->virtuemart_category_id, FALSE);
$neighbours_id_next = $this->product->neighbours ['next'][0] ['virtuemart_product_id'];
$neighbours_id_n = array();
$neighbours_id_n[] = $neighbours_id_next;
$prods_neighbours_n = $product_model->getProducts($neighbours_id_n);
$product_model->addImages($prods_neighbours_n);
?>
<div class="product-next">
<a href="<?php echo $next_link; ?>">
<span class="product-navbar"><i class="fa fa-chevron-right"></i></span>
</a>
<div class="product-next-popup">
<div class="product-thumb">
<?php
foreach($prods_neighbours_n as $product) {
echo $product->images[0]->displayMediaThumb("",true,"rel=''",true,$product->images[0]->file_description);
}
?>
</div>
<div class="product-title-price">
<span class="ptitle"><?php echo $this->product->neighbours ['next'][0] ['product_name']; ?></span>
</div>
</div>
</div>
<?php
}
?>
</div>
<?php } // Product Navigation END
?>
</div>
<div class="vm-product-details-container">
<div class="spacer-buy-area">
<?php
// TODO in Multi-Vendor not needed at the moment and just would lead to confusion
/* $link = JRoute::_('index2.php?option=com_virtuemart&view=virtuemart&task=vendorinfo&virtuemart_vendor_id='.$this->product->virtuemart_vendor_id);
$text = vmText::_('COM_VIRTUEMART_VENDOR_FORM_INFO_LBL');
echo '<span class="bold">'. vmText::_('COM_VIRTUEMART_PRODUCT_DETAILS_VENDOR_LBL'). '</span>'; ?><a class="modal" href="<?php echo $link ?>"><?php echo $text ?></a><br />
*/
?>
<?php
echo shopFunctionsF::renderVmSubLayout('rating', array('showRating' => $this->showRating, 'product' => $this->product));
foreach ($this->productDisplayTypes as $type=>$productDisplayType) {
foreach ($productDisplayType as $productDisplay) {
foreach ($productDisplay as $virtuemart_method_id =>$productDisplayHtml) {
?>
<div class="<?php echo substr($type, 0, -1) ?> <?php echo substr($type, 0, -1).'-'.$virtuemart_method_id ?>">
<?php
echo $productDisplayHtml;
?>
</div>
<?php
}
}
}
//In case you are not happy using everywhere the same price display fromat, just create your own layout
//in override /html/fields and use as first parameter the name of your file
echo shopFunctionsF::renderVmSubLayout('prices',array('product'=>$this->product,'currency'=>$this->currency));
if ($this->product->product_in_stock >=1) {
echo '<span class="availability instock"><i class="fa fa-check-square" aria-hidden="true"></i>&#32;'.JText::_('DR_IN_STOCK_NEW').'</span>';
}else {
echo '<span class="availability outstock"><i class="fa fa-check-square" aria-hidden="true"></i>&#32;'.JText::_('DR_OUT_STOCK_NEW').'</span>';
}
?>
<div class="clear"></div>
<?php
// Product Short Description
if (!empty($this->product->product_s_desc)) {
?>
<div class="product-short-description" itemprop="description">
<?php echo nl2br($this->product->product_s_desc); ?>
</div>
<?php
} // Product Short Description END
echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$this->product));
echo shopFunctionsF::renderVmSubLayout('stockhandle',array('product'=>$this->product));
// Ask a question about this product
if (VmConfig::get('ask_question', 0) == 1) {
$askquestion_url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&task=askquestion&virtuemart_product_id=' . $this->product->virtuemart_product_id . '&virtuemart_category_id=' . $this->product->virtuemart_category_id . '&tmpl=component', FALSE);
?>
<div class="ask-a-question">
<a class="ask-a-question" href="<?php echo $askquestion_url ?>" rel="nofollow" ><?php echo vmText::_('COM_VIRTUEMART_PRODUCT_ENQUIRY_LBL') ?></a>
</div>
<?php
}
?>
</div>
</div>
<?php
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'ontop'));
?>
<div class="product_meta">
<?php
// Manufacturer of the Product
if (VmConfig::get('show_manufacturers', 1) && !empty($this->product->virtuemart_manufacturer_id)) {
echo $this->loadTemplate('manufacturer');
}
?>
<span class="posted_in">
<?php echo vmText::_( 'COM_VIRTUEMART_CATEGORIES' ).': '; ?>
<?php
$i=0;
$tt=0;
foreach ($this->product->categoryItem as $category){
if ($category['published']==0)continue;
$caturl = JRoute::_ ( 'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category['virtuemart_category_id'] );
$catname=$category['category_name'];
$categoriescombineds[]= array($caturl,$catname,$category['virtuemart_category_id']);
$tt++;
$skip[]=$field->customfield_value;
}
foreach ($categoriescombineds as $y => $categoriescombined){
if (!empty($skip)){ if (in_array($categoriescombined[2],$skip, TRUE)){
continue;
} }
$html.=' <a href="'.$categoriescombined[0].'"title="'.$categoriescombined[1].'" > '.$categoriescombined[1].'</a>';
if($y != (count($categoriescombineds)-1)) $html.= ',';
$i++;
if ($i==5 && $tt>5);
}
echo $html;
?>
</span>
</div>
<?php
// PDF - Print - Email Icon
if (VmConfig::get('show_emailfriend') || VmConfig::get('show_printicon') || VmConfig::get('pdf_icon')) {
?>
<div class="icons">
<?php
$link = 'index.php?tmpl=component&option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->virtuemart_product_id;
echo $this->linkIcon($link . '&format=pdf', 'COM_VIRTUEMART_PDF', 'pdf_button', 'pdf_icon', false);
//echo $this->linkIcon($link . '&print=1', 'COM_VIRTUEMART_PRINT', 'printButton', 'show_printicon');
echo $this->linkIcon($link . '&print=1', 'COM_VIRTUEMART_PRINT', 'printButton', 'show_printicon',false,true,false,'class="printModal"');
$MailLink = 'index.php?option=com_virtuemart&view=productdetails&task=recommend&virtuemart_product_id=' . $this->product->virtuemart_product_id . '&virtuemart_category_id=' . $this->product->virtuemart_category_id . '&tmpl=component';
echo $this->linkIcon($MailLink, 'COM_VIRTUEMART_EMAIL', 'emailButton', 'show_emailfriend', false,true,false,'class="recommened-to-friend"');
?>
<div class="clear"></div>
</div>
<?php } // PDF - Print - Email Icon END
?>
<div class="social-share-button">
<div class="normal-social">
<a href="#" data-type="twitter" data-url="<?php echo $this->product->link; ?>" data-description="<?php echo nl2br($this->product->product_s_desc); ?>" class="prettySocial fa fa-twitter"></a>
<a href="#" data-type="facebook" data-url="<?php echo $this->product->link; ?>" data-title="<?php echo $this->product->product_name ?>" data-description="<?php echo nl2br($this->product->product_s_desc); ?>" class="prettySocial fa fa-facebook"></a>
<a href="#" data-type="googleplus" data-url="<?php echo $this->product->link; ?>" data-description="<?php echo nl2br($this->product->product_s_desc); ?>" class="prettySocial fa fa-google-plus"></a>
<a href="#" data-type="pinterest" data-url="<?php echo $this->product->link; ?>" data-description="<?php echo nl2br($this->product->product_s_desc); ?>" class="prettySocial fa fa-pinterest"></a>
<a href="#" data-type="linkedin" data-url="<?php echo $this->product->link; ?>" data-title="<?php echo $this->product->product_name ?>" data-description="<?php echo nl2br($this->product->product_s_desc); ?>" class="prettySocial fa fa-linkedin"></a>
</div>
</div>
</div>
</div>
<div role="tabpanel" class="czd-commerce-tabs czd-tabs-wrapper">
<!-- Nav tabs -->
<ul class="tabs czd-tabs nav nav-tabs" role="tablist" id="dscr_tab">
<li role="presentation" class="description_tab active"><a href="#tab-description" aria-controls="prod_dscr" role="tab" data-toggle="tab" aria-expanded="true"><?php echo vmText::_( 'COM_VIRTUEMART_PRODUCT_DESC_TITLE' ); ?></a></li>
<li role="presentation" class="reviews_tab"><a href="#tab-reviews" aria-controls="prod_reviews" role="tab" data-toggle="tab" aria-expanded="false"><?php echo vmText::_( 'COM_VIRTUEMART_REVIEWS' ); ?></a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade active in" id="tab-description">
<?php echo $this->product->product_desc; ?>
</div>
<div role="tabpanel" class="tab-pane fade" id="tab-reviews">
<?php echo $this->loadTemplate('reviews');?>
</div>
</div>
</div>
<?php // Back To Category Button
if ($this->product->virtuemart_category_id) {
$catURL = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$this->product->virtuemart_category_id, FALSE);
$categoryName = vmText::_($this->product->category_name) ;
} else {
$catURL = JRoute::_('index.php?option=com_virtuemart');
$categoryName = vmText::_('COM_VIRTUEMART_SHOP_HOME') ;
}
?>
<?php
// Product Edit Link
echo $this->edit_link;
// Product Edit Link END
?>
<?php
// event onContentBeforeDisplay
echo $this->product->event->beforeDisplayContent; ?>
<?php
//echo ($this->product->product_in_stock - $this->product->product_ordered);
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'normal'));
// Product Packaging
$product_packaging = '';
if ($this->product->product_box) {
?>
<div class="product-box">
<?php
echo vmText::_('COM_VIRTUEMART_PRODUCT_UNITS_IN_BOX') .$this->product->product_box;
?>
</div>
<?php } // Product Packaging END ?>
<?php
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'onbot'));
echo shopFunctionsF::renderVmSubLayout('customfields_related',array('product'=>$this->product,'position'=>'related_products','class'=> 'product-related-products','customTitle' => true ));
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'related_categories','class'=> 'product-related-categories'));
?>
<?php // onContentAfterDisplay event
echo $this->product->event->afterDisplayContent;
// Show child categories
if (VmConfig::get('showCategory', 1)) {
// echo $this->loadTemplate('showcategory');
}
$j = 'jQuery(document).ready(function($) {
$("form.js-recalculate").each(function(){
if ($(this).find(".product-fields").length && !$(this).find(".no-vm-bind").length) {
var id= $(this).find(\'input[name="virtuemart_product_id[]"]\').val();
Virtuemart.setproducttype($(this),id);
}
});
});';
//vmJsApi::addJScript('recalcReady',$j);
if(VmConfig::get ('jdynupdate', TRUE)){
/** GALT
* Notice for Template Developers!
* Templates must set a Virtuemart.container variable as it takes part in
* dynamic content update.
* This variable points to a topmost element that holds other content.
*/
$j = "Virtuemart.container = jQuery('.productdetails-view');
Virtuemart.containerSelector = '.productdetails-view';
//Virtuemart.recalculate = true; //Activate this line to recalculate your product after ajax
";
vmJsApi::addJScript('ajaxContent',$j);
$j = "jQuery(document).ready(function($) {
Virtuemart.stopVmLoading();
var msg = '';
$('a[data-dynamic-update=\"1\"]').off('click', Virtuemart.startVmLoading).on('click', {msg:msg}, Virtuemart.startVmLoading);
$('[data-dynamic-update=\"1\"]').off('change', Virtuemart.startVmLoading).on('change', {msg:msg}, Virtuemart.startVmLoading);
});";
vmJsApi::addJScript('vmPreloader',$j);
}
echo vmJsApi::writeJS();
if ($this->product->prices['salesPrice'] > 0) {
echo shopFunctionsF::renderVmSubLayout('snippets',array('product'=>$this->product, 'currency'=>$this->currency, 'showRating'=>$this->showRating));
}
?>
<div class="back-to-category">
<a href="<?php echo $catURL ?>" class="product-details" title="<?php echo $categoryName ?>"><?php echo vmText::sprintf('COM_VIRTUEMART_CATEGORY_BACK_TO',$categoryName) ?></a>
</div>
</div>
Looks like it was enough. Try to replace your code with this:
$i=0;
$tt=0;
$html = '';
$skip = array();
foreach ($this->product->categoryItem as $category){
if ($category['published']==0)continue;
$caturl = JRoute::_ ( 'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $category['virtuemart_category_id'] );
$catname=$category['category_name'];
$categoriescombineds[]= array($caturl,$catname,$category['virtuemart_category_id']);
$tt++;
if (!empty($field->customfield_value)) {
$skip[]=$field->customfield_value;
}
}
Good lord, yes, it is gone.
Thanks you so much.
Seems I found a very good programmer to hire for future problems.