I have played with this even further and found the issue to be even more simple that what was previously presented. Please read all to get the gist of the issue. I wish to mention here that only the inclusion of a simple "href" is even causing the same error. Here is an example of the code causing the same problem described below.
This is the entire custom email/order/shipment/track.phtml file as modified with the added usps link.
<?php $_shipment=$this->getShipment() ?>
<?php $_order=$this->getOrder() ?>
<?php if ($_shipment && $_order && $_shipment->getAllTracks()): ?>
<table cellspacing="0" cellpadding="0" border="0" width="100%" style="border:1px solid #bebcb7; background:#f8f7f5;">
<thead>
<tr>
<th align="left" style="padding:3px 9px; background:rgb(242,248,228); border-bottom:1px solid #bebcb7;"><?php echo $this->__('Shipped By') ?></th>
<th align="center" style="padding:3px 9px; background:rgb(242,248,228); border-bottom:1px solid #bebcb7;"><?php echo $this->__('Tracking Number') ?></th>
</tr>
</thead>
<tbody>
<?php $i=0; foreach ($_shipment->getAllTracks() as $_item): $i++ ?>
<tr <?php echo $i%2?'bgcolor="#eeeded"':'' ?>>
<td align="left" valign="top" style="padding:3px 9px">United States Postal Service</td>
<td align="center" valign="top" style="padding:3px 9px"><a href="https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=<?php echo $_item->getNumber() ?>"><?php echo $_item->getNumber() ?></a></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php endif; ?>
This is the original track.phtml file found in base/default.
<?php $_shipment=$this->getShipment() ?>
<?php $_order=$this->getOrder() ?>
<?php if ($_shipment && $_order && $_shipment->getAllTracks()): ?>
<table cellspacing="0" cellpadding="0" border="0" width="100%" style="border:1px solid #bebcb7; background:#f8f7f5;">
<thead>
<tr>
<th align="left" bgcolor="#d9e5ee" style="padding:3px 9px"><?php echo $this->__('Shipped By') ?></th>
<th align="center" bgcolor="#d9e5ee" style="padding:3px 9px"><?php echo $this->__('Tracking Number') ?></th>
</tr>
</thead>
<tbody>
<?php $i=0; foreach ($_shipment->getAllTracks() as $_item): $i++ ?>
<tr <?php echo $i%2?'bgcolor="#eeeded"':'' ?>>
<td align="left" valign="top" style="padding:3px 9px"><?php echo $_item->getTitle() ?></td>
<td align="center" valign="top" style="padding:3px 9px"><?php echo $_item->getNumber() ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php endif; ?>
ORIGINAL MESSAGE:
We use a transactional email template for shipping notifications sent to customers when their order has shipped. The template contains the code below to insert the track/phtml block to add the tracking number with URL in the message.
{{block type='core/template' area='frontend' template='email/order/shipment/track.phtml' shipment=$shipment order=$order}}
Inside track.phtml, we added custom php code to wrap the tracking number is a hyperlink. When entering the tracking number manually and selecting the carrier, we have no problem. The t/n arrives as an active hyperlink. The title is, of course, automatically selected when the carrier is chosen from the drop-down box.
<?php $_shipment=$this->getShipment() ?>
<?php $_order=$this->getOrder() ?>
<?php if ($_shipment && $_order && $_shipment->getAllTracks()): ?>
<table cellspacing="0" cellpadding="0" border="0" width="100%" style="border:1px solid #bebcb7; background:#f8f7f5;">
<thead>
<tr>
<th align="left" style="padding:3px 9px; background:rgb(242,248,228); border-bottom:1px solid #bebcb7;"><?php echo $this->__('Shipped By') ?></th>
<th align="center" style="padding:3px 9px; background:rgb(242,248,228); border-bottom:1px solid #bebcb7;"><?php echo $this->__('Tracking Number') ?></th>
</tr>
</thead>
<tbody>
<?php $i=0; foreach ($_shipment->getAllTracks() as $_item): $i++ ?>
<tr <?php echo $i%2?'bgcolor="#eeeded"':'' ?>>
<td align="left" valign="top" style="padding:3px 9px"><?php echo $_item->getTitle() ?></td>
<?php if ($_item->getCarrierCode()=='usps'): ?>
<td align="center" valign="top" style="padding:3px 9px"><a href="https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=<?php echo $_item->getNumber() ?>"><?php echo $_item->getNumber() ?></a></td>
<?php else: ?>
<?php if ($_item->getCarrierCode()=='fedex'): ?>
<td align="center" valign="top" style="padding:3px 9px"><a href="http://www.fedex.com/fedextrack/index.html?tracknumbers=<?php echo $_item->getNumber() ?>"><?php echo $_item->getNumber() ?></a></td>
<?php else: ?>
<?php if ($_item->getCarrierCode()=='ups'): ?>
<td align="center" valign="top" style="padding:3px 9px"><a href="http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&trackNums=<?php echo $_item->getNumber() ?>&track.x=Track"><?php echo $_item->getNumber() ?></a></td>
<?php else: ?>
<?php if ($_item->getCarrierCode()=='dhl'): ?>
<td align="center" valign="top" style="padding:3px 9px"><?php echo $_item->getNumber() ?></td>
<?php else: ?>
<td align="center" valign="top" style="padding:3px 9px"><?php echo $_item->getNumber() ?></td>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php endif; ?>
We started using a third-party shipping service called ShippingEasy. They automatically return the tracking number to Magento through an API. They also change the title, not the carrier, to contain the name ShippingEasy and a unique transaction number.
Here is the problem. For some reason, the track.phtml block is completely ignored when ShippingEasy delivers the t/n through the API. Their system properly selects the carrier as "usps." The transactional email is sent just fine, but with no tracking number and no table. So, we altered the code in track.phtml to getTitle and look for "ShippingEasy." See below.
<?php $_shipment=$this->getShipment() ?>
<?php $_order=$this->getOrder() ?>
<?php if ($_shipment && $_order && $_shipment->getAllTracks()): ?>
<table cellspacing="0" cellpadding="0" border="0" width="100%" style="border:1px solid #bebcb7; background:#f8f7f5;">
<thead>
<tr>
<th align="left" style="padding:3px 9px; background:rgb(242,248,228); border-bottom:1px solid #bebcb7;"><?php echo $this->__('Shipped By') ?></th>
<th align="center" style="padding:3px 9px; background:rgb(242,248,228); border-bottom:1px solid #bebcb7;"><?php echo $this->__('Tracking Number') ?></th>
</tr>
</thead>
<tbody>
<?php $i=0; foreach ($_shipment->getAllTracks() as $_item): $i++ ?>
<tr <?php echo $i%2?'bgcolor="#eeeded"':'' ?>>
<td align="left" valign="top" style="padding:3px 9px"><?php echo $_item->getTitle() ?></td>
<?php if (strpos($_item->getTitle(), 'ShippingEasy') !== false): ?>
<td align="center" valign="top" style="padding:3px 9px"><a href="https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=<?php echo $_item->getNumber() ?>"><?php echo $_item->getNumber() ?></a></td>
<?php else: ?>
<?php if ($_item->getTitle()=='Federal Express'): ?>
<td align="center" valign="top" style="padding:3px 9px"><a href="http://www.fedex.com/fedextrack/index.html?tracknumbers=<?php echo $_item->getNumber() ?>"><?php echo $_item->getNumber() ?></a></td>
<?php else: ?>
<?php if ($_item->getTitle()=='United Parcel Service'): ?>
<td align="center" valign="top" style="padding:3px 9px"><a href="http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&trackNums=<?php echo $_item->getNumber() ?>&track.x=Track"><?php echo $_item->getNumber() ?></a></td>
<?php else: ?>
<?php if ($_item->getTitle()=='DHL'): ?>
<td align="center" valign="top" style="padding:3px 9px"><?php echo $_item->getNumber() ?></td>
<?php else: ?>
<td align="center" valign="top" style="padding:3px 9px"><?php echo $_item->getNumber() ?></td>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php endif; ?>
However, this still resulted in the API transfer of data from ShippingEasy to Magento to completely ignore inserting the block track.phtml in the transactional email.
Here is the odd part. If we revert to the track.phtml in base/default, the block is recognized and the t/n is transmitted. Furthermore, if we use our custom track.phtml file, we can resend the e-mail by manually clicking the button in Shipments in Order View to "Send Tracking Information" again.
One other thing. The reason the code looks for "ShippingEasy" in the title rather than an exact match is because:
- getCarrierCode worked manually when looking for "usps," but did not work with ShippingEasy.
<?php if ($_item->getCarrierCode()=='usps'): ?>
- Each shipment contains the name ShippingEasy with a unique transaction number. So, we cannot look for an exact match. We were hoping that detecting the "ShippingEasy" string in the title would work.
Before you suggest it, ShippingEasy was of no help in fixing this.
To add to it, we have tested this in both 1.4.1.1 and 1.9.2.1, and the results are the same.
So, what would cause the transfer via API to completely ignore the block only when the custom php or merely the HTML href hyperlink is included in the track.phtml file? Any suggestions?