Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: backend article preview 'shop' cookie #2737

Open
wants to merge 1 commit into
base: 5.7
Choose a base branch
from

Conversation

Dominikrt
Copy link
Contributor

1. Why is this change necessary?

If you have a subshop with a different domain and click on the preview button in the backend, you are no longer able to visit the main shop on the main domain. You get redirected to the subshop all the time.

2. What does this change do, exactly?

The shop cookie get a ttl from 30 seconds. after this time you can visit the main shop again.

3. Describe each step to reproduce the issue or behaviour.

Setup a subshop with a different domain and show the preview of an article in this subshop. you are no longer able to visit the main shop.

This bug works only over https!

4. Please link to the relevant issues (if any).

5. Which documentation changes (if any) need to be made because of this PR?

6. Checklist

  • I have written tests and verified that they fail without my change
  • I have squashed any insignificant commits
  • This change has comments for package types, values, functions, and non-obvious lines of code
  • I have read the contribution requirements and fulfil them.

Copy link

Warnings
⚠️ The Pull Request doesn't contain any changes to the Upgrade file

@mitelg
Copy link
Contributor

mitelg commented Jul 25, 2024

this looks like a "hacky" workaround, and not really like a solution to the problem 😬
Is there no other possibility? couldn't this cookie be deleted once it is read? 🤔

@Dominikrt
Copy link
Contributor Author

Hi @mitelg ,
I do it this way, to keep compatibility for 3rd party solutions. I don't know, if this cookie is needed somewhere else.

here is a solution with clearing the cookie after reading it. But i think this is a breaking change.

@mitelg
Copy link
Contributor

mitelg commented Jul 29, 2024

I would have to dig deeper into the code, but if I remember correctly the cookie is only used, to select the current shop from the cookie. I hope, that no one is relying on it 🙈

your change is also breaking, just after 30 seconds 😁

@mitelg
Copy link
Contributor

mitelg commented Aug 26, 2024

@Dominikrt any news on this?

@Dominikrt
Copy link
Contributor Author

Hi @mitelg,
i pushed now the other branch in this, I think this is a breaking change!

But I don't know if there is a better way doing this.

@@ -317,6 +319,7 @@ protected function getShopByRequest(Request $request)

if ($shop === null && $request->getCookie('shop') !== null) {
$shop = $repository->getActiveById($request->getCookie('shop'));
$response->headers->clearCookie('shop');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearing the cookie here, would also affect the next if condition, if I see that correctly.

Before your change, the if condition could also be met, if this condition was met before.

With your change this is no longer possible.

A test of the \Shopware_Plugins_Core_Router_Bootstrap::onRouteStartup method in \Shopware\Tests\Functional\Plugins\Core\Router\BootstrapTest would be really nice, to ensure, that we do not break stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, the main problem is, I don't understand the reason of this cookie.

I tested this change on my server and I still get redirect after the first attempt, trying to visit the start page. Only on the second attempt is the Cookie gone and I can visit the primary shop again.

But I don't know, if there is a case that the cookie is needed to redirect to the right shop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the cookie at all then? 🤔

unfortunately I cannot reproduce this locally. you wrote this only occurs via HTTPS? 🤔 If I am using only HTTP, the cookie is not set at all 🤔

@mitelg
Copy link
Contributor

mitelg commented Aug 27, 2024

@Dominikrt thanks! this looks better to me, but still a little question mark 😁

$pluginBootstrap->onRouteStartup($args);

static::assertSame(Response::HTTP_OK, $response->getStatusCode());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitelg, here 2 options for testing this, I'm not happy with both solutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants