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
CartLoadRoute is called with unauthenticated SalesChannelContext via CacheResponseSubscriber after LoginRoute #3666
Comments
Maybe we need to move this into the Login Route? 🤔 shopware/src/Storefront/Controller/AuthController.php Lines 164 to 176 in 3ba890a
|
I can confirm, that it work with a RouteDecorator for the LoginRoute #[Route(path: '/store-api/account/login', name: 'store-api.account.login', methods: ['POST'])]
public function login(RequestDataBag $data, SalesChannelContext $context): ContextTokenResponse
{
$result = $this->decorated->login($data, $context);
$newContext = $this->salesChannelContextService->get(
new SalesChannelContextServiceParameters(
$context->getSalesChannelId(),
$result->getToken(),
$context->getLanguageId(),
$context->getCurrencyId(),
$context->getDomainId(),
$context->getContext()
)
);
$request = $this->requestStack->getCurrentRequest();
$request->attributes->set(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT, $newContext);
return $result;
} One thing I don't like is the fact that I had to inject the RequestStack into the decorator because the If desired, I can work on a PR in the next few days to get this fix into the original route and get rid of the decorator? |
sounds good :) I would also check that getCurrentRequest is not null, before using it |
PHP Version
8.3
Shopware Version
6.5.8.8
Expected behaviour
After the initial login (when there's no entry for a specific customer in sales_channel_api_context), the SalesChannelContext passed to
CartLoadRoute->load()
fromCacheResponseSubscriber->setResponseCache()
should be "re-fetched"/"rebuilt" before calling $cart = $this->cartService->getCart($context->getToken(), $context); to ensure that the correct authenticated SalesChannelContext (with customer and customerId correctly set) is available in CartLoadRoute->load().Maybe it could also be feasible to relocate the check below, preceding the call to
$this->cartService->getCart()
, but I'm uncertain about the potential performance implications this may entail.Actual behaviour
Currently, after the initial login (when there's no entry in sales_channel_api_context), the SalesChannelContext passed to CartLoadRoute->load() from CacheResponseSubscriber->setResponseCache() does not include information about the newly logged-in customer. From the second login onwards (when an entry in sales_channel_api_context exists), the passed SalesChannelContext contains the accurate information about the currently logged-in customer.
How to reproduce
sales_channel_api_context
for a specific customer.$context->ensureLoggedIn(false)
to a RouteDecorator forstore-api.checkout.cart.read
.store-api.account.login
.store-api.account.login
(because of the missingcustomer
andcustomerId
).The text was updated successfully, but these errors were encountered: