hyyan / woo-poly-integration

Looking for maintainers! - Wordpress WooCommerce Polylang Integration
https://wordpress.org/plugins-wp/woo-poly-integration/
MIT License
183 stars 66 forks source link

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

Closed Jon007 closed 6 years ago

Jon007 commented 7 years ago

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 commented 7 years ago

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:

@hyyan what's the use case for this?

Jon007 commented 7 years ago

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 commented 7 years ago

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 commented 6 years ago

quick note:

hyyan commented 6 years ago

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