VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: man.of.earth on October 16, 2019, 16:08:19 PM

Title: Modification in the email template to show „Same as billing” same address
Post by: man.of.earth on October 16, 2019, 16:08:19 PM
Hello,

I want that, in case the shipping address is the same as billing address, to display this on the shipping user data as ,,Same as billing", instead of duplicating the data from the billing column (in the emails sent to customers/vendor, that is).
The lines that show the shipping address are in the mail_html_shopperaddresses.php file (lines 52 to 67):
<td valign="top" width="50%" style="border: 1px solid #CCCCCC;">
    <?php
    
foreach ($this->shipmentfields['fields'] as $field) {

if (!empty($field['value'])) {
    ?>
<!-- span class="titles"><?php echo $field['title'?></span -->
    <span class="values vm2<?php echo '-' $field['name'?>" ><?php echo $field['value'?></span>
    <?php if ($field['name'] != 'title' and $field['name'] != 'first_name' and $field['name'] != 'middle_name' and $field['name'] != 'zip') { ?>
<br class="clear" />
<?php
    }
}
    }

?>

</td>



I added the condition
if(!empty($this->orderdetails['details']['has_ST'])){
before this cycle, but, in the emails only, I still get ,,Same as billing", even if the shipping address if different from billing address:
<td valign="top" width="50%" style="border: 1px solid #CCCCCC;">
if(!empty($this->orderdetails['details']['has_ST'])){?><br/><?
foreach ($this->shipmentfields['fields'] as $field){
if (!empty($field['value'])){?><!--span class="titles"?><?#echo $field['title']?></span-->
<span class="values vm2<?echo '-' . $field['name']?>"><?echo $field['value']?></span><?
if ($field['name'] != 'title' and $field['name'] != 'first_name' and $field['name'] != 'middle_name' and $field['name'] != 'zip'){
?><br class="clear"/><?
}
}
}
}
else{
echo vmText::_('COM_VM_ST_SAME_AS_BT');
}?>
</td>


Does any of you know why or what I could try?
Thank you.

(VM 3.6.2 10159 on Joomla! 3.9.12 and PHP 7.2.9)
Title: Re: Modification in the email template to show „Same as billing” same address
Post by: AH on October 16, 2019, 17:14:05 PM
That is part of the core system

Provided in the invoice\tmpl\invoice.order.php

If you have an override you can look at how this file does it

it determines if there is a stored ST address using     -  if(!empty($this->orderDetails['details']['has_ST']


<td valign="top" ><strong>
    <?php echo vmText::_('COM_VIRTUEMART_ORDER_PRINT_SHIP_TO_LBL'?></strong><br/>
<?php if(!empty($this->orderDetails['details']['has_ST'])){
echo "<table border='0'>";
foreach ($this->shipmentfields['fields'] as $field) {
if (!empty($field['value'])) {
echo '<tr><td class="key">' $field['title'] . '</td>'
'<td>' $field['value'] . '</td></tr>';
}
}
echo "</table>";
} else {
echo "<br/>".vmText::_('COM_VM_ST_SAME_AS_BT');
}

?>

        </td>
Title: Re: Modification in the email template to show „Same as billing” same address
Post by: man.of.earth on October 16, 2019, 17:29:51 PM
Originally, I saw that done for orders in frontend (that's where I was inspired from), but in the emails sent, it does not detect $this->orderDetails['details']['has_ST'] correctly.
I echoed that value and it showed nothing.
I was wondering: should I call a model before that, or...?
Title: Re: Modification in the email template to show „Same as billing” same address
Post by: man.of.earth on October 16, 2019, 17:54:47 PM
It works now!  :D
The difference was the ,,D" capital letter from orderDetails (I used orderdetails).

Curiously, for displaying this for orders in frontend, it works correctly only if used orderdetails (and not orderDetails with capital ,,D")  :D.
Title: Re: Modification in the email template to show „Same as billing” same address
Post by: AH on October 16, 2019, 21:03:57 PM
yes they are different

Order FE display

$this->orderdetails['details']['has_ST']

Invoice

$this->orderDetails['details']['has_ST']