A reply to my own post about adding wish list link to product listing page. I was able to do this via AJAX: a link underneath 'sold out' items calls the wishlist AJAX module I wrote to add the product to wishlist, and to show confirmation box. The code that calls it is in includes/functions/functions_general.php zen_get_buy_now_button, in 'case' for sold out:
also added to templates/tpl_modules_product_listing.php, at end - assumes you have jquery in /ajax dir:Code:if (UN_MODULE_WISHLISTS_ENABLED) { if ($_SESSION['customer_id']) { $return_button .= "<br /><a href='javascript:AddToWishlist($product_id);'>add to wish list</a>"; } }
Finally, this is the simple wishlist_ajax.php file in store home directory:Code:<script language="javascript"> if (!window.jQuery) { var jq = document.createElement('script'); jq.type = 'text/javascript'; // Path to jquery.js file, eg. Google hosted version jq.src = '/ajax/jquery.js'; document.getElementsByTagName('head')[0].appendChild(jq); } function AddToWishlist(product_id) { var url = '/wishlist_ajax.php' + '?nocache=' + new Date().getTime() + '&product_id=' + product_id; $.get(url,'',AddToWishlistDone); } function AddToWishlistDone(data,status) { alert(data); } </script>
Pretty simple, works great. In action: www.capriflavors.comCode:<?php require('includes/application_top.php'); if (!$_SESSION['customer_id']) { echo "Please login."; exit; } if (!isset($_GET['product_id'])) { echo "Invalid product."; exit; } $product_id = (int)$_GET['product_id']; if (!$product_id) { echo "Invalid product."; exit; } $data = $db->Execute("select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = 1" ); $product_name = $data->fields['products_name']; require_once(DIR_WS_CLASSES . 'wishlist_class.php'); $oWishlist = new un_wishlist($_SESSION['customer_id']); $oWishlist->addProduct($product_id, array()); echo "$product_name added to Wish List"; ?>


Reply With Quote
