fransjaeger Posted February 7, 2015 Share Posted February 7, 2015 (edited) Hi 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)) unset(self::$_customerHasAddress[$id_customer]); } $_customerHasAddress[$id_customer] vs $_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) unset(self::$_customerHasAddress[$key]); } } Hope it helpsand please post if you have a better fix Edited February 7, 2015 by michaelhjulskov (see edit history) 1 Link to comment Share on other sites More sharing options...
fransjaeger Posted February 7, 2015 Author Share Posted February 7, 2015 (edited) If you like this, please create a link that points to www.dyrefoder.dk THANKS ;o) Edited February 7, 2015 by michaelhjulskov (see edit history) Link to comment Share on other sites More sharing options...
fransjaeger Posted February 9, 2015 Author Share Posted February 9, 2015 I made a pull request here https://github.com/PrestaShop/PrestaShop/pull/2466 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now