5 replies [Last post]
tom-d's picture
Offline
Bug Finder
Joined: 11/21/2007
Juice: 107
Was this information Helpful?

What I'm trying to do is change the redirect link for a single product while keeping the rest of my products with no redirect where they simply refresh the page while adding it to there cart.

Something like this

  • "Special redirect product" - redirect=/cart/checkout
  • "Everything else - no redirect

Cheers,

tom-d's picture
Offline
Bug Finder
Joined: 11/21/2007
Juice: 107
Re: Custom add to cart redirect

They are two different Content types (product types) if that makes a difference

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Custom add to cart redirect

Hey Tom, you're going to have to use a custom module w/ hook_form_alter() to accomplish this right now. Might seem like a bit of overkill, but it should be a quick job.

tom-d's picture
Offline
Bug Finder
Joined: 11/21/2007
Juice: 107
Re: Re: Re: Custom add to cart redirect

Thanks Ryan, I finally managed to create a custom module with my very limited php experience (it's getting better Smiling

<?php
function uc_subscribe_form_alter($form_id, &$form) {
      if (
$form_id == "uc_product_add_to_cart_form_495") {
       
$form['#action'] = url($_GET['q'], "destination=cart/checkout");
      return;
        }
}
?>

Basically this allows my form to redirect directly to checkout, which when it did I jumped for joy of course LOL!
What I need it to do now is it to empty the cart so they only have this one product in their cart, but for the life of me I can't work out how to do it!

any suggestions would be most appreciated

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: Re: Custom add to cart redirect

hehe Well, you might try a query... first, a big picture of how the shopping cart works. There's a database table called uc_cart_products where for every unique product in a cart, we store the qty and data array using the user ID or session ID of the customer as a key. The function uc_cart_get_items(), for example, loads up the items from this table and does stuff with them.

Your function can simply delete anything from that table that doesn't match this product's nid (which I'm assuming is 495?).

<?php
  db_query
("DELETE FROM {uc_cart_products} WHERE cart_id = '%s' AND nid != 495", uc_cart_get_id());
?>

You can do other queries to adjust the qty if you need to, too.

You should check out the Drupal API for db_query() for more info.

activelyOUT's picture
Offline
Joined: 04/20/2009
Juice: 70
helpfull info

thanks. this is pretty helpful. i am trying to do something similar but once checkout is completed. I am hoping I can do something like this.