пятница, 10 апреля 2009 г.

CubeCart Empties Basket and sessions fix

CubeCart logo

Symptoms - you add product to busket, but when you open it - you see empty basket. In result you lost customer, "clicking 'checkout' Empties Basket For 30% Of Customers"...

This solution applyed for CubeCart 3 with SEO Urls (User Friendly URL, Human Friendly URL, SEF) but I believe that in CubeCart 4 problem the same.

First of all I scrutinize symptoms and see that if we first open url with category (or document), than it was ok - we have only one cookie and one session.

But if we first open product than if we go to category - we have one more cookie with same name and new session.

After testing I found part of code that in use (session.inc.php)
if(!isset($_SESSION['ccUser']) && $results == FALSE) {
...
} else {
...
}


And in second case (first open product url) if we go to category we have no session (!isset($_SESSION['ccUser']===TRUE) and so create it one more time.

I decide that problem was in $session name and comment two lines of code (sessionStart.inc.php)

@ini_set("session.cookie_path",$sessionDomain);
session_name($sessionName);


and wow - its working, no more double session/cookies. I think that this is bug with name of session.

But when I went to sleep I think about this again and decide that if it was bug with session name it was fixed very soon.

And I understand that problem was in cookie_path. Of course - why I don't understand early - products have bigger nesting level

domain/category
domain/category/product

than product, so cookie set for certain category will work only with products inside of this category. I check and see that

$sessionDomain = substr($GLOBALS['rootRel'],0, strlen($GLOBALS['rootRel'])-1);

if $GLOBALS['rootRel'] ='\' return '' to us ($sessionDomain = ''). So used relative url for cookies, not cookies for whole domain (so if we first visit product page our first cookie set only for products with same category, not for whole domain and we can't see it in another category or basket etc.).

This is as I think - category nested in domains, so cookie set for category work for whole domain, and cookie for products only work for products in certain category.

So if you wanna fix - you need to find something like this
@ini_set("session.cookie_path",$sessionDomain);

in files working with session and just comment.

It took me whole day to find problem, and I hope this help to decide you problem faster.
What reason for redefinition session.cookie_path I really don't understand. (probably to separate site and admin part, but in result we lost customers.)

If you want to thank or you have a questions please comment.

Комментариев нет: