经仔细研究发现,问题出在system/library/cart.php中,该类中的函数:public function getProducts()乃最终原因。
该函数如下:
public function getProducts() {
$product_data = array();
foreach ($this->session->data['cart'] as $key => $value) {
....
....
}
return $product_data;
}
此处返回的购物车商品数组中始终为1条商品,经测试发现是由于foreach只执行了一次循环。
例如我现在添加三条商品到购物车中,那么此处foreach应执行3次,$product_data数组中应包含三条商品的数据,但是实际上却只执行了1次。
接下来测试foreach是否有问题,于是我在foreach前又添加如下代码:
foreach($this->session->data['cart'] as $key => $value){
$this->log->write($key . "=" . $value);
}
即输出所以session中购物车信息,此时却可以实实在在的执行三次了。
所以该问题非常蹊跷,想请教各位高手相助。
step 1
---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------
step 2
---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------
step3
---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------
step 4
---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------
step 5
---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------
step 6
---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------
step 7
---------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------
so i check the function getProducts in system/libray/cart.php
code:
public function getProducts() {
$product_data = array();
foreach ($this->session->data['cart'] as $key => $value) {
....
....
}
return $product_data;
}
i found " return $product_data " just can return one product infomation, in function getProducts() .
so i chaged the code:
public function getProducts() {
$product_data = array();
foreach ($this->session->data['cart'] as $key => $value) {
$this->log->write($key . "=" . $value);
}
foreach ($this->session->data['cart'] as $key => $value) {
....
....
}
return $product_data;
}
then i refresh the page "index.php?route=checkout/cart", and then i opened error.txt ,
i find the first foreach{} run 2 time's loop.
but the second foreach{} run 1 time loop all the time.
I don't know why this is?