1

In my Drupal site I have placed a link in checkout page which takes to user/login. On successful login it redirects back to checkout page. For this I have used ?destination=checkout in the url. I have achieved using form alter

function module_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
  $form['checkout_message']['#markup'] = t('<a href="/user/login?destination=/checkout">Click to login</a>');
}

This redirects to login page and then redirects back to checkout page, till now it works fine. I have social site login in my login page (for eg., facebook, twitter, google).

How can I redirect the user to checkout if he/she login via social sites? FYI: Above is not working for social network login.

These are the modules used for performing a social login:

2 Answers 2

1

You can use user_login_destination() for your requirement which third-party authentication modules may use to determine the proper destination after a user has been properly logged in.

function user_login_destination() {
  $destination = drupal_get_destination();
  if ($destination['destination'] == 'user/login') {
    $destination['destination'] = 'user';
  }
  return $destination;
}

You just need to change line 4 to:

$destination['destination'] = '<path you want to go to after login>';
1

I would use the Rules module to get this to work, using a variation of the sample rule included in my answer to "How to use the Rules module to implement a custom redirect for an outdated URL?". Here are some modifications you'd need to get it to work for your case also:

  • Adapt the URLs to point to your checkout page.
  • Add a Rules event specific to the social site they used to perform a login, i.e.:

By using Rules as detailed above, you probably won't need the custom code anymore that you already have (as mentioned in your question).

To make the value of the URL argument available as a new variable to Rules, you can use the Rules URL Argument module. Here is a quote about it (from its project page):

... provides two rules conditions based on URL arguments:

  • check if a URL argument is present.
  • compare the value of an URL argument.

It also provides an action that makes the value of an URL argument available as new variable to Rules.

The newly provided Rules actions and conditions can be found under the "URL Argument" conditions and actions groups in the rule configuration interface.

For an example of how to use it, refer to Comment # 3 in issue # 1686360 which is about "Pass an amount to the url, ie; site/content/node-title?amount=10 or /node-title?=amount:10". Here is the relevant part of it:

  • add a "Check if URL argument exist" condition to your rule and set the "ARGUMENT" value to "amount".
  • add "Provide URL argument value" action to the rule and set "URL ARGUMENT NAME" value to "amount" and in the "Provided variables" section "ARGUMENT FROM URL - Variable name" to e.g. "amount_from_url".

You will now be able to use the amount value as a variable "amount-from-url" for other actions in this rule.

PS: If you're not familiar (enough/yet) with Rules, checkout the 32 (!!!) great, and free, video tutorials Learn the Rules framework, organized in 7 chapters.

3
  • I want to redirect the user only when the url has destination parammeter. Is it possible with rules.
    – Vamsi
    Commented Nov 26, 2015 at 5:20
  • 1
    Sure you can do that too ... Via the Rules URL Argument module (as explained in my updated answer). Good enough? Commented Nov 26, 2015 at 7:07
  • In the social login link I have added destination parameter like below url. digi.co/hybridauth/window/…
    – Vamsi
    Commented Jul 19, 2016 at 7:36

Your Answer

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

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