Filipe Ferminiano
Filipe Ferminiano

Reputation: 8801

Undefined variable OpenCart

I'm trying to send order info to the success page in my OpenCart v2.0.3.1 store, to send data to Google Analytics. But I'm getting this error message on success page:

Undefined variable: order_tracker in /Applications/XAMPP/xamppfiles/htdocs/opencart/catalog/view/theme/default/template/common/success.tpl on line 21

But I'm defining order_tracker on

atalog/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;

EDIT: I change the last line to this:

$data['order_tracker'] = $order_tracker;

And it worked.

But, now I'm getting another error:

Undefined variable: order_id in <b>/Applications/XAMPP/xamppfiles/htdocs/opencart/catalog/controller/checkout/success.php</b> on line <b>85</b>

This is line 85:

$order_info = $this->model_checkout_order->getOrder($order_id);

And this is how I'm defining order_id

if (isset($this->session->data['order_id'])) {

            $order_id = $this->session->data['order_id'];

Upvotes: 2

Views: 1260

Answers (1)

cari
cari

Reputation: 2302

The problem lies within your array relation. If

$data['order_tracker'] = $order_tracker;

then

$order_id = $data['order_tracker']['order_id'];

will give you your order_id, not data['order_id'].

Edit:

In clear words, that means, you have to use this code:

if (isset($this->session->data['order_tracker']['order_id'])) {

        $order_id = $this->session->data['order_tracker']['order_id'];

Upvotes: 3

Related Questions