CodeIgniter 购物车 Class:如何检索数组中的独立值?
CodeIgniter Shopping Cart Class: How to retrieve independent values on an array?
所以我在一个电子商务网站上使用 CodeIgniter 的购物车 Class 有了这个控制器。
一切正常。它加载 class,将产品添加到购物车,去结账并完成交易。但是我需要在用户结帐时检索一些信息(例如产品名称、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
有效。在我的仪表板中,我看到特定用户激活了事件 "Added to Cart"。但是在这个事件的属性中我看到了这样的东西("property" 数字是由 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 件商品。 "product 1" 和 "product 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 的购物车 Class 中检索特定数据吗?像这样:
$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,
));
我想这可能真的很简单,但我(又)卡在这里了。
这与您 display the cart 时没有太大区别。遍历购物车数组,$this->cart->contents()
,并处理每个项目。
foreach ($this->cart->contents() as $item)
{
$this->mixpanel_wrapper->track_something('User Logged In', array(
'Name' => $item['name'],
'Product ID' => $item['id'],
'Price' => $item['price'],
'Quantity' => $item['qty'],
));
}
否则,遍历购物车并创建一个 Mixpanel 可以正确处理的新数组。
所以我在一个电子商务网站上使用 CodeIgniter 的购物车 Class 有了这个控制器。
一切正常。它加载 class,将产品添加到购物车,去结账并完成交易。但是我需要在用户结帐时检索一些信息(例如产品名称、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
有效。在我的仪表板中,我看到特定用户激活了事件 "Added to Cart"。但是在这个事件的属性中我看到了这样的东西("property" 数字是由 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 件商品。 "product 1" 和 "product 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 的购物车 Class 中检索特定数据吗?像这样:
$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,
));
我想这可能真的很简单,但我(又)卡在这里了。
这与您 display the cart 时没有太大区别。遍历购物车数组,$this->cart->contents()
,并处理每个项目。
foreach ($this->cart->contents() as $item)
{
$this->mixpanel_wrapper->track_something('User Logged In', array(
'Name' => $item['name'],
'Product ID' => $item['id'],
'Price' => $item['price'],
'Quantity' => $item['qty'],
));
}
否则,遍历购物车并创建一个 Mixpanel 可以正确处理的新数组。