OpenCart 添加到数组

发布于 2024-10-29 16:20:35 字数 1105 浏览 0 评论 0原文

这可能是一个非常简单的问题,但我找不到答案。我想向 OpenCart 中的数组添加一个键/值对,但我似乎无法让它工作。我不确定我添加的内容是否已经是一个数组。

在catalog/controller/account/history.php第66行有一个数组的定义:-

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

我想使用VQMod添加到这个数组。 VQMod 不允许我替换定义中的一行。不知道为什么,我试了好几个小时了,就是不行。所以我决定在它下面添加一行,如下所示:-

$this->data['orders']['amountToPay'] = $ paymentState['amountToPay'];

这是行不通的。即使我直接在页面中输入它也不会。我认为我已经搞乱了语法,但除非我不理解数组结构,否则我不知道如何搞砸。

任何帮助表示赞赏。

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╄→承喏 2024-11-05 16:20:35

您可以使用以下行 -

$this->data['orders'][sizeof($this->data['orders'])-1]['amountToPay'] = $paymentState['amountToPay']; 

因为您的 $this->data['orders'] 也是一个数字索引数组,其中包含关联数组的集合。

我想你的问题将会得到解决。

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.

手长情犹 2024-11-05 16:20:35

使用 vQmod 可以很容易地做到这一点。基本上你需要搜索

$this->data['orders'][] = array(

并将该行放在它后面。以下是您需要放入自定义 vQmod XML 文件中的内容

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文