Author Topic: Bill To and Ship To Address layout on order emails.  (Read 6067 times)

mirrorsandglass

  • Jr. Member
  • **
  • Posts: 163
  • Time Is Precious, Waste It Wisely
Bill To and Ship To Address layout on order emails.
« on: August 14, 2013, 13:40:45 pm »
I've made a template override for the components/com_virtuemart/invoice/mail_html_shopperaddresses.php and pdf invoice file components/com_virtuemart/invoice/invoice_order.php which allows for the re-arrangement of the fields sequence on the emails compared to the sequence that a shopper inputs them on the registration form or to not display certain fields.
This is similar to the old address layout options in VM1. At the moment this only works on the customer Bill To and Ship To addresses but I think it should be incorporated in the renderVendorAddress and parent functions.

I did this as I have a system that finds the customer address from the postcode so I wanted the postcode first in the registration form but obviously that looks strange when listed out in an email or invoice. So I came up with this. It may not be the most efficient way of doing it but it does work for me so I thought I'd share it.

Here's the mail_html_shopperaddresses.php code:
Code: [Select]
<?php
/**
 *
 * Layout for the order email
 * shows the chosen adresses of the shopper
 * taken from the stored order
 *
 * @package VirtueMart
 * @subpackage Order
 * @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.
 *
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
$addressBTOrder = array('email{br}''company{br}''title''first_name''last_name{br}''address_1{br}''address_2{br}''city{br}''county{br}''zip{br}''virtuemart_country_id{br}''phone_1{br}''phone_2{br}');
$addressSTOrder = array('company{br}''title''first_name''last_name{br}''address_1{br}''address_2{br}''city{br}''county{br}''zip{br}''virtuemart_country_id{br}''phone_1{br}''phone_2{br}');
?>

<table class="html-email" cellspacing="0" cellpadding="0" border="0" width="100%">
  <tr  >
<th width="50%">
<?php echo JText::_('COM_VIRTUEMART_USER_FORM_BILLTO_LBL'); ?>
</th>
<th width="50%" >
<?php echo JText::_('COM_VIRTUEMART_USER_FORM_SHIPTO_LBL'); ?>
</th>
</tr>
<tr>
<td valign="top" width="50%">
<?php
foreach ($addressBTOrder as $fieldname) {
$fieldinfo explode('{',$fieldname);
if (!empty($this->userfields['fields'][$fieldinfo[0]]['value'])) { ?>

<span class="values vm2<?php echo '-' $this->userfields['fields'][$fieldinfo[0]]['name'?>" ><?php echo $this->escape($this->userfields['fields'][$fieldinfo[0]]['value']) ?></span> <?php
if (isset($fieldinfo[1]) && $fieldinfo[1] == 'br}') { ?>

<br class="clear" /> <?php
}
}
}
?>

</td>
<td valign="top" width="50%">
<?php
foreach ($addressSTOrder as $fieldname) {
$fieldinfo explode('{',$fieldname);
if (!empty($this->shipmentfields['fields'][$fieldinfo[0]]['value'])) { ?>

<span class="values vm2<?php echo '-' $this->shipmentfields['fields'][$fieldinfo[0]]['name'?>" ><?php echo $this->escape($this->shipmentfields['fields'][$fieldinfo[0]]['value']) ?></span> <?php
if (isset($fieldinfo[1]) && $fieldinfo[1] == 'br}') { ?>

<br class="clear" /> <?php
}
}
}
?>

</td>
</tr>
</table>
The two arrays at the top:
$addressBTOrder = array('email{br}', 'company{br}', 'title', 'first_name', 'last_name{br}', 'address_1{br}', 'address_2{br}', 'city{br}', 'county{br}', 'zip{br}', 'virtuemart_country_id{br}', 'phone_1{br}', 'phone_2{br}');
$addressSTOrder = array('company{br}', 'title', 'first_name', 'last_name{br}', 'address_1{br}', 'address_2{br}', 'city{br}', 'county{br}', 'zip{br}', 'virtuemart_country_id{br}', 'phone_1{br}', 'phone_2{br}');
hold the sequence information. Hopefully it's fairly self explanatory but basically you list the order you want the fields to appear plus if you want a break at the end of it, in which case put a  {br} at the end of that field name. If you want an extra break just put a {br} on it's own in single quotes without a field_name.
invoice_order.php adds "breaks" between fields anyway as each field is displayed in a row and cell of a table but you can add extra breaks if you wish to space out the information.

Here is the invoice_order.php code:
Code: [Select]
<?php
/**
 *
 * Order detail view
 *
 * @package VirtueMart
 * @subpackage Orders
 * @author Oscar van Eijk, 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: details_order.php 5341 2012-01-31 07:43:24Z alatak $
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

$addressBTOrder = array('email''company''title''first_name''last_name''address_1''address_2''city''county''zip''virtuemart_country_id''{br}''phone_1''phone_2{br}');
$addressSTOrder = array('company''title''first_name''last_name''address_1''address_2''city''county''zip''virtuemart_country_id''{br}''phone_1''phone_2{br}');
?>

<?php if ($this->invoiceNumber) { ?>
<h1><?php echo JText::_('COM_VIRTUEMART_INVOICE').' '.$this->invoiceNumber?> </h1>
<?php ?>

<table width="100%" cellspacing="0" cellpadding="0" border="0">
<?php if ($this->invoiceNumber) { ?>
    <tr>
<td class=""><?php echo JText::_('COM_VIRTUEMART_INVOICE_DATE'?></td>
<td align="left"><?php echo vmJsApi::date($this->invoiceDate'LC4'true); ?></td>
    </tr>
    <?php ?>
    <tr>
<td ><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_PO_NUMBER'?></td>
<td align="left"><strong>
    <?php echo $this->orderDetails['details']['BT']->order_number?>
</strong>
</td>
    </tr>

    <tr>
<td class=""><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_PO_DATE'?></td>
<td align="left"><?php echo vmJsApi::date($this->orderDetails['details']['BT']->created_on'LC4'true); ?></td>
    </tr>
    <tr>
<td class=""><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_PO_STATUS'?></td>
<td align="left"><?php echo $this->orderstatuses[$this->orderDetails['details']['BT']->order_status]; ?></td>
    </tr>
  <tr>
<td class=""><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_SHIPMENT_LBL'?></td>
<td align="left"><?php
    echo 
$this->orderDetails['shipmentName'];
    ?>
</td>
    </tr>
    <tr>
<td class=""><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_PAYMENT_LBL'?></td>
<td align="left"><?php echo $this->orderDetails['paymentName']; ?>
</td>
    </tr>
<?php if ($this->orderDetails['details']['BT']->customer_note) { ?>
<tr>
    <td><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_CUSTOMER_NOTE'?></td>
    <td valign="top" align="left" width="50%"><?php echo $this->orderDetails['details']['BT']->customer_note?></td>
</tr>
<?php ?>

<tr>
<td class="orders-key"><strong><?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_TOTAL'?></strong></td>
<td class="orders-key" align="left"><strong><?php echo $this->currency->priceDisplay($this->orderDetails['details']['BT']->order_total); ?></strong></td>
</tr>

<tr>
<td colspan="2"></td>
</tr>
<tr>
<td valign="top"><strong>
<?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_BILL_TO_LBL'?></strong> <br/>
<table border="0">
<?php
foreach ($addressBTOrder as $fieldname) {
$fieldinfo explode('{',$fieldname);
if (!empty($this->userfields['fields'][$fieldinfo[0]]['value'])) {
echo '<tr><td class="key">' $this->userfields['fields'][$fieldinfo[0]]['title'] . '</td>'
'<td>' $this->escape($this->userfields['fields'][$fieldinfo[0]]['value']) . '</td></tr>';
if (isset($fieldinfo[1]) && $fieldinfo[1] == 'br}') { ?>

<br class="clear" /> <?php
}
}
}
?>

</table>
</td>
<td valign="top" ><strong>
<?php echo JText::_('COM_VIRTUEMART_ORDER_PRINT_SHIP_TO_LBL'?></strong><br/>
<table border="0">
<?php
foreach ($addressBTOrder as $fieldname) {
$fieldinfo explode('{',$fieldname);
if (!empty($this->shipmentfields['fields'][$fieldinfo[0]]['value'])) {
echo '<tr><td class="key">' $this->shipmentfields['fields'][$fieldinfo[0]]['title'] . '</td>'
'<td>' $this->escape($this->shipmentfields['fields'][$fieldinfo[0]]['value']) . '</td></tr>';
if (isset($fieldinfo[1]) && $fieldinfo[1] == 'br}') { ?>

<br class="clear" /> <?php
}
}
}
?>

</table>
</td>
    </tr>
</table>

I'm sure this could be made into a plugin by somebody with a bit more time than me. It would also be nice to have this configurable in one of the Shop->Shop-> [Tabs] or Configuration->Configuration->Templates options.

Hope this is helpful to someone.

Robert_ITMan

  • Jr. Member
  • **
  • Posts: 88
    • websites developed and managed @ ourfingertips.com
  • VirtueMart Version: 3.2.12
Re: Bill To and Ship To Address layout on order emails.
« Reply #1 on: November 07, 2013, 05:33:24 am »
Brilliant! Thanks a ton for sharing this! Your sweet code saved me hours doing this myself - I was about to add each field ... but your way is so much faster and results are exactly what I needed.

FYI - Only change I made was to add &nbsp; instead of blank space after the </span> so I have spaces now between values.
www.ourfingertips.com - websites developed and managed @ ourfingertips

Let me help you make the most of the technology at our fingertips

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2738
  • VirtueMart Version: 3.2.15
Re: Bill To and Ship To Address layout on order emails.
« Reply #2 on: November 08, 2013, 18:43:42 pm »
Nice solution to a problem that some people may come across.

 :)
regards
A

Joomla 3.8.8
php 5.6 + php 7.0

bryanearl

  • Beginner
  • *
  • Posts: 29
  • Web Design and SEO / SMO
    • Bryan Earl Web Design
Re: Bill To and Ship To Address layout on order emails.
« Reply #3 on: June 15, 2018, 01:30:33 am »
I know this is old, but it is specifically relevant to what I am doing...

I modified the above code to re-order my address displays in the newest version of VM. It works!

However, I need to add a comma after "city" in the final output for the email. If I add a comma to the array like this:

Code: [Select]
'city,'
... it doesn't work and the city doesn't display at all. I also tried the hex value for comma (%2c) but it didn't work either.

What would I add in the array after city to add a comma?

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7725
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.14
Re: Bill To and Ship To Address layout on order emails.
« Reply #4 on: June 15, 2018, 10:50:01 am »
{,} 

and then add in the loop

if (isset($fieldinfo[1]) && $fieldinfo[1] == ',}') { ?>
                  , <?php
               }

 maybe - haven't tried it - but will be something like this
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

bryanearl

  • Beginner
  • *
  • Posts: 29
  • Web Design and SEO / SMO
    • Bryan Earl Web Design
Re: Bill To and Ship To Address layout on order emails.
« Reply #5 on: June 15, 2018, 15:19:59 pm »
maybe - haven't tried it - but will be something like this

Thanks, I ended up doing it a bit differently, but I was able to get the address output how I wanted it like this:

Firstname Lastname
P.O. Box 999999
Chino Valley, Arizona 86323
928-555-1212


Here is what I did to the email file (mail_html_shopperaddresses.php) as an example:

Code: [Select]
<?php
/**
 *
 * Layout for the order email
 * shows the chosen adresses of the shopper
 * taken from the stored order
 *
 * @package VirtueMart
 * @subpackage Order
 * @author Max Milbers,   Valerie Isaksen
 *
 * @link https://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.
 *
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

$br '<br class="clear" />';
$addressBTOrder = [[
    
'key' => 'email',
    
'suffix' => $br
], [
    
'key' => 'company',
    
'suffix' => $br
], [
    
'key' => 'title',
    
'suffix' => ''
], [
    
'key' => 'first_name',
    
'suffix' => ''
], [
    
'key' => 'last_name',
    
'suffix' => $br
], [
    
'key' => 'address_1',
    
'suffix' => $br
], [
    
'key' => 'address_2',
    
'suffix' => $br
], [
    
'key' => 'city',
    
'suffix' => ','
], [
    
'key' => 'virtuemart_state_id',
    
'suffix' => ''
], [
    
'key' => 'zip',
    
'suffix' => $br
], [
    
'key' => 'virtuemart_country_id',
    
'suffix' => $br
], [
    
'key' => 'phone_1',
    
'suffix' => $br
], [
    
'key' => 'phone_2',
    
'suffix' => $br
]];

$addressSTOrder = [[
    
'key' => 'company',
    
'suffix' => $br
], [
    
'key' => 'title',
    
'suffix' => ''
], [
    
'key' => 'first_name',
    
'suffix' => ''
], [
    
'key' => 'last_name',
    
'suffix' => $br
], [
    
'key' => 'address_1',
    
'suffix' => $br
], [
    
'key' => 'address_2',
    
'suffix' => $br
], [
    
'key' => 'city',
    
'suffix' => ','
], [
    
'key' => 'virtuemart_state_id',
    
'suffix' => ''
], [
    
'key' => 'zip',
    
'suffix' => $br
], [
    
'key' => 'virtuemart_country_id',
    
'suffix' => $br
], [
    
'key' => 'phone_1',
    
'suffix' => $br
], [
    
'key' => 'phone_2',
    
'suffix' => $br
]];


?>

<table class="html-email" cellspacing="0" cellpadding="5" border="0" width="100%" style="border-collapse: collapse; font-family: Arial, Helvetica, sans-serif; font-size: 12px; margin: 0 auto;">
<tr>
<th width="50%" bgcolor="#EEEEEE" style="border: 1px solid #CCCCCC;">
    <?php echo vmText::_('COM_VIRTUEMART_USER_FORM_BILLTO_LBL'); ?>
</th>
<th width="50%" bgcolor="#EEEEEE" style="border: 1px solid #CCCCCC;">
    <?php echo vmText::_('COM_VIRTUEMART_USER_FORM_SHIPTO_LBL'); ?>
</th>
    </tr>
    <tr>
<td valign="top" width="50%" style="border: 1px solid #CCCCCC;">

<?php foreach ($addressBTOrder as $field) :
$userField $this->userfields['fields'][$field['key']];
if (!empty($userField['value'])) : ?>

<span class="values vm2-<?= $userField['name'] ?>">
  <?= $this->escape($userField['value']) ?><?= $field['suffix'] ?>
</span>
<?php endif; endforeach ?>

</td>
<td valign="top" width="50%" style="border: 1px solid #CCCCCC;">
    <?php if(!empty($this->orderDetails['details']['has_ST'])){
foreach ($addressSTOrder as $field) :
$userField $this->shipmentfields['fields'][$field['key']];
if (!empty($userField['value'])) : ?>

<span class="values vm2-<?= $userField['name'] ?>">
  <?= $this->escape($userField['value']) ?><?= $field['suffix'] ?>
</span> <?php endif; endforeach ?>
<br class="clear" /> <?php
} else {
echo "<br/>".vmText::_('COM_VM_ST_SAME_AS_BT');
}
?>

</td>
    </tr>
<tr><td valign="top" width="50%" style="padding:5px"></td><td valign="top" width="50%" style="padding:5px"></td></tr>
</table>