我有一个看起来像这样的数组:
Array ( [0] => Credit Card Type [1] => MasterCard )
Array ( [0] => Credit Card Number [1] => xxxx-1111 )
Array ( [0] => Processed Amount [1] => $106.91 )
Array ( [0] => Transaction Id [1] => 5011056094736597703015 )
Array ( [0] => AVS Response [1] => Z (Street address does not match, but 5-digit postal code matches.) )
Array ( [0] => CVN Response [1] => M (Card verification number matched.) )
Array ( [0] => Merchant Reference Code [1] => 25f11646823dc7488b48c04491335936 )
我正在使用print_r(array($_label, $_value));
来显示上述内容。
我想换出商家参考代码值,这是长字母数字编号。
这是一个magento构建,所以我假设我回应
$order = Mage::getModel('sales/order')->load($orderId);
echo $order->getIncrementId();
完成工作最合适的方式是什么?
array_splice
或array_push
?
非常感谢任何帮助。谢谢。
<div class="cards-list">
<?php if (!$this->getHideTitle()): ?>
<div class="bold"><?php echo $this->escapeHtml($this->getMethod()->getTitle()) ?></div>
<?php endif;?>
</div>
<?php
$cards = $this->getCards();
$showCount = count($cards) > 1;
?>
<?php foreach ($cards as $key => $card): ?>
<?php if ($showCount): ?>
<span><?php echo sprintf($this->__('Credit Card %s'), $key + 1); ?></span>
<?php endif;?>
<table class="info-table<?php if ($showCount):?> offset<?php endif;?>">
<tbody>
<?php foreach ($card as $_label => $_value):?>
<tr>
<td><?php echo $this->escapeHtml($_label)?>:</td>
<td><?php echo nl2br(implode($this->getValueAsArray($_value, true), "\n"))?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endforeach; ?>
答案 0 :(得分:2)
好的,所以根据你提供的print_r输出,我假设你循环一个看起来如下的数组并打印键($ _label)和值($ _value)。 / p>
math
那么为什么不取消设置商家参考代码键并将所需的键/值添加到数组中。例如:
$data = array(
'Credit Card Type' => 'MasterCard',
'Credit Card Number' => 'xxxx-1111',
'Processed Amount' => '$106.91',
'Transaction Id'=> '5011056094736597703015',
'AVS Response' => 'Z (Street address does not match, but 5-digit postal code matches.)',
'CVN Response' => 'M (Card verification number matched.)',
'Merchant Reference Code' => '25f11646823dc7488b48c04491335936'
);
答案 1 :(得分:1)
我认为你可以取代:
<?php foreach ($card as $_label => $_value):?>
<tr>
<td><?php echo $this->escapeHtml($_label)?>:</td>
<td><?php echo nl2br(implode($this->getValueAsArray($_value, true), "\n"))?></td>
</tr>
<?php endforeach; ?>
使用:
<?php foreach ($card as $_label => $_value): ?>
<?php if ($_label === 'Merchant Reference Code') {
continue;
} ?>
<tr>
<td><?php echo $this->escapeHtml($_label)?>:</td>
<td><?php echo nl2br(implode($this->getValueAsArray($_value, true), "\n"))?></td>
</tr>
<?php endforeach; ?>
<tr>
<td>Order ID:</td>
<td><?php echo $order->getIncrementId();?></td>
</tr>
注意: 可能会添加$this->__()
来翻译&#34;订单ID&#34;和&#34;商家参考代码&#34;
修改以回复评论
如果模板块类继承自Mage_Core_Block_Abstract
,则可以使用$this->__('some String)
使用Magentos默认方法来翻译某些内容。
首先要取代
<?php if ($_label === 'Merchant Reference Code') {
使用
<?php if ($_label === $this->__('Merchant Reference Code')) {
这使得这种检查语言不会被转换为客户语言。对于德语,它将首先翻译为<?php if ($_label === Refferenz Code) {
,它仍然有效。对于&#34;订单ID:&#34;。
支持不同语言......
使用
将My_Module.csv
添加到app/locale/{LANG_ISO}/
"Merchant Reference Code";"Translate string"
在app/code/{pool}/My/Module/ect/config.xml
中提供转换文件,将其添加到global
,frontend
或adminhtml
部分
<translate>
<modules>
<My_Module>
<files>
<default>My_Module.csv</default>
</files>
</My_Module>
</modules>
</translate>
将助手添加到&#34;启用&#34;翻译,将其添加到app/code/{pool}/My/Module/Helpers/Data.php
class My_Module_Helper_Data extends Mage_Core_Helper_Abstract
{
protected $_moduleName = 'My_Module';
}