diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Config.php b/app/code/community/Algolia/Algoliasearch/Helper/Config.php index 3e9c0e1f..64cdfbd5 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Config.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Config.php @@ -236,7 +236,12 @@ public function isPartialUpdateEnabled($storeId = null) public function getAutocompleteSections($storeId = null) { - $attrs = unserialize(Mage::getStoreConfig(self::AUTOCOMPLETE_SECTIONS, $storeId)); + $attrs = array(); + $config = Mage::getStoreConfig(self::AUTOCOMPLETE_SECTIONS, $storeId); + + if ($config !== null && $config !== '') { + $attrs = \Zend_Serializer::unserialize($config); + } if (is_array($attrs)) { return array_values($attrs); @@ -358,7 +363,12 @@ public function getInstantSelector($storeId = null) public function getExcludedPages($storeId = null) { - $attrs = unserialize(Mage::getStoreConfig(self::EXCLUDED_PAGES, $storeId)); + $attrs = array(); + $config = Mage::getStoreConfig(self::EXCLUDED_PAGES, $storeId); + + if ($config !== null && $config !== '') { + $attrs = \Zend_Serializer::unserialize($config); + } if (is_array($attrs)) { return $attrs; @@ -382,7 +392,12 @@ public function getSortingIndices($storeId = null) /** @var Algolia_Algoliasearch_Helper_Entity_Producthelper $product_helper */ $product_helper = Mage::helper('algoliasearch/entity_producthelper'); - $attrs = unserialize(Mage::getStoreConfig(self::SORTING_INDICES, $storeId)); + $attrs = array(); + $config = Mage::getStoreConfig(self::SORTING_INDICES, $storeId); + + if ($config !== null && $config !== '') { + $attrs = \Zend_Serializer::unserialize($config); + } /** @var Mage_Customer_Model_Session $customerSession */ $customerSession = Mage::getSingleton('customer/session'); @@ -503,7 +518,12 @@ public function getAttributesToRetrieve($groupId, $store) public function getCategoryAdditionalAttributes($storeId = null) { - $attrs = unserialize(Mage::getStoreConfig(self::CATEGORY_ATTRIBUTES, $storeId)); + $attrs = array(); + $config = Mage::getStoreConfig(self::CATEGORY_ATTRIBUTES, $storeId); + + if ($config !== null && $config !== '') { + $attrs = \Zend_Serializer::unserialize($config); + } if (is_array($attrs)) { return $attrs; @@ -514,20 +534,41 @@ public function getCategoryAdditionalAttributes($storeId = null) public function getProductAdditionalAttributes($storeId = null) { - $attributes = unserialize(Mage::getStoreConfig(self::PRODUCT_ATTRIBUTES, $storeId)); + $attributes = array(); + $config = Mage::getStoreConfig(self::PRODUCT_ATTRIBUTES, $storeId); + + if ($config !== null && $config !== '') { + $attributes = \Zend_Serializer::unserialize($config); + } + + $facets = array(); + $config = Mage::getStoreConfig(self::FACETS, $storeId); - $facets = unserialize(Mage::getStoreConfig(self::FACETS, $storeId)); + if ($config !== null && $config !== '') { + $facets = \Zend_Serializer::unserialize($config); + } $attributes = $this->addIndexableAttributes($attributes, $facets, '0'); - $sorts = unserialize(Mage::getStoreConfig(self::SORTING_INDICES, $storeId)); + $sorts = array(); + $config = Mage::getStoreConfig(self::SORTING_INDICES, $storeId); + + if ($config !== null && $config !== '') { + $sorts = \Zend_Serializer::unserialize($config); + } $attributes = $this->addIndexableAttributes($attributes, $sorts, '0'); - $customRankings = unserialize(Mage::getStoreConfig(self::PRODUCT_CUSTOM_RANKING, $storeId)); + $customRankings = array(); + $config = Mage::getStoreConfig(self::PRODUCT_CUSTOM_RANKING, $storeId); + + if ($config !== null && $config !== '') { + $customRankings = \Zend_Serializer::unserialize($config); + } $customRankings = array_filter($customRankings, function ($customRanking) { return $customRanking['attribute'] != 'custom_attribute'; }); $attributes = $this->addIndexableAttributes($attributes, $customRankings, '0', '0'); + if (is_array($attributes)) { return $attributes; } @@ -537,7 +578,13 @@ public function getProductAdditionalAttributes($storeId = null) public function getFacets($storeId = null) { - $attrs = unserialize(Mage::getStoreConfig(self::FACETS, $storeId)); + $attrs = array(); + $config = Mage::getStoreConfig(self::FACETS, $storeId); + + if ($config !== null && $config !== '') { + $attrs = \Zend_Serializer::unserialize($config); + } + foreach ($attrs as &$attr) { if ($attr['type'] == 'other') { $attr['type'] = $attr['other_type']; @@ -660,7 +707,12 @@ public function isEnabledSynonyms($storeId = null) public function getSynonyms($storeId = null) { - $synonyms = unserialize(Mage::getStoreConfig(self::SYNONYMS, $storeId)); + $synonyms = array(); + $config = Mage::getStoreConfig(self::SYNONYMS, $storeId); + + if ($config !== null && $config !== '') { + $synonyms = \Zend_Serializer::unserialize($config); + } if (is_array($synonyms)) { return $synonyms; @@ -671,7 +723,12 @@ public function getSynonyms($storeId = null) public function getOnewaySynonyms($storeId = null) { - $onewaySynonyms = unserialize(Mage::getStoreConfig(self::ONEWAY_SYNONYMS, $storeId)); + $onewaySynonyms = array(); + $config = Mage::getStoreConfig(self::ONEWAY_SYNONYMS, $storeId); + + if ($config !== null && $config !== '') { + $onewaySynonyms = \Zend_Serializer::unserialize($config); + } if (is_array($onewaySynonyms)) { return $onewaySynonyms; @@ -734,7 +791,11 @@ public function getBackendRenderingDisplayMode($storeId = null) public function getNonCastableAttributes($storeId = null) { $nonCastableAttributes = array(); - $config = unserialize(Mage::getStoreConfig(self::NON_CASTABLE_ATTRIBUTES, $storeId)); + $config = Mage::getStoreConfig(self::NON_CASTABLE_ATTRIBUTES, $storeId); + + if ($config !== null && $config !== '') { + $config = \Zend_Serializer::unserialize($config); + } if (is_array($config)) { foreach ($config as $attributeData) { @@ -749,7 +810,12 @@ public function getNonCastableAttributes($storeId = null) private function getCustomRanking($configName, $storeId = null) { - $attrs = unserialize(Mage::getStoreConfig($configName, $storeId)); + $attrs = array(); + $config = Mage::getStoreConfig($configName, $storeId); + + if ($config !== null && $config !== '') { + $attrs = \Zend_Serializer::unserialize($config); + } if (is_array($attrs)) { foreach ($attrs as $index => $attr) { diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Suggestionhelper.php b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Suggestionhelper.php index 83ca723e..1754472d 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Suggestionhelper.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Suggestionhelper.php @@ -51,7 +51,7 @@ public function getPopularQueries($storeId) // load from cache if we can $cachedPopularQueries = Mage::app()->loadCache($this->_popularQueriesCacheId); if ($cachedPopularQueries) { - $this->_popularQueries = unserialize($cachedPopularQueries); + $this->_popularQueries = \Zend_Serializer::unserialize((string) $cachedPopularQueries); } else { $collection = Mage::getResourceModel('catalogsearch/query_collection'); $collection->getSelect()->where('num_results >= '.$this->config->getMinNumberOfResults().' AND popularity >= '.$this->config->getMinPopularity().' AND query_text != "__empty__"'); @@ -77,7 +77,7 @@ public function getPopularQueries($storeId) $this->_popularQueries = array_slice($suggestions, 0, 9); try { //save to cache - $cacheContent = serialize($this->_popularQueries); + $cacheContent = \Zend_Serializer::serialize($this->_popularQueries); $tags = array( Mage_CatalogSearch_Model_Query::CACHE_TAG, ); diff --git a/app/code/community/Algolia/Algoliasearch/Model/System/Config/Backend/Serialized/Array.php b/app/code/community/Algolia/Algoliasearch/Model/System/Config/Backend/Serialized/Array.php index eb54e184..84658f35 100644 --- a/app/code/community/Algolia/Algoliasearch/Model/System/Config/Backend/Serialized/Array.php +++ b/app/code/community/Algolia/Algoliasearch/Model/System/Config/Backend/Serialized/Array.php @@ -9,7 +9,7 @@ protected function _afterLoad() if ($helper->isX3Version()) { if (!is_array($this->getValue())) { $value = $this->getValue(); - $this->setValue(empty($value) ? false : unserialize($value)); + $this->setValue(empty($value) ? false : \Zend_Serializer::unserialize((string) $value)); } return;