1

So I want to do redirect to the following URL:

http:/www.url.com/checkout?foo=bar

Tried using this:

drupal_goto($path = 'checkout', $options = array( 'query' => array( 'foo' => 'bar')), $http_response_code = 302);

Now it works, but instally redirects to this:

http:/www.url.com/checkout/order_id/

...meaning that I lose the GET variable. How do I do this? The same happens if you just type /checkout into the address bar, it redirects to checkout/order_id. I think it might be commerce doing this automatically. Any idea how to resolve this?

2 Answers 2

1

drupal_goto should work just fine. You can confirm (e.g with Firebug) that it does the initial redirect to where you want (including foo=bar). Then you'll see a second redirect to the plain URL which is being performed by another code/module that you haven't told us about.

1
  • Hey @cherouvim you're right about this! It goes to /checkout?foo=bar and then redirects to checkout/15 or whatever the order_id is. I think it is commerce by default because if I just manually type the url /checkout it does the same thing. Could I write a function that sends the GET value on or something? Oct 14, 2012 at 17:15
1

So the checkout URL path requires an order id else it is redirected by the commerce system.

To combat this issue I needed to get the current user's order ID, if they didn't have an order, one needed to be created, so that we do have an order ID. Once you have this you can then use drupal_goto with the path *checkout/order_id*. The checkout URL is now valid meaning the GET vars can be included and are no longer overwritten with a redirect.

global $user;
     $user_id = $user->uid;
     if($user_id){
        $uid =  $user_id;
     }else{
        $uid = 0; 
     }
      $order_id = commerce_cart_order_id($uid);
      if(!$order_id){
        commerce_cart_order_new($uid);
         $order_id = commerce_cart_order_id($uid);
      }

 drupal_goto($path = 'checkout/'. $order_id, $options = array( 'query' => array( 'amount' =>  $amount, 'allocation' =>  $allocation )), $http_response_code = 302);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.