What are the Slack Archives?

Itโ€™s a history of our time together in the Slack Community! Thereโ€™s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you wonโ€™t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hi everyone! I would like to display a dedicated screen for new users where they can configure some

martin
martin Spryker Solution Partner Posts: 49 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

Hi everyone!

I would like to display a dedicated screen for new users where they can configure some essential components in the beginning.

I was thinking to set a cookie if the user has already seen the introduction screen and depending on that cookie I either redirect all requests to /introduction or just do nothing in case the cookie is set. My first attempt was to look into RouterDependencyProvider and manipulate the routes depending on the cookie, but I think it's a dead end.

Any suggestions how I could implement such a route manipulation?

Comments

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet
    edited May 2021

    How about doing conditional redirects in Controllers based on the presence of the cookie?

    class HomeController extends AbstractController
    {
        /**
         * @param Request $request
         * @return View|RedirectResponse
         */
        public function indexAction(Request $request)
        {
            if (!$request->cookies->get('foo')->has('bar')) {
                return $this->redirectResponseInternal('introduction');
            }
    
            ...
        }
    }
    
    
    
    class IntroductionController extends AbstractController
    {
        /**
         * @param Request $request
         * @return View|RedirectResponse
         */
        public function indexAction(Request $request)
        {
            if ($request->cookies->get('foo')->has('bar')) {
                $this->addInfoMessage('You\'ve already passed the introduction');
    
                return $this->redirectResponseInternal('home');
            }
    
            ...
    
            $request->cookies->set('foo', 'bar');
        }
    }
    

    Will your user be browsing as a guest or logged in? If the latter, I'd suggest to not use a cookie, but flag the customer account in the database instead.

  • martin
    martin Spryker Solution Partner Posts: 49 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    Hi, thanks for your response!

    I was also thinking about such an implementation but this has the drawback that new users must always pass the Homepage and if they would enter another URL (e.g. a promotion link), they would not see the introduction screen.

    But since this only applies to first-page visits I think this might be fine. Thank you for also pointing out to store such information in the customer account table.

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    Okay, then you might check the RouterDependencyProvider->getRouterPlugins(). Maybe you can extend the YvesRouterPlugin to add your cookie handling inside the Router. The Router implementation is also having some plugin processing inside, maybe you can use it for your needs.
    vendor/spryker/router/src/Spryker/Yves/Router/Router/Router.php

  • martin
    martin Spryker Solution Partner Posts: 49 ๐Ÿง‘๐Ÿปโ€๐Ÿš€ - Cadet

    Thanks for your tip, I'll look into it!