Php 在opencart(2.0.3.1)订单电子邮件(客户端和管理员)上向运输成本添加税费
如果订单的装运重量成本中存在文本手续费,我想添加手续费。我还希望避免编辑任何控制器。如何从我的视图中编辑Php 在opencart(2.0.3.1)订单电子邮件(客户端和管理员)上向运输成本添加税费,php,arrays,opencart,opencart2.x,Php,Arrays,Opencart,Opencart2.x,如果订单的装运重量成本中存在文本手续费,我想添加手续费。我还希望避免编辑任何控制器。如何从我的视图中编辑confirm.tpl <tfoot> <?php foreach ($totals as $total) { ?> <tr> <td colspan="4" class="text-right"><strong><?php echo $total[
confirm.tpl
<tfoot>
<?php foreach ($totals as $total) { ?>
<tr>
<td colspan="4" class="text-right"><strong><?php echo $total['title']; ?>:</strong></td>
<td class="text-right"><?php echo $total['text']; ?></td>
</tr>
<?php } ?>
</tfoot>
:
以下是我迄今为止所做的工作:
<tfoot>
<?php foreach ($totals as $total) { ?>
<?php
if(strpos($total['title'], "Handling") !== false) {
// handling exists, what now?
}
?>
<tr>
<td colspan="4" class="text-right"><strong><?php echo $total['title']; ?>:</strong></td>
<td class="text-right"><?php echo $total['text']; ?></td>
</tr>
<?php } ?>
</tfoot>
:
:
这里有一个枯燥无味的答案。如果我能改进这一点,请让我现在。它使用strpos来隐藏手续费,并将preg_替换为float,以便我执行一些基本的算术运算
<?php
$totals = array(
array('title' => 'Handling Fee', 'text' => '₱171.33'),
array('title' => 'Sub-Total', 'text' => '₱17,132.85'),
array('title' => 'Nationwide Fee', 'text' => '₱280.00')
);
?>
<tfoot>
<?php $toAdd = 0; foreach ($totals as $total) { ?>
<?php
if(strpos($total['title'], "Handling") !== false) {
$toAdd = (float)preg_replace('/[^.a-zA-Z0-9]/s', '', $total['text']);
} else { ?>
<tr>
<td colspan="4" class="text-right"><strong><?php echo $total['title']; ?>:</strong></td>
<td class="text-right"><?php
if($toAdd && (strpos($total['title'], 'Nationwide') !== false)) {
$nationwide = (float)preg_replace('/[^.a-zA-Z0-9]/s', '', $total['text']);
echo "₱". number_format($nationwide + $toAdd, 2, '.', ',');
} else {
echo $total['text'];
}
?></td>
</tr>
<?php } ?>
<?php } ?>
</tfoot>