Custom Fields Not Available in Quote Web Template


#1

Version 1.5.9

Trying to build a custom template for quotes however when I include the $custom_fields variable I get an error that it is not defined. Is this a known bug or am I doing something wrong?


#2

I seem to have this problem as well. Just migrated from 1.4 and trying to solve this. Have read the docs on migrating & changes to custom fields.

For a custom variable called “ABN” in “user”, I’ve tried:

<?php if ($custom_fields['user']['ABN']) {
  echo 'ABN: ' . ($custom_fields['user']['ABN']) . '<br><br>'; } ?>

Which throws up a PHP error: “Undefined variable: custom_fields”

I’ve also tried:

<?php if (!empty($custom_fields['user']['ABN'])): ?>
  <?php echo 'ABN: ' . ($custom_fields['user']['ABN']) . '<br><br>'; ?>
<?php endif; ?>

Which doesn’t throw an error, but doesn’t print the custom variable.

Any ideas?


#3

I cannot reproduce this problem.
Adding

<?php
echo '<pre>';
var_dump($custom_fields);
echo '</pre>';
?>

prints out

array (size=3)
  'invoice' => 
    array (size=3)
      'Sent on' => string '2018-04-26' (length=10)
      'Test Custom Field 2' => null
      'Test Single Choice' => string '' (length=0)
  'client' => 
    array (size=0)
      empty
  'user' => 
    array (size=0)
      empty

which is correct for my testing setup.

Please verify that the contents of your file application/modules/guest/controllers/View.php matches this file.


$custom_fields is not available in invoice templates and email template
#4

Thanks for the reply. That code again just prints the same error for me.

And yes, checked my live production version of View.php and the one from Git and they are identical.

Mystery! What else could be causing this?


#5

that is weird indeed. If both files are identical, the custom_fields variable should be available in the templates. Have no idea why the var could be missing.


#6

Ive got the same problem with getting custom field from user.
Same line of code works in invoice web view but not in quote.

<?php echo $custom_fields['user']['oznaka_operatera']; ?>

an error in quote web template

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: custom_fields
Filename: public/quote-web.php
Line Number: 269
Backtrace:
File: /public_html/application/views/quote_templates/public/quote-web.php
Line: 269
Function: _error_handler

File: /public_html/application/third_party/MX/Loader.php
Line: 464
Function: include

File: /public_html/application/third_party/MX/Loader.php
Line: 415
Function: _ci_load

File: /public_html/application/modules/guest/controllers/View.php
Line: 208
Function: view

File: /public_html/index.php
Line: 325
Function: require_once

IP v1.5.9

edit:
@Kovah

<?php
echo '<pre>';
var_dump($custom_fields);
echo '</pre>';
?>

returns error:

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: custom_fields
Filename: public/quote-web.php
Line Number: 297
Backtrace:
File: /public_html/application/views/quote_templates/public/quote-web.php
Line: 297
Function: _error_handler

File: /public_html/application/third_party/MX/Loader.php
Line: 464
Function: include

File: /public_html/application/third_party/MX/Loader.php
Line: 415
Function: _ci_load

File: /public_html/application/modules/guest/controllers/View.php
Line: 208
Function: view

File: /public_html/index.php
Line: 325
Function: require_once

NULL 

same code in invoice web template returns an array of custom fields.


#7

found the solution
in file application/modules/guest/controllers/View.php after line 170 add

$this->load->model('custom_fields/mdl_custom_fields');

after

if ($this->session->userdata('user_type') <> 1 and $quote->quote_status_id == 2) {
            $this->mdl_quotes->mark_viewed($quote->quote_id);
        }

add

// Get all custom fields
        $custom_fields = array(
            'quote' => $this->mdl_custom_fields->get_values_for_fields('mdl_invoice_custom', $quote->quote_id),
            'client' => $this->mdl_custom_fields->get_values_for_fields('mdl_client_custom', $quote->client_id),
            'user' => $this->mdl_custom_fields->get_values_for_fields('mdl_user_custom', $quote->user_id),
        );

and add

    'custom_fields' => $custom_fields,

to array

$data = array(
    'quote' => $quote,
    'items' => $this->mdl_quote_items->where('quote_id', $quote->quote_id)->get()->result(),
    'quote_tax_rates' => $this->mdl_quote_tax_rates->where('quote_id', $quote->quote_id)->get()->result(),
    'quote_url_key' => $quote_url_key,
    'flash_message' => $this->session->flashdata('flash_message'),
    'is_expired' => $is_expired,
    'attachments' => $attachments,
);

this is my working version of View.php -> https://pastebin.com/LbKbxvzG

Cheers,
G.


#8

Thanks @gregorb for solving this issue. The next steps should be:

  • to open a ticket at the development portal and
  • to submit a pull-request on GitHub with your fixes so that they can be incorporated into the next release.

If you don’t want/plan to do it for whatever reason, let us know and I will do it on behalf of you and will keep your name as contributor.

BTW, you should mark your last post as accepted answer.


#9

Ticket at the development portal:

  • IP-741 - Custom Fields Not Available in Quote Web Template

and pull request in GitHub: