Post by braveperson » Mon Jun 20, 2011 12:08 am

因为换了Linux主机,导致购物车出现严重异常问题,在该主机上安装1.4.9.4版本后,进入前台,添加一条商品至购物车中,购物车中可以正常显示,可是当我再添加第二条、第三条。。。的时候却不能显示出来了,在购物车中此时只能显示第一条添加进的商品。当我在购物车中删除显示的这个第一条添加的商品时候,接着第二条又显示了,而且也只是显示第二条一条,删掉后第三条又显示出来了...
经仔细研究发现,问题出在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
---------------------------------------------------------------------------------------------------------------------------------
Image
---------------------------------------------------------------------------------------------------------------------------------
step 2
---------------------------------------------------------------------------------------------------------------------------------Image
---------------------------------------------------------------------------------------------------------------------------------
step3
---------------------------------------------------------------------------------------------------------------------------------
Image
---------------------------------------------------------------------------------------------------------------------------------
step 4
---------------------------------------------------------------------------------------------------------------------------------Image
---------------------------------------------------------------------------------------------------------------------------------
step 5
---------------------------------------------------------------------------------------------------------------------------------
Image
---------------------------------------------------------------------------------------------------------------------------------
step 6
---------------------------------------------------------------------------------------------------------------------------------
Image
---------------------------------------------------------------------------------------------------------------------------------
step 7
---------------------------------------------------------------------------------------------------------------------------------
Image
---------------------------------------------------------------------------------------------------------------------------------

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?
Last edited by braveperson on Mon Jun 20, 2011 1:56 am, edited 1 time in total.

Newbie

Posts

Joined
Sun Jun 19, 2011 11:50 pm

Post by braveperson » Mon Jun 20, 2011 12:16 am

请各位帮忙研究一下,谁的英文流畅的话,可以帮我转译成英文的话也行,可以发送给 Daniel ,看一下。

Newbie

Posts

Joined
Sun Jun 19, 2011 11:50 pm

Post by braveperson » Mon Jun 20, 2011 12:59 am

谁可以帮我,我被这个问题弄得晕头转向了。

:choke:

Newbie

Posts

Joined
Sun Jun 19, 2011 11:50 pm

Post by Daniel » Mon Jun 20, 2011 1:11 am

sorry i can not read Chinese. although i'm looking to hire 2 Chinese developers.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by braveperson » Mon Jun 20, 2011 1:18 am

Daniel wrote:sorry i can not read Chinese. although i'm looking to hire 2 Chinese developers.
:laugh:

It doesn't matter.
i'll give some pictures to you .

Newbie

Posts

Joined
Sun Jun 19, 2011 11:50 pm

Post by king_lake » Tue Jun 21, 2011 4:19 pm

系统设置问题,说明里面有讲到阿。
# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

这就是问题所在.

Newbie

Posts

Joined
Tue May 03, 2011 7:45 pm

Post by braveperson » Wed Jun 22, 2011 1:32 pm

king_lake wrote:系统设置问题,说明里面有讲到阿。
# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

这就是问题所在.

我来试一下

Newbie

Posts

Joined
Sun Jun 19, 2011 11:50 pm
Who is online

Users browsing this forum: No registered users and 4 guests