Author Topic: Shipping address formating  (Read 4771 times)

rogy

  • Jr. Member
  • **
  • Posts: 61
Shipping address formating
« on: November 10, 2015, 15:37:10 pm »
How can i formating the shipping address on a line like:

First name last name
Zip City

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3733
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Shipping address formating
« Reply #1 on: November 11, 2015, 07:57:02 am »
Hello Yes

This is of course possible. You have to edit the template for the view. here is what I have done. I assume You are talking about the invoice view right?

You have to replace the address section in the
templates/yourtemplate/html/com_virtuemart/invoice/invoice_order.php

if You don´t have any override, copy the file from Components/com_virtuemart/views/invoice/tmpl/invoice_order.php

att approx line 90 replace
Code: [Select]
    <tr>
<td valign="top"><strong>
    <?php echo vmText::_('COM_VIRTUEMART_ORDER_PRINT_BILL_TO_LBL'?></strong> <br/>
    <table border="0"><?php
    foreach (
$this->userfields['fields'] as $field) {
if (!empty($field['value'])) {
    echo '<tr><td class="key">' $field['title'] . '</td>'
    . '<td>' $field['value'] . '</td></tr>';
}
    }
    ?>
</table>
</td>
<td valign="top" ><strong>
    <?php echo vmText::_('COM_VIRTUEMART_ORDER_PRINT_SHIP_TO_LBL'?></strong><br/>
    <table border="0"><?php
    foreach (
$this->shipmentfields['fields'] as $field) {
if (!empty($field['value'])) {
    echo '<tr><td class="key">' $field['title'] . '</td>'
    . '<td>' $field['value'] . '</td></tr>';
}
    }
    ?>
</table>
</td>
    </tr>

With something like this:

Code: [Select]
<!-- Bill to address -->
    <tr>
<td valign="top">

<strong><?php echo vmText::_('COM_VIRTUEMART_ORDER_PRINT_CUST_INFO_LBL'?></strong><br/>
<strong><?php echo vmText::_('COM_VIRTUEMART_ORDER_PRINT_BILL_TO_LBL'?></strong>
<table border="0"><?php
    foreach (
$this->userfields['fields'] as $field) {
if (!empty($field['value'])) {
echo '<tr><td>';
switch ($field['name']) {
case 'zip':
   case 'address_type_name':
   break;

case 'first_name':
if (empty($this->userfields['fields']['last_name']['value']))
echo $field['value'];
break;

   case'last_name'
   echo $this->userfields['fields']['first_name']['value'] . ' ' $field['value'];
   break;
  
   case 'city':
   echo $this->userfields['fields']['zip']['value'] . ' ' $field['value'];
   break;

case 'phone_1':
echo '<br/>';
default:
    echo $field['value'];
    break;
// switch ()  
// if ()
echo '</td></tr>';     
// foreach
echo '<tr><td><br/></td></tr>';
    ?>
</table>
<!-- Ship to address -->
</td>
<td valign="top" ><strong><br/>
    <?php echo vmText::_('COM_VIRTUEMART_ORDER_PRINT_SHIP_TO_LBL'?></strong>
    <table border="0"><?php
echo '<tr><td><br/></td></tr>';
    foreach ($this->shipmentfields['fields'] as $field) {
if (!empty($field['value'])) {
echo '<tr><td><strong>';
switch ($field['name']) {
   case 'zip':
   case 'address_type_name':
   break;

case 'first_name':
if (empty($this->shipmentfields['fields']['last_name']['value']))
echo $field['value'];
break;

   case 'last_name'
   echo $this->shipmentfields['fields']['first_name']['value'] . ' ' $field['value'];
   break;
  
   case 'city':
   echo $this->shipmentfields['fields']['zip']['value'] . ' ' $field['value'];
   break;

case 'phone_1':
echo '<br/>';
default:
    echo $field['value'];
    break;
// switch ()  
// if ()
echo '<strong></td></tr>';  
// foreach
echo '<tr><td><br/></td></tr>';
    ?>
</table>
</td>
    </tr>

I made some checks if the name fields were left empty and have formatted the output the way I want it. Feel free to suggest any enhancements.

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

rogy

  • Jr. Member
  • **
  • Posts: 61
Re: Shipping address formating
« Reply #2 on: November 11, 2015, 08:32:32 am »
Thank's for your answer.
I put the code in my overright:
templates/yourtemplate/html/com_virtuemart/invoice/invoice_order.php

But i have tested, nothing happend.

Is this the right php file?

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3733
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Shipping address formating
« Reply #3 on: November 11, 2015, 09:10:11 am »
Hello Rogy

I was a bit to quick. The changes I suggested is for the Invoice. Have You checked if You can see any Changes in the layout for the emailed invoices ?

The cart layout does not seem to have this issue in my override. I use version 3.0.9.4. What version of VM Do You use?

templates/yourtemplate/html/com_virtuemart/cart/default_address.php

This is the 3.0.9.4 file:
Code: [Select]
<?php
/**
*
* Layout for the shopping cart and the mail
* shows the chosen adresses of the shopper
* taken from the cart in the session
*
* @package VirtueMart
* @subpackage Cart
* @author Max Milbers
*
* @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.
*
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
?>

<div class="billto-shipto">
<div class="width50 floatleft">

<span><span class="vmicon vm2-billto-icon"></span>
<?php echo vmText::('COM_VIRTUEMART_USER_FORM_BILLTO_LBL'); ?></span>
<?php // Output Bill To Address ?>
<div class="output-billto">
<?php
$cartfieldNames = array();
foreach( $this->userFieldsCart['fields'] as $fields){
$cartfieldNames[] = $fields['name'];
}

foreach ($this->cart->BTaddress['fields'] as $item) {
if(in_array($item['name'],$cartfieldNames)) continue;
if (!empty($item['value'])) {
if ($item['name'] === 'agreed') {
$item['value'] = ($item['value'] === 0) ? vmText::('COM_VIRTUEMART_USER_FORM_BILLTO_TOS_NO') : vmText::('COM_VIRTUEMART_USER_FORM_BILLTO_TOS_YES');
}
?>
<!-- span class="titles"><?php echo $item['title'?></span -->
<span class="values vm2<?php echo '-' $item['name'?>"><?php echo $item['value'?></span>
<?php if ($item['name'] != 'title' and $item['name'] != 'first_name' and $item['name'] != 'middle_name' and $item['name'] != 'zip') { ?>
<br class="clear"/>
<?php
}
}
?>

<div class="clear"></div>
</div>

<?php
if($this->pointAddress){
$this->pointAddress 'required invalid';
}

?>

<a class="details <?php echo $this->pointAddress ?>" href="<?php echo JRoute::('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT'$this->useXHTML$this->useSSL?>" rel="nofollow">
<?php echo vmText::('COM_VIRTUEMART_USER_FORM_EDIT_BILLTO_LBL'); ?>
</a>

<input type="hidden" name="billto" value="<?php echo $this->cart->lists['billTo']; ?>"/>
</div>

<div class="width50 floatleft">

<span><span class="vmicon vm2-shipto-icon"></span>
<?php echo vmText::('COM_VIRTUEMART_USER_FORM_SHIPTO_LBL'); ?></span>
<?php // Output Bill To Address ?>
<div class="output-shipto">
<?php
if (!class_exists ('VmHtml')) {
require(VMPATH_ADMIN DS 'helpers' DS 'html.php');
}
if($this->cart->user->virtuemart_user_id==0){

echo vmText::('COM_VIRTUEMART_USER_FORM_ST_SAME_AS_BT');
echo VmHtml::checkbox ('STsameAsBT'$this->cart->STsameAsBT,1,0,'id="STsameAsBTjs"') . '<br />';
} else if(!empty($this->cart->lists['shipTo'])){
echo $this->cart->lists['shipTo'];
}

if(empty($this->cart->STsameAsBT) and !empty($this->cart->ST) and !empty($this->cart->STaddress['fields'])){ ?>

<div id="output-shipto-display">
<?php
foreach ($this->cart->STaddress['fields'] as $item) {
if (!empty($item['value'])) {
?>

<!-- <span class="titles"><?php echo $item['title'?></span> -->
<?php
if ($item['name'] == 'first_name' || $item['name'] == 'middle_name' || $item['name'] == 'zip') {
?>

<span class="values<?php echo '-' $item['name'?>"><?php echo $item['value'?></span>
<?php } else { ?>
<span class="values"><?php echo $item['value'?></span>
<br class="clear"/>
<?php
}
}
}
?>

</div>
<?php
}
?>

<div class="clear"></div>
</div>
<?php if (!isset($this->cart->lists['current_id'])) {
$this->cart->lists['current_id'] = 0;

?>

<a class="details" href="<?php echo JRoute::('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=ST&virtuemart_user_id[]=' $this->cart->lists['current_id'], $this->useXHTML$this->useSSL?>" rel="nofollow">
<?php echo vmText::('COM_VIRTUEMART_USER_FORM_ADD_SHIPTO_LBL'); ?>
</a>

</div>

<div class="clear"></div>
</div>

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

rogy

  • Jr. Member
  • **
  • Posts: 61
Re: Shipping address formating
« Reply #4 on: November 11, 2015, 10:31:43 am »
Hi Jörgen

The Email looks ok. But not the shiping address in the cart.
My Php Knowhow is not very good ;-(

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3733
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Shipping address formating
« Reply #5 on: November 11, 2015, 10:42:33 am »
Hello Rogy

What VM version are You using ?

You should have an address template very near the last code I showed You.
Does the cart default_address view look like this file ?

If it does then You have a CSS error somewhere and You should be able to find it with FireBug.

Jörgen @ Kreativ Fotografi

Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

rogy

  • Jr. Member
  • **
  • Posts: 61
Re: Shipping address formating
« Reply #6 on: November 11, 2015, 10:54:21 am »
Yes it is the same.
I use 3.0.11
In firebug the fields are all withe the class values <span class="values">Musterstrasse 12</span>
No way with css :(

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3733
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Shipping address formating
« Reply #7 on: November 11, 2015, 11:26:33 am »
Hello

Are You using some kind of custom template ? That should explain it.

Here is my output for the billto address:
Code: [Select]
<div class="output-billto">
<!-- span class="titles">E-post</span -->
<span class="values vm2-email">testkund@kreativfotografi.se</span>
<br class="clear">
<!-- span class="titles">Adress alias</span -->
<span class="values vm2-address_type_name">-default-</span>
<br class="clear">
<!-- span class="titles">Förnamn</span -->
<span class="values vm2-first_name">testkund</span>
<!-- span class="titles">Efternamn</span -->
<span class="values vm2-last_name">Hübner</span>
<br class="clear">
<!-- span class="titles">Gatuadress</span -->
<span class="values vm2-address_1">Aklejavägen 8</span>
<br class="clear">
<!-- span class="titles">Postnummer / ZIP</span -->
<span class="values vm2-zip">19468</span>
<!-- span class="titles">Stad</span -->
<span class="values vm2-city">UPPLANDS VÄSBY</span>
<br class="clear">
<!-- span class="titles">Land</span -->
<span class="values vm2-virtuemart_country_id">Sweden</span>
<br class="clear">
<!-- span class="titles">Telefon</span -->
<span class="values vm2-phone_1">08-59088528</span>
<br class="clear">
<div class="clear"></div>
</div>

If Your output looks the same and You still have breaks in the wrong Place, You may have a CSS issue.

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

rogy

  • Jr. Member
  • **
  • Posts: 61
Re: Shipping address formating
« Reply #8 on: November 11, 2015, 11:42:45 am »
Hi, sorry for this misunderstanding. The Bill address is ok.
But the Shipping Address:


Code: [Select]
<div class="output-shipto">
<div class="controls">
<div id="output-shipto-display">
<span class="values">Shipping Address</span>
<br class="clear">
<span class="values">Company</span>
<br class="clear">
<span class="values">Hans</span>
<br class="clear">
<span class="values">Muster</span>
<br class="clear">
<span class="values">Musterstrasse 12</span>
<br class="clear">
<span class="values">8005</span>
<br class="clear">
<span class="values">Zürich</span>
<br class="clear">
<span class="values">Switzerland</span>
<br class="clear">
</div>

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3733
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Shipping address formating
« Reply #9 on: November 11, 2015, 11:53:18 am »
Hello Rogy

It was my fault. Now I see what You mean. I will make some corrections tonight and publish a solution for this. I also want to have this corrected :)

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3733
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Shipping address formating
« Reply #10 on: November 11, 2015, 22:55:20 pm »
Hello Rogy

I made some changes in the file
templates/yourtemplate/html/com_virtuemart/cart/default_address.php

Find this on approx line 93:
Code: [Select]
<?php
if ($item['name'] == 'first_name' || $item['name'] == 'middle_name' || $item['name'] == 'zip') {
?>

<span class="values<?php echo '-' $item['name'?>"><?php echo $item['value'?></span>
<?php } else { ?>
<span class="values"><?php echo $item['value'?></span>
<br class="clear"/>
and replace with:
Code: [Select]
<span class="values vm2<?php echo '-' $item['name'?>"><?php echo $item['value'?></span>
<?php if ($item['name'] != 'title' and $item['name'] != 'shipto_first_name' and $item['name'] != 'shipto_middle_name' and $item['name'] != 'shipto_zip') { ?>
<br class="clear"/>

Then it should work :)

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

rogy

  • Jr. Member
  • **
  • Posts: 61
Re: Shipping address formating
« Reply #11 on: November 12, 2015, 08:30:36 am »
Hi Jörgen

Thank's a lot.
That was i'm looking for :D

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3733
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Shipping address formating
« Reply #12 on: November 12, 2015, 10:45:08 am »
Hello Rogy

This is a bonus for me. I very rarely choose a special shipping address and because of that I haven´t spotted the problem with the layout. But now I have fixed this in my website too :)

have a nice day

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.