partheeban
partheeban

Reputation: 1

How to Solve This Error In Prestashop

Code:

public function init()
{
   global $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files;

   if(!session_id()){
      if(!isset($_SESSION)){
         session_start();
      }
   }

   $cookie->id_cart=$_SESSION['pj_punchout_id'];

   if (self::$initialized)
      return;

   self::$initialized = true;

   $css_files = array();
   $js_files = array();

Error:

Strict Standards: Creating default object from empty value in C:\xampp\htdocs\pjwebstoredev\classes\FrontController.php on line 82

Upvotes: 0

Views: 4268

Answers (1)

Paul Campbell
Paul Campbell

Reputation: 1145

I'm assuming that you're using Prestashop v1.4. The main problem I can see is that you've edited one of the core files, so most bets are off for the ability to support your code in the future. If you want to cleanly modify the behaviour of the core classes, then you should create an override called /override/classes/FrontController.php with the following contents:

class FrontController extends FrontControllerCore
{
    function init()
    {
        // Your additional custom init code goes here
        parent::init();
        // And/or additional custom init code goes here
    }
}

That's not the fundamental problems though, as we get to the next stage. The error you're seeing is because you are tring to use the global variable $cookie, but at a point in time before the variable is set to anything meaningful (the global cookie variable is actually initialised later in the very function you were modifying). Since you need to manipulate the cookie properties then you could try creating a temporary cookie object, use it to manipulate the user's cookie, then call the core code e.g.

class FrontController extends FrontControllerCore
{
    function init()
    {
        if ( !session_id() ) {
            if( !isset($_SESSION) ) {
              session_start();
            }
        }
        $cookieLifetime = (time() + (((int)Configuration::get('PS_COOKIE_LIFETIME_FO') > 0 ? (int)Configuration::get('PS_COOKIE_LIFETIME_FO') : 1)* 3600));
        $cookie = new Cookie('ps', '', $cookieLifetime);
        $cookie->id_cart=$_SESSION['pj_punchout_id'];

        parent::init();
    }
}

Upvotes: 2

Related Questions