skip to Main Content

I have an array that looks like so:

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 )

I’m using print_r(array($_label, $_value)); to display the above.

I want to swap out the Merchant reference code value which is the long alpha numeric number.

This is a magento build so I’m assuming I’d echo

$order = Mage::getModel('sales/order')->load($orderId);

echo $order->getIncrementId();

What will be the most appropriate way to ge the job done?

array_splice or array_push?

Any help would be greatly appreciated. thank you.

<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; ?>

2

Answers


  1. OK, so based on the print_r output that you have provided, I’m going to assume that you are looping through an array that looks like the below and printing the key ($_label) and value ($_value).

    $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'
    );
    

    So why not just unset the Merchant Reference Code key and add what ever key/value you want into the array. eg:

    unset($data['Merchant Reference Code']);
    $data['Order Id'] = $order->getIncrementId();
    
    Login or Signup to reply.
  2. I think you can replace:

    <?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; ?>
    

    with:

    <?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>
    

    Note: maybe add $this->__() to translate “Order ID” and “Merchant Reference Code”


    Edit: to answer comment

    If you template block class inherits from Mage_Core_Block_Abstract you can use $this->__('some String) to use Magentos default method to translate something.

    So first thing is to replace

    <?php if ($_label === 'Merchant Reference Code') {
    

    With

    <?php if ($_label === $this->__('Merchant Reference Code')) {
    

    This makes this this check language indepented from being tranlated to the customers language. For german language it would be translated first to <?php if ($_label === Refferenz Code) { and it would still work. Same for “Order Id:”.

    To support different languages …

    • add My_Module.csv to app/locale/{LANG_ISO}/ with

      "Merchant Reference Code";"Translate string"
      
    • make tranlation file available in app/code/{pool}/My/Module/ect/config.xml add this to global, frontend or adminhtml section

      <translate>
          <modules>
              <My_Module>
                  <files>
                      <default>My_Module.csv</default>
                  </files>
              </My_Module>
          </modules>
      </translate>
      
    • add helper to “enable” translations, add this to app/code/{pool}/My/Module/Helpers/Data.php

      class My_Module_Helper_Data extends Mage_Core_Helper_Abstract
      {
          protected $_moduleName = 'My_Module';
      }
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search