skip to Main Content

How can I send back the client who has just created their account on the home page by postponing the validation of their account on PrestaShop 8.0.4?

I work on a PrestaShop project whose owner wanted it to be B2B and validated after verifying the company identification number. My issue is that even after the account is created, it remains stuck on the form page. From my research, I’ve found that if the default account is enabled, it logs the user in and redirects them to the home page. My question is, how can we modify this process to redirect the user to the home page as a guest, allowing them to browse while waiting for their account to be validated?

2

Answers


  1. Chosen as BEST ANSWER

    Thank you for your method I was able to redirect the customer to home store . But in addition to bringing it home I wanted to display a small banner on the house to inform the user that their account is being validated. so I created a variable $just_registered = true that I pass to the index to check it in index.tpl of my theme but it doesn't work

    public function hookActionCustomerAccountAdd(array $params)
        {
            $customer = $params['newCustomer'];
            $customer->active = false;
            $customer->save();
            $this->context->customer->logout();
    
            $just_registered = true;
            var_dump($just_registered);
        
            $url = $this->context->link->getPageLink('index', true, null, array('just_registered' => $just_registered));
        
        }`
    
       `{block name='page_content_container'}
      <section id="content" class="page-home">
        {hook h='displaySliderContainerWidth'}
        {hook h='displayHomeBefore'}
    
        {block name='page_content_top'}{/block}
    
        {block name='page_content'}
          {block name='hook_home'}
            {$HOOK_HOME nofilter}
          {/block}
        {/block}
    
        {**hook h='displayHomeAfter'**}
        {if isset($just_registered) && $just_registered == true}
          <style>
            .registration-banner {
            position: fixed;
            top: 190px;
            right: 10px;
            background-color: rgba(0, 128, 0, 0.5);
            border: none;
            padding: 10px;
            width: 40%;
            z-index: 9999;
            }
            .registration-banner h1 {
              font-size: 21px;
              color: rgba(255, 255, 255, 1);
              margin: 0;
            }
          </style>
          <div class="registration-banner">
            <h1>
              Merci pour votre inscription ! Votre compte sera activé sous peu.
            </h1>
          </div>
          <script>
            setTimeout(function() {
                document.querySelector('.registration-banner').style.display = 'none';
            }, 5000);
          </script>
        {/if}
      </section>
    {/block}
    `
    

  2. You need to create a module to be able to do it.
    You also need to use the hook hookActionCustomerAccountAdd

    Here is an example:

    public function hookActionCustomerAccountAdd(array $params)
    {
        /** @var Customer $customer */
        $customer = $params['newCustomer'];
        $customer->active = false;
        $customer->save();
        $this->context->customer->logout();
    
        $url = $this->context->link->getModuleLink('privateshop', 'accountpending');
    
        Tools::redirect($url);
    }
    

    Basically, you need to hook to the event hookActionCustomerAccountAdd, set the customer status as inactive and logout them.
    Then redirect to a custom page with some message saying that an admin confirmation is needed to confirm the account.
    Don’t forget to register the hook in the public function install() of your module

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search