Return to on legacy customer accounts

Short description of issue

Return to on legacy customer accounts

Reproduction steps

N/A

Additional info

Is it still possible to redirect back to a page with legacy customer accounts?

I tried using the following but had no luck:

{{ routes.account_login_url }}?return_to={{ request.path | url_encode }}

What type of topic is this

General discussion

Have you tried adding a customer_login form input as follow ?

<input type="hidden" name="return_to" value="...">

1 Like

I’m not sure if that’ll work for my scenario, I need a dynamic return to. Essentially have a login button on product pages, so need to redirect to whatever product the user was on.

Just tested on my end, stock the URL in the query parameters and on form submission, preventDefault, integrate the return_to input and submit the form, you should be redirected to the URL :wink:

Here is some pseudo-code:

form.addEventListener('submit', (event) => {
  event.preventDefault();
  const form = event.currentTarget;

  const returnToPath = new URLSearchParams(window.location.search).get('return_to');

  const hiddenInput = document.createElement('input');
  hiddenInput.type = 'hidden';
  hiddenInput.name = 'return_to';
  hiddenInput.value = returnToPath;
  form.appendChild(hiddenInput);

  form.submit();
});

This redirected me to the URL