Posts Tagged ‘ prices

PrestaShop wholesale mode fix (force catalog mode when uses is logged in)

After searching all of Google’s entries for how to make PrestaShop hide it’s prices when the user is not logged on, which is the common behaviour for dealer/wholesale stores (where by non-registered users do not see prices) I was rather disappointed by the variety of the non-elegant solutions out there.

Also, there are some paid solutions, but what’s the point of paying 50 bucks for open source applications?

Here’s my solution, it works like a charm and is a very easy fix!

In classes\Configuration.php (around line 114) it looks like this

static public function get($key, $id_lang = NULL)
{
	if ($id_lang AND isset(self::$_CONF_LANG[(int)$id_lang][$key]))
		return self::$_CONF_LANG[(int)$id_lang][$key];
	elseif (is_array(self::$_CONF) AND key_exists($key, self::$_CONF))
		return self::$_CONF[$key];
	return false;
}

change it to this:

static public function get($key, $id_lang = NULL)
{
	//Grab access to the $cookie which is already loaded in the FrontController as global $cookie;
	global $cookie;
	if ($id_lang AND isset(self::$_CONF_LANG[(int)$id_lang][$key]))
		return self::$_CONF_LANG[(int)$id_lang][$key];
	elseif (is_array(self::$_CONF) AND key_exists($key, self::$_CONF))
		//If the system is trying to find out if Catalog Mode is ON, then return the configuration setting,
		//but override it with the user logon status
		if($key == 'PS_CATALOG_MODE')
		{
			return !$cookie->logged || self::$_CONF[$key];
		}
		else
		{
			return self::$_CONF[$key];
		}
	return false;
}

Essentially, I wanted to force the system to display the “Catalog Mode” when the user is not logged in, and to turn this off when he is logged in. Instead of going through every call that checks if it’s on or off, we override the call to also check if the user is logged in.

I can guarantee this works for v1.4.3.0 and the code for the current version 1.4.8.2 (at the time of this post) has not changed, so it should work there.

If you have any difficulties with this, let me know with a comment below!