function cw_wl_get_product($wlitem)
{
    cw_load('product');
    $p = cw_wl_get_item($wlitem);
    return cw_product_get(array('id' => $p['product_id']));
}
    } else {
        db_query("insert into {$tables['wishlist']} (customer_id, amount, options, object) values ('{$customer_id}', '1', '', '" . addslashes(serialize($giftcert)) . "')");
    }
    cw_header_location("index.php?target=gifts&mode=wishlist");
}
if ($mode == 'wl2cart' && $wlitem) {
    // if in cart products from invoice, then new giftcert can't be added
    if (!empty($cart['info']['quote_doc_id'])) {
        $top_message['type'] = "E";
        $top_message['content'] = cw_get_langvar_by_name("err_add_product_to_cart_with_quote");
        cw_header_location('index.php?target=gifts&mode=wishlist');
    }
    define('DO_NOT_REDIRECT_CART', true);
    $action = 'add';
    // Add to cart product from wish list
    $wl = cw_wl_get_item($wlitem);
    if ($wl) {
        // Add gift certificate to the cart
        $giftcert = unserialize($wl['object']);
        if (!isset($cart['giftcerts'])) {
            $cart['giftcerts'] = array();
        }
        $cart['giftcerts'][] = cw_array_merge($giftcert, array('wishlistid' => $wlitem));
        $top_message = array('type' => 'I', 'content' => 'Wishlist item has been added to cart');
        $products = cw_call('cw_products_in_cart', array($cart, $userinfo));
        $cart = cw_func_call('cw_cart_calc', array('cart' => $cart, 'products' => $products, 'userinfo' => $userinfo));
    }
}
// Redirect
if (!empty($action)) {
    cw_header_location("index.php?target={$target}&mode={$redirect_mode}&event_id={$event_id}&js_tab={$js_tab}");