6 replies [Last post]
txcrew's picture
Offline
Joined: 09/28/2007
Juice: 103
Was this information Helpful?

Greetings all,

I'm struggling with the concept of having to redirect the user after a successful checkout back to the product node.

Basically I've created a cart link and a workflow that will examine if the customer has purchased a certain class of product, then upon a successful checkout (confirmation page) they will be redirected back to the products node ID.

However, Workflow_ng does not have a token for node/product id.

Does anyone know of a way to redirect the customer back to the page that they purchased the product on?

Let me know when you get a chance,

TIA,
txcrew

txcrew's picture
Offline
Joined: 09/28/2007
Juice: 103
Re: After Successful Checkout, Set Redirect to Prodcut Page

Answered my own issue. If anyone needs to do something similar you can see what I did below. Not sure if its the best way, but it got the job done.

<?php

foreach ($order->products as $product) {
$content=$product->nid;
};
drupal_goto($path = 'node/'.$content, $query = 'param=[order:order-id]', $fragment = NULL, $http_response_code = 302)
?>
activelyOUT's picture
Offline
Joined: 04/20/2009
Juice: 70
Re: Re: After Successful Checkout, Set Redirect to Prodcut Page

Where did you put this?

sesameseed77's picture
Offline
Joined: 09/27/2009
Juice: 23
Redirect after order depending on product type

1) Use hook_menu_alter to override the page callback for 'cart/checkout/complete'. Change

<?php
'page callback' => 'uc_cart_checkout_complete',
?>

to

<?php
 
'page callback' => 'yourCustomModule_checkout_complete',
?>

2) copy the code from 'uc_cart_checkout_complete' function and make alterations. Below I'm iterating through the products and checking for a particular product. If I find that product, I redirect to a certain page.

<?php
function edge_ubercart_menu_alter(&$items) {

 

$items['cart/checkout/complete'] = array(
   
'title' => 'Order complete',
   
'description' => 'Display information upon completion of an order.',
   
'page callback' => 'edge_ubercart_checkout_complete',
   
'access arguments' => array('access content'),
   
'type' => MENU_CALLBACK,
  );
 
}

function

edge_ubercart_checkout_complete() {

  if (!

$_SESSION['do_complete']) {
   
drupal_goto('cart');
  }

 

$order = uc_order_load(intval($_SESSION['cart_order']));

  if (empty(

$order)) {
   
// Display messages to customers and the administrator if the order was lost.
   
drupal_set_message(t("We're sorry.  An error occurred while processing your order that prevents us from completing it at this time. Please contact us and we will resolve the issue as soon as possible."), 'error');
   
watchdog('uc_cart', 'An empty order made it to checkout! Cart order ID: @cart_order', array('@cart_order' => $_SESSION['cart_order']), WATCHDOG_ERROR);
   
drupal_goto('cart');
  }
   
$output = '';
 
//$output = uc_cart_complete_sale($order, variable_get('uc_new_customer_login', FALSE));

  // Add a comment to let sales team know this came in through the site.
 

uc_order_comment_save($order->order_id, 0, t('Order created through website.'), 'admin');
   
 
/*
*
*  If product's node id is the one I want, I set the redirect!
*
*/
 
     
foreach($order->products as $product) {
           
   
                if(
$product->nid == EDGE_CREDITS_ECOACHING_NID) {
                   
                   
$page = 'mytraining';
                   
drupal_set_message(t("We have received your order."));
                   
drupal_goto($page);
                }
   
           
    }
// end foreach
     
     
  /*
  $page = variable_get('uc_cart_checkout_complete_page', '');
  if (!empty($page)) {
    drupal_goto($page);
  }
  */

 

return $output;

}

?>
sesameseed77's picture
Offline
Joined: 09/27/2009
Juice: 23
one more thing

in the code above I commented out

$output = uc_cart_complete_sale($order, variable_get('uc_new_customer_login', FALSE));

I shouldn't have done that. You still need to call this function to finish the order.

Yuri's picture
Offline
Joined: 05/26/2010
Juice: 35
Re: one more thing

Thank you very much. Could you elaborate a bit more on how to actually build this module and where to change the code?
Thanks

Yuri's picture
Offline
Joined: 05/26/2010
Juice: 35
Re: one more thing

Thank you very much. Could you elaborate a bit more on how to actually build this module and where to change the code?
Thanks