我尝试将订单信息发送到OpenCart v2.0.3.1商店的成功页面,以便将数据发送到Google Analytics。 但是我在成功页面上收到此错误消息:
Undefined variable: order_tracker in /Applications/XAMPP/xamppfiles/htdocs/opencart/catalog/view/theme/default/template/common/success.tpl on line 21
但我在
上定义了order_trackeratalog/controller/checkout/success.php
$order_tracker = array(
'order_id' => $order_id,
'store_name' => $order_info['store_name'],
'total' => $order_info['total'],
'tax' => $order_tax,
'shipping' => $order_shipping,
'city' => $order_info['payment_city'],
'state' => $order_info['payment_zone'],
'country' => $order_info['payment_country'],
'currency' => $order_info['currency_code'],
'products' => $order_products
);
$this->data['order_tracker'] = $order_tracker;
修改 我将最后一行更改为:
$data['order_tracker'] = $order_tracker;
它有效。
但是,现在我又收到了另一个错误:
Undefined variable: order_id in <b>/Applications/XAMPP/xamppfiles/htdocs/opencart/catalog/controller/checkout/success.php</b> on line <b>85</b>
这是第85行:
$order_info = $this->model_checkout_order->getOrder($order_id);
这就是我定义order_id
的方式if (isset($this->session->data['order_id'])) {
$order_id = $this->session->data['order_id'];
答案 0 :(得分:3)
问题在于你的数组关系。如果
$data['order_tracker'] = $order_tracker;
然后
$order_id = $data['order_tracker']['order_id'];
会为您提供order_id,而不是data['order_id']
。
编辑:
简而言之,这意味着,您必须使用此代码:
if (isset($this->session->data['order_tracker']['order_id'])) {
$order_id = $this->session->data['order_tracker']['order_id'];