Here's how I imagine it'd get done.
- Create a custom module, call it UC_ajax_cart or something.
- In uc_ajax_cart.module you'll need a menu path that could be /cart/ajax/add - to which the vars get posted. (Using a GET would probably result in a redirect, especially if you are using a link.)
- Basically AJAX is just posting to another location. So your add to cart button would need to be a form (something that can POST vars) and your callback for /cart/ajax/add/.. will be a function that goes something like..
<?php
function uc_ajax_cart_add() {
$nid = $_POST['nid']; $qty = $_POST['qty']; // Make sure these vars are posting from the form.
uc_cart_add_item($nid, $qty); // Not sure if $data is required?
/** Turns out there is also a $check_redirect var..
uc_cart_add_item($nid, $qty = 1, $data = NULL, $cid = NULL, $msg = TRUE, $check_redirect = TRUE)
- So you could potentially override the redirect that way. **/
}
?>I think this would work, but it's untested. You would also need to add a drupal_add_js() bit of code that would basically be your AJAX callback - which would utilize jQuery to update the cart block. (The cart block might also need to be ajaxified for this reason - another part of the custom module.)
That's just my scattershot thoughts on the thing, anyway.



Joined: 08/14/2007