在opencart中获取购物车数据

How can I get cart information in open cart? I'm trying to get things like cart total in the tag.

I've tried $this->cart (Undefined property: Loader::$cart), and $registry->get('cart').

I'm editing catalog/view/theme/default/template/common/header.tpl

You can't load the library files in .tpl files in Opencart 2.X, You have to do this in controller & assign that variable in template file. eg

// Write something like that in controller
$data['cartData'] = $this->cart->getProducts();

You can access the cart products in .tpl file in $cartData variable.

Here's how I did it (so i don't forget next time!)

in the file catalog/controller/common/cart.php

Line 138

You can store the $data variable in the $_SESSION:

$_SESSION['cart_data'] = $data;