O'Reilly logo

PHP 5 e-commerce Development by Michael Peacock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

From visitor to a user

When a visitor comes to our site, adds products to their basket, and then signs up, we need to transfer the basket to them, as a user. This would allow them to access this basket on other computers too.

The transferToUser function

A function within our basket model would make this easy; all it needs to do is find any products in the basket table, which are associated with the user's session data and update these records to have the user's ID contained.

/** * Transfer the basket to another user * @param int user id * @return bool */ public function transferToUser( $user ) { $changes = array( 'user_id' => $user ); $s = session_id(); $ip = $_SERVER ['REMOTE_ADDR']; $this->registry->getObject('db')-> updateRecords( 'basket_contents', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required