function uc_wishlist_user in UC Wish List 6
Implementation of hook_user().
When a user logs in, any products on the wish list associated with the current session are moved to the newly authenticated user's wish list (or if that does not exist, the anonymous wish list is assigned as the user's wish list).
Also, provide a link to the user's wish list from the user's profile page.
File
- ./
uc_wishlist.module, line 208 - Allows users to create public shopping/wish lists.
Code
function uc_wishlist_user($op, &$edit, &$user, $category = NULL) {
switch ($op) {
case 'login':
$oldwid = db_result(db_query("SELECT wid FROM {uc_wishlists} WHERE uid = '%s'", session_id()));
$newwid = uc_wishlist_get_wid();
if ($oldwid && $newwid) {
$res = db_query("SELECT * FROM {uc_wishlist_products} WHERE wid = %d", $oldwid);
while ($obj = db_fetch_object($res)) {
// NOTE: the delete must precede uc_wishlist_add_item because
// it may update the old record but we expect it to insert
// a new record
db_query("DELETE FROM {uc_wishlist_products} WHERE wpid = %d", $obj->wpid);
uc_wishlist_add_item($obj->nid, $obj->qty, unserialize($obj->data), $newwid);
}
db_query("DELETE FROM {uc_wishlists} WHERE wid = %d", $oldwid);
}
elseif ($oldwid && !$newwid) {
db_query("UPDATE {uc_wishlists} SET uid = %d WHERE wid = %d", $user->uid, $oldwid);
}
break;
case 'view':
$res = db_query("SELECT * FROM {uc_wishlists} WHERE uid = %d", $user->uid);
$items = array();
while ($obj = db_fetch_object($res)) {
$items['wishlist_' . $obj->wid] = array(
'value' => l($obj->title, "wishlist/{$obj->wid}"),
);
}
if (count($items) > 0) {
return array(
t('Wish lists') => $items,
);
}
break;
case 'delete':
// Find and delete any wish lists associated with the user being deleted.
$result = db_query("SELECT wid FROM {uc_wishlists} WHERE uid = %d", $user->uid);
while ($row = db_fetch_object($result)) {
uc_wishlist_delete($row->wid);
}
break;
}
}