2

In the home page of main site, I am listing all the products. Buyer has logged into the main site and clicks on any product title or image, then I take the buyer to the corresponding sub domain individual product page. In the redirected page or site I want the buyer to logged in since I am using the same database.

This is what I have done for that to happen:

  • I am using the Rules module to redirect from one site to another site.
  • The Rules Event I am using is Content is viewed, but actually it doesn't get called at all.
  • In Rules I am using page redirect action with value http://[node:author].[site:url-brief]/ajax_callback.php?context=buyer-redirect&username=[account:name]&nid=[node:nid]

In my ajax_callback.php file I have used this code:

case 'buyer-redirect':
        global $user;
        $username = $_REQUEST['username'];
        $user = user_load_by_name($username);
        $login_array = array ('name' => $username);
        user_login_finalize($login_array);
        $nid = $_REQUEST['nid'];        
        drupal_goto('node/' . $nid);

But in the sub domain still I am not logged in as buyer.

Above mentioned is a PHP file where I am manipulating the requests, but Rules Event "Content is viewed" is not all getting invoked.

How can I make buyer login info to be send and make the buyer to be automatically logged in which clicking on a link in main site?

Any suggestions?

0

I'm pretty sure that the "... Content is viewed, but actually it doesn't get called at all ..." part of your question is not correct. And that this Rules Event does get called (if not you've found a major Rules bug ...), but that it is NOT the right Rules Event to use for your scenario. Read on for details (and a possible solution) ...

You should be able to get this to work, using the Rules module, using the "Drupal is initializing" event. That will ensure that the rule gets triggered BEFORE the actual content is shown. Using Rules event " Content is viewed " is typically 'too late'. Refer to 'How to specify a Rules event like "Content is 'going to be' viewed"?' for more details on that. Adapt your rule to use this event, and (just for temporary unit testing) add a Rules Action (as the very first Rules Action) to "Show a message on a site", e.g to say 'Bingo, let the Rules party begin (we did find a Rules Event to continue building on)'.

Moreover, as per the http://[node:author].[site:url-brief]/ajax_callback.php?context=buyer-redirect&username=[account:name]&nid=[node:nid] URL that you mentioned, you can make the value of the URL arguments (= such as the value of the context argument in this example) available as new variable to Rules, simply by using 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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