Search code examples
opencart

Customer Logged in condition is not working in Hostgator server


I am developing OpenCart 3.0.8 Website. I want to restrict to show cart page without customer login. I have added the following condition in catalog/controller/checkout/cart.php to do that.

    if($this->customer->isLogged())  {
        if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) {......
    }
    else
    {
        $this->response->redirect($this->url->link('account/login'));
    }

In my system , it is working good. Once I click without log in it moving to login page otherwise it showing cart. But in hostgator, when I click cart it goes to accounts page even after logged in. This looks weird to me.

I have checked with Hostgator support, they said all the required extensions are installed correctly.

Curl, ZIP, Zlib, GD Library, Mcrypt, Mbstrings, Xml

In both local and hostgator server, PHP 7.4 release is used. There is no error logs appearing. Can anyone please suggest any possibilities to fix this error?

Thanks


Solution

  • Yes. Found the answer. Instead of just using if($this->customer->isLogged()) ,change the code as below.

    if (!$this->customer->isLogged()) {
        $this->session->data['redirect'] = $this->url->link('checkout/cart', '', true);
    
        $this->response->redirect($this->url->link('account/login', '', true));
    }
    

    Thanks