OpenCart add to array
This may be very simplistic question but I can't find the answer. I want to add a key/value pair to an array in OpenCart but I can't seem to get it to work. I'm not sure if what I'm adding to is already an array.
开发者_JAVA技巧In catalog/controller/account/history.php at line 66 there is the definition of an array:-
$this->data['orders'][] = array(
'order_id' => $result['order_id'],
'name' => $result['firstname'] . ' ' . $result['lastname'],
'status' => $result['status'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'products' => $product_total,
'total' => $this->currency->format($result['total'], $result['currency'], $result['value']),
'href' => HTTPS_SERVER . 'index.php?route=account/invoice&order_id=' . $result['order_id']
);
I want to add to this array using VQMod. VQMod won't let me replace a line within the definition. I don't know why, I've tried for a couple of hours, it just won't. So I decided to add a line beneath it like so:-
$this->data['orders']['amountToPay'] = $paymentState['amountToPay'];
This doesn't work. Not even if I type it directly in the page. I reckon I've messed up the syntax but don't see how unless I'm not understanding the array structure.
Any help appreciated.
You can use the following line -
$this->data['orders'][sizeof($this->data['orders'])-1]['amountToPay'] = $paymentState['amountToPay'];
Because your $this->data['orders'] is also a numeric indexed array which contains collection of associative array.
I think your problem will be solved.
Pretty easy to do this using vQmod. Basically you need to search for
$this->data['orders'][] = array(
and put the line after it. Here's what you need to put in your custom vQmod XML file
<file name="catalog/controller/account/history.php">
<operation>
<search position="after"><![CDATA[$this->data['orders'][] = array(]]></search>
<add><![CDATA['amountToPay' => $paymentState['amountToPay']]]></add>
</operation>
</file>
精彩评论