Jump to content

bug in resetAddressCache - address related issue


Recommended Posts

I think I have found a bug, that might have annoyed many people with diverse error messages on adding address via OPC ajax
Please look at the below and notice how its not using the same key value
	public static function customerHasAddress($id_customer, $id_address)
		$key = (int)$id_customer.'-'.(int)$id_address;
		if (!array_key_exists($key, self::$_customerHasAddress))
			self::$_customerHasAddress[$key] = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
			SELECT `id_address`
			FROM `'._DB_PREFIX_.'address`
			WHERE `id_customer` = '.(int)$id_customer.'
			AND `id_address` = '.(int)$id_address.'
			AND `deleted` = 0');
		return self::$_customerHasAddress[$key];

	public static function resetAddressCache($id_customer)
		if (array_key_exists($id_customer, self::$_customerHasAddress))

$_customerHasAddress[$key] (which is actually $id_customer.'-'.$id_address;)
Here is my workaround (it might not be perfect(fast enough), but it works)
    public static function resetAddressCache($id_customer)
        // lets reset (could be improved by loopin and removing all keys beginning with $id_customer.'-')
        self::$_customerHasAddress = array();

Here is my newest and best attempt

    public static function resetAddressCache($id_customer)
        foreach (self::$_customerHasAddress as $key => $value) {
            list($firstPart) = explode('-', $key);
            if ((int)$firstPart == $id_customer)

Hope it helps
and please post if you have a better fix

Edited by michaelhjulskov (see edit history)
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...