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

Multiple channels cannot be created without a default language defined in services.yaml (redirect to homepage at second channel) #566

Open
adamterepora opened this issue Dec 4, 2024 · 0 comments

Comments

@adamterepora
Copy link

adamterepora commented Dec 4, 2024

I encountered a problem in which I have two channels:

  1. Polish
  2. English

Polish channel contains only polish lang, english has english only.

In the services.yaml file the default language is defined as pl_EN.
When I go to the english channel and try to go to payment, I am redirected to the home page.

The reason is routing configuration:

<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
    <route id="payum_capture_do_session" path="/payment/capture/session-token">
        <default key="_controller">Payum\Bundle\PayumBundle\Controller\CaptureController::doSessionTokenAction</default>
    </route>

    <route id="payum_capture_do" path="/payment/capture/{payum_token}">
        <default key="_controller">Payum\Bundle\PayumBundle\Controller\CaptureController::doAction</default>
    </route>
</routes>

etc. for any other route in bundle.

Since in Sylius ShopBundle we have a method:

final class NonChannelLocaleListener
{
    ...

    /**
     * @throws NotFoundHttpException
     */
    public function restrictRequestLocale(RequestEvent $event): void
    {
        ...

        $requestLocale = $request->getLocale();
        if (!in_array($requestLocale, $this->channelBasedLocaleProvider->getAvailableLocalesCodes(), true)) {
            $event->setResponse(
                new RedirectResponse(
                    $this->router->generate(
                        'sylius_shop_homepage',
                        ['_locale' => $this->channelBasedLocaleProvider->getDefaultLocaleCode()],
                    ),
                ),
            );
        }
    }
}

everytime we are redirecting to payum routes, $request->getLocale() provides invalid locale, which causes redirect to homepage instead of payment proceeding.

Quick solution for this is to add /{_locale} in paths (system will automatically provide this locale from previous actions):

<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
    <route id="payum_capture_do_session" path="/{_locale}/payment/capture/session-token">
        <default key="_controller">Payum\Bundle\PayumBundle\Controller\CaptureController::doSessionTokenAction</default>
    </route>

    <route id="payum_capture_do" path="/{_locale}/payment/capture/{payum_token}">
        <default key="_controller">Payum\Bundle\PayumBundle\Controller\CaptureController::doAction</default>
    </route>
</routes>

for all routes included.

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

No branches or pull requests

1 participant