Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

getLoginRedirectPermalink redirects to my account when trying to access an order #207

Closed
Jon007 opened this issue Jul 1, 2017 · 5 comments
Assignees

Comments

@Jon007
Copy link
Contributor

Jon007 commented Jul 1, 2017

Steps to Reproduce

  1. Log out of the system
  2. Attempt to directly access an order page eg http://mysite/my-account/view-order/12345/
  3. Login form is presented, note that login form contains hidden input _wp_http_referer
  4. do login

What I Expected

  1. expected to redirect to order page

What Happened Instead

  1. user is redirected to My Account page

Actually the same problem exists in WooCommerce #15911,
however woo-poly also filters woocommerce_login_redirect and getLoginRedirectPermalink() page look up causes redirects to the root page (eg the my-account page) instead of the requested endpoint.

@Jon007
Copy link
Contributor Author

Jon007 commented Jul 1, 2017

In this case, I recommend the removal of the woo-poly Login.php, there is no need for this plugin to attempt to modify the login behaviour.

removal can be done quickly in various ways:

  • plugin.php l.180 comment out // new Login();
  • login.php comment out the filter
    ...

@hyyan what's the use case for this?

@Jon007 Jon007 added this to the 1.0.2 milestone Jul 16, 2017
@hyyan hyyan closed this as completed in 3d09512 Jul 29, 2017
@Jon007 Jon007 reopened this Aug 3, 2017
@Jon007
Copy link
Contributor Author

Jon007 commented Aug 3, 2017

this will be broken again in 1.0.3 as the login code has been restored: this means when the client is logging in from an email to pay for an order for example, the login redirects to my account home page, instead of the order or payment page.

This is because the code is only looking up the link for the page (which is un-necessary) and does not know about the endpoint requested.

(There was also a related change in WooCommerce to fix the login direct to endpoint, this is now done.)

@Jon007
Copy link
Contributor Author

Jon007 commented Aug 13, 2017

Ok, I got it, there's no translation for the endpoints in URLs so the login is maybe deliberately stripping the endpoint.

To solve, there's a missing filter which can be implemented like this in endpoints.php:

        add_filter(
                'woocommerce_get_endpoint_url', array($this, 'translateEndpoints'), 10, 4
        );
    /**
     * Filter endpoint links in emails and menus to get correctly translated endpoint link
     *
     * @param  string $endpoint
     * @param  string $value
     * @param  string $permalink
     *
     * @return string
     */
    public function translateEndpoints($url, $endpoint, $value, $permalink)
    {
        $correctEndpoint = $this->getEndpointTranslation($endpoint);
        if ($correctEndpoint!=$endpoint){
            $url = str_replace($endpoint, $correctEndpoint, $url);
        }
        return $url;
    }

Then for example if you want to add order links to emails, this code works whatever the order language:
echo($order->get_view_order_url()); ?>"><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() );

(as long as you also disable the login filter so it is possible to link through to the order after login)

It doesn't quite solve the @todo comment on links in menus, since the menu editor isn't aware of the language of the menu being edited....

@Jon007 Jon007 removed this from the 1.0.2 milestone Sep 8, 2017
@Jon007
Copy link
Contributor Author

Jon007 commented Dec 3, 2017

quick note:

  • this woocommerce_get_endpoint_url filter didn't work so was taken out of endpoints.php
  • the login.php code I needed to remove in my scenario, as I recall I removed the login.php logic in 1.0.2 when this was first closed and @hyyan you re-added it in version 1.0.3.
    I need to remove it as it breaks eg link in email to open your order.
    Without the login.php you can log straight into your order in the email language.
    So I need that login.php removed, it breaks "pay for order" type links in emails etc.
    If there is any good reason for it to exist we could leave an option but I can't see the scenario where it might be needed at the moment..

@hyyan
Copy link
Owner

hyyan commented Dec 12, 2017

Hmmm , @Jon007 As far as I can remember this part exists since version 0.1 to allow login page translation, it was just as a workaround. But as the plugin has evolved a lot has been changed.
So you are right this part is not really required anymore.

Closing no need to invest time in this part

@hyyan hyyan closed this as completed Dec 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants