VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: jesperkronholm on October 09, 2012, 10:59:36 AM

Title: Product pdf does not display custom fields - Virtuemart 2
Post by: jesperkronholm on October 09, 2012, 10:59:36 AM
I'm using VirtueMart 2.0.10 with Joomla! 2.5.6 and my problem is the autogenerated pdf documents for each product don't include my custom fields. I'm no php expert but I think theese lines in file /components/com_virtuemart/views/productdetails/tmpl/default_pdf.php has something to do with it, starting at line 145:

<?php // Product custom_fields TODO relation to Childs
if (!empty($this->product->customfields)) { ?>

    <div class="product-fields">
    <?php
    $custom_title 
null ;
    foreach (
$this->product->customfields as $field){
        
?>
<div style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field_type ?>">
        <?php if ($field->custom_title != $custom_title) { ?>
            <span class="product-fields-title" ><strong><?php echo JText::_($field->custom_title); ?></strong></span>
            <?php //echo JHTML::tooltip($field->custom_tip, $field->custom_title, 'tooltip.png');
        
?>

        <span class="product-field-display"><?php echo $field->display ?></span>
        <span class="product-field-desc"><?php echo jText::_($field->custom_field_desc?></span>
        </div>
        <?php
        $custom_title 
$field->custom_title;
    } 
?>

    </div>
    <?php
// Product custom_fields END ?>


I tested adding an else statement echoing some text after the above if statement and it executetd. So apperently there are no custom fields... but there really are...

I haven't found anyone else experiencing this problem wich I think is weird, but I don't think I have screwed something up. I HAVE made a few changes in the /components/com_virtuemart/views/productdetails/tmpl/default.php file.
Title: Re: Product pdf does not display custom fields - Virtuemart 2
Post by: jesperkronholm on October 17, 2012, 14:09:33 PM
I found a solution!

I removed all the code that I entered in my question and replaced it with the following code from the file /components/com_virtuemart/views/productdetails/tmpl/default.php:

    <?php
    $custom_title 
null;
    foreach (
$this->product->customfieldsSorted['normal'] as $field) { // I set the position to normal
    
if ( $field->is_hidden )
    continue;
    if (
$field->display) {
    
?>

    <?php if ($field->custom_title != $custom_title) { ?>
    <b><?php echo JText::_($field->custom_title); ?></b><br />
   
    <?php
    
if ($field->custom_tip)
    echo 
JHTML::tooltip($field->custom_tipJText::_($field->custom_title), 'tooltip.png');
    }
    
?>

    <?php echo $field->display ?><br />
    <?php echo jText::_($field->custom_field_desc?><br />
    <?php
    $custom_title 
$field->custom_title;
    }
    }
    
?>


I'm no expert but this worked for me. The PDF now includes the custom fields.

As you see in the comment in the code I changed the position to 'normal'. The other positions seems to be 'ontop' and 'onbot'. But I won't change that setting so I leave it be.