Hey! Hola que tal amigos de Junior a Senior el día de hoy les vengo con un nuevo tutorial, el cual consta de redirigir a nuestros nuevos usuarios de Prestashop, a una url personalizada despues de que estos se hayan registrado.

Este problema me surgió en la versión 1.7.7.5 de Prestashop, ya que al momento de que un usuario realizaba su registro fuera de la pasarela de pago, esta los redireccionaba a la pagina de inicio. Lo cual no era lo correcto y más si queríamos medir el trafico web y de donde provenían estos registros.

Por lo cual me di a la tarea de investigar un poco el cómo hacerlo, pero hay muy poca información acerca de esto. Pero entre tanto buscar encontré una solución, tal vez no sea la más correcta pero soluciono el problema. Y hasta el momento de estar haciendo pruebas no he encontrado algún error.(recuerden siempre hacer un override jejeje).

A continuación mostrare el codigo y la ruta para que ustedes puedan hacer los cambios correspondientes:

Ruta: /controllers/front/AuthController.php

A continuación deberán reemplazar o escribir el siguiente codigo para poder hacer el redireccionamiento, no entrare mucho en detalle, pero si tienen dudas no duden en comentar:

class AuthControllerCore extends FrontController
{
    public $ssl = true;
    public $php_self = 'authentication';
    public $auth = false;

    public function checkAccess()
    {
        if ($this->context->customer->isLogged() && !$this->ajax) {
            $this->redirect_after = ($this->authRedirection) ? urlencode($this->authRedirection) : 'my-account';
            $this->redirect();
        }

        return parent::checkAccess();
    }

    public function initContent()
    {
        $should_redirect = false;
        $new_page_redirect = false;

        if (Tools::isSubmit('submitCreate') || Tools::isSubmit('create_account')) {
            $register_form = $this
                ->makeCustomerForm()
                ->setGuestAllowed(false)
                ->fillWith(Tools::getAllValues());

            if (Tools::isSubmit('submitCreate')) {
                $hookResult = array_reduce(
                    Hook::exec('actionSubmitAccountBefore', [], null, true),
                    function ($carry, $item) {
                        return $carry && $item;
                    },
                    true
                );
                if ($hookResult && $register_form->submit()) {
                    //$should_redirect = true;
                    $new_page_redirect = true;
                }
            }

            $this->context->smarty->assign([
                'register_form' => $register_form->getProxy(),
                'hook_create_account_top' => Hook::exec('displayCustomerAccountFormTop'),
            ]);
            $this->setTemplate('customer/registration');
        } else {
            $login_form = $this->makeLoginForm()->fillWith(
                Tools::getAllValues()
            );

            if (Tools::isSubmit('submitLogin')) {
                if ($login_form->submit()) {
                    $should_redirect = true;
                }
            }

            $this->context->smarty->assign([
                'login_form' => $login_form->getProxy(),
            ]);
            $this->setTemplate('customer/authentication');
        }

        parent::initContent();

        if ($should_redirect && !$this->ajax) {
            $back = urldecode(Tools::getValue('back'));

            if (Tools::urlBelongsToShop($back)) {
                // Checks to see if "back" is a fully qualified
                // URL that is on OUR domain, with the right protocol
                return $this->redirectWithNotifications($back);
            }

            // Well we're not redirecting to a URL,
            // so...
            if ($this->authRedirection) {
                // We may need to go there if defined
                return $this->redirectWithNotifications($this->authRedirection);
            }

            // go home
            return $this->redirectWithNotifications(__PS_BASE_URI__);
        }
        if ($new_page_redirect && !$this->ajax) {
            $back = urldecode(Tools::getValue('back'));
            if (Tools::urlBelongsToShop($back)) {
                return $this->redirectWithNotifications('https://dejuniorasenior.com.com/content/13-gracias-por-registrarte');
            }
            if ($this->authRedirection) {
                return $this->redirectWithNotifications($this->authRedirection);
            }

            // go home
            return $this->redirectWithNotifications(__PS_BASE_URI__);
        }
    }

    public function getBreadcrumbLinks()
    {
        $breadcrumb = parent::getBreadcrumbLinks();

        if (Tools::isSubmit('submitCreate') || Tools::isSubmit('create_account')) {
            $breadcrumb['links'][] = [
                'title' => $this->trans('Create an account', [], 'Shop.Theme.Customeraccount'),
                'url' => $this->context->link->getPageLink('authentication'),
            ];
        } else {
            $breadcrumb['links'][] = [
                'title' => $this->trans('Log in to your account', [], 'Shop.Theme.Customeraccount'),
                'url' => $this->context->link->getPageLink('authentication'),
            ];
        }

        return $breadcrumb;
    }
}

Una vez realizando este cambio, los nuevos usuarios serán redirigiros al sitio web que ustedes coloquen, por defecto.

Espero les haya servido de algo esta breve información, si tienen dudas u otras maneras de hacerlo pueden mostrárnoslo en los comentarios, esto ayudara a qué todos crezcamos y resolvamos nuestros problemas de forma rápida y sencilla.

Y sin mas que decir por el momento, nos vemos y espero nos apoyen con sus opiniones y comentarios, saludos.

Leave a reply

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

You may also like