【发布时间】:2015-04-22 17:18:13
【问题描述】:
所以我有这个控制器在电子商务网站上使用 CodeIgniter 的购物车类。
一切正常。它加载类,将产品添加到购物车,结账并完成交易。但是我需要在用户结账时检索一些信息(例如产品名称、ID、价格),然后将其发送到Mixpanel(这是一个分析工具)。
我已将此代码添加到结帐控制器中:
// Sends subscription information to mixpanel
$this->mixpanel_wrapper->people_set($aluno[0]->aluno_id, array(
'$first_name' => $student[0]->student_first_name,
'$last_name' => $student[0]->student_last_name,
'$email' => $student[0]->student_email,
));
$this->mixpanel_wrapper->identify($student[0]->student_id);
$this->mixpanel_wrapper->track_something('Added to cart', array ($this->cart->contents()));
// Ends mixpanel
它有效。在我的仪表板中,我看到特定用户激活了“已添加到购物车”事件。但是在这个事件的属性中,我看到了类似这样的内容(“属性”编号是由 mixpanel 自动添加的:
Property: 0
{"ee55c5260c7d5fe7fe9bc73b0e0cc82c":{"name":"Product 1","price":"99.00","qty":"1","rowid":"ee55c5260c7d5fe7fe9bc73b0e0cc82c","id":"8","subtotal":99,"options":{"category":"business","teacher":"La Gracia","image":"cozinhando.png","type":"course","description":"Montar uma apresentação é como cozinhar. Se você faz um “catadão” e coloca tudo na panela, sem ordem ou critério, sai uma gororoba. Uma experiência saborosa exige cuidado e atenção na seleção e preparo dos ingredientes. Nesse curso, aprenda"}},"1bebb39e8f44062ff10639f452ea8f8f":{"name":"Product 2","price":"59.00","qty":"1","rowid":"1bebb39e8f44062ff10639f452ea8f8f","id":"7","subtotal":59,"options":{"category":"creativity","teacher":"Pedro Maciel Guimarães","image":"cover_almodovar.png","type":"course","description":"Conheça a evolução das obras de Almodóvar por duas matrizes únicas: a imitação e o intercâmbio de gêneros. Passando por suas comédias e dramas, veremos como Almodóvar pensou e produziu seus diversos trabalhos, desde suas primeiras referências"}}}
此购物车中有 2 件商品。 “产品 1”和“产品 2”。但实际上我应该看到这样的东西:
Property: 0
Name: Product 1
Price: 99.00
Qty: 1
ID: 8
Property: 1
Name: Product 2
Price: 59.00
Qty: 1
ID: 7
Mixpanel 需要的是我把它转换成这样的数组来设置一个新用户:
$this->mixpanel_wrapper->people_set($aluno[0]->aluno_id, array(
'$first_name' => $aluno[0]->aluno_primeiro_nome,
'$last_name' => $aluno[0]->aluno_sobrenome,
'$email' => $aluno[0]->aluno_email,
));
有人知道如何从 CI 的购物车类中检索特定数据吗?像这样的:
$this->mixpanel_wrapper->track_something('User Logged In', array(
'Name' => $this->cart->contents->name,
'Product ID' => $this->cart->contents->id,
'Price' => $this->cart->contents->price,
'Quantity' => $this->cart->contents->qty,
));
我认为这可能真的很简单,但我(再次)被困在这里。
【问题讨论】:
标签: php codeigniter codeigniter-2 mixpanel