Force Login Then Redirect

We have certain promotions where users with special pricing need to log in before visiting a particular page.

So for example if we're trying to sell pumpkin seeds, retail customers and wholesalers both go to /pumpkin-seeds/ but wholesalers will see different prices. If they are not logged in they see wholesale prices.

If we direct them to the site with http://site.tld/login.html?return_url=pumpkin-seeds, and they are not authenticated already, they will be redirected to pumpkin seeds after logging in. However, for users that are already logged in, the link will take them to the root of the site.

Around line 248 of controllers/common/auth.php we have:

    if (!empty($auth['user_id'])) {
        return array(CONTROLLER_STATUS_REDIRECT, fn_url());
    }

If that section is like this instead:

    if (!empty($auth['user_id'])) {
        if (!empty($_REQUEST['return_url'])) {
            $redirect_url = $_REQUEST['return_url'];
        } else {
            $redirect_url = fn_url();
        }
        return array(CONTROLLER_STATUS_REDIRECT, $redirect_url);
    }
Already logged in users will be redirected. As far as I understand controller structure, this won't work in a post controller?
I could create another addon controller that redirects to the login page for not-logged-in users or redirects to the correct page for logged in users.
Unless there is already some way to do this I'm not thinking of?

Generally, if you want to intercept before the REQUEST data is processed you would use a pre controller.

If all you're wanting is to have non-logged in user see retail pricing and logged in uses see either retail or some discounted amount, then use the quantity pricing to determine the prices. You can have wholesale users in a separate group where they would get additional discounts. I.e.

Prices:for usergroups

all = retail

registered = discounted

wholesale = wholesale discount

Not sure of your need to redirect them, but you can use a pre-controller if you really need to do that.