diff --git a/FACTFinder/Adapter/AbstractAdapter.php b/FACTFinder/Adapter/AbstractAdapter.php index 2efebaa..cadbe74 100644 --- a/FACTFinder/Adapter/AbstractAdapter.php +++ b/FACTFinder/Adapter/AbstractAdapter.php @@ -191,4 +191,9 @@ protected function convertServerQueryToClientUrl($query) return $this->urlBuilder->generateUrl($parameters); } + + protected function isValidResponse($jsonData) + { + return (!empty($jsonData) && !isset($jsonData['error'])); + } } diff --git a/FACTFinder/Adapter/Compare.php b/FACTFinder/Adapter/Compare.php index d35b518..2d6031c 100644 --- a/FACTFinder/Adapter/Compare.php +++ b/FACTFinder/Adapter/Compare.php @@ -114,13 +114,15 @@ private function createComparableAttributes() else { $jsonData = $this->getResponseContent(); - foreach($jsonData['attributes'] as $attributeData) + if (parent::isValidResponse($jsonData)) { - $name = $attributeData['attributeName']; - $attributes[$name] = $attributeData['different']; + foreach($jsonData['attributes'] as $attributeData) + { + $name = $attributeData['attributeName']; + $attributes[$name] = $attributeData['different']; + } } } - return $attributes; } @@ -157,15 +159,18 @@ private function createComparedRecords() { $position = 1; $jsonData = $this->getResponseContent(); - foreach($jsonData['records'] as $recordData) + if (parent::isValidResponse($jsonData)) { - $records[] = FF::getInstance( - 'Data\Record', - (string)$recordData['id'], - $recordData['record'], - 100.0, - $position++ - ); + foreach($jsonData['records'] as $recordData) + { + $records[] = FF::getInstance( + 'Data\Record', + (string)$recordData['id'], + $recordData['record'], + 100.0, + $position++ + ); + } } } diff --git a/FACTFinder/Adapter/ProductCampaign.php b/FACTFinder/Adapter/ProductCampaign.php index adef241..f7ad2dc 100644 --- a/FACTFinder/Adapter/ProductCampaign.php +++ b/FACTFinder/Adapter/ProductCampaign.php @@ -147,23 +147,27 @@ private function createCampaigns() { // Use only the first product ID $productIDs = $this->parameters['productNumber']; - if (is_array($productIDs)) + if (is_array($productIDs) && !empty($productIDs)) + { $this->parameters['productNumber'] = $productIDs[0]; - + } $jsonData = $this->getResponseContent(); // Restore IDs $this->parameters['productNumber'] = $productIDs; } - foreach ($jsonData as $campaignData) { - $campaign = $this->createEmptyCampaignObject($campaignData); + if(parent::isValidResponse($jsonData)) + { + foreach ($jsonData as $campaignData) { + $campaign = $this->createEmptyCampaignObject($campaignData); - $this->fillCampaignWithFeedback($campaign, $campaignData); - $this->fillCampaignWithPushedProducts($campaign, $campaignData); + $this->fillCampaignWithFeedback($campaign, $campaignData); + $this->fillCampaignWithPushedProducts($campaign, $campaignData); - $campaigns[] = $campaign; - } + $campaigns[] = $campaign; + } + } } $campaignIterator = FF::getInstance( diff --git a/FACTFinder/Adapter/Recommendation.php b/FACTFinder/Adapter/Recommendation.php index 726b0d1..b4b7768 100644 --- a/FACTFinder/Adapter/Recommendation.php +++ b/FACTFinder/Adapter/Recommendation.php @@ -145,17 +145,20 @@ private function createRecommendations() else { $recommenderData = $this->getResponseContent(); - if (isset($recommenderData['resultRecords'])) + if (parent::isValidResponse($recommenderData)) { - $recommenderData = $recommenderData['resultRecords']; - } - $position = 1; - foreach($recommenderData as $recordData) - { - if ($this->idsOnly) - $records[] = $this->createSparseRecord($recordData); - else - $records[] = $this->createRecord($recordData, $position++); + if (isset($recommenderData['resultRecords'])) + { + $recommenderData = $recommenderData['resultRecords']; + } + $position = 1; + foreach($recommenderData as $recordData) + { + if ($this->idsOnly) + $records[] = $this->createSparseRecord($recordData); + else + $records[] = $this->createRecord($recordData, $position++); + } } } diff --git a/FACTFinder/Adapter/Search.php b/FACTFinder/Adapter/Search.php index 434dd58..8f6e6d7 100755 --- a/FACTFinder/Adapter/Search.php +++ b/FACTFinder/Adapter/Search.php @@ -139,7 +139,7 @@ private function createResult() $jsonData = $this->getResponseContent(); - if (isset($jsonData['searchResult'])) { + if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult'])) { $searchResultData = $jsonData['searchResult']; $refKey = $searchResultData['refKey']; @@ -192,7 +192,7 @@ private function createSingleWordSearch() $singleWordSearch = array(); $jsonData = $this->getResponseContent(); - if (!empty($jsonData['searchResult']['singleWordResults'])) + if (parent::isValidResponse($jsonData) && !empty($jsonData['searchResult']['singleWordResults'])) { foreach ($jsonData['searchResult']['singleWordResults'] as $swsData) { @@ -233,7 +233,7 @@ public function getStatus() $status = $searchStatusEnum::NoResult(); $jsonData = $this->getResponseContent(); - if (isset($jsonData['searchResult'])) + if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult'])) { switch($jsonData['searchResult']['resultStatus']) { @@ -257,7 +257,7 @@ public function getArticleNumberStatus() $status = $articleNumberSearchStatusEnum::IsNoArticleNumberSearch(); $jsonData = $this->getResponseContent(); - if (isset($jsonData['searchResult'])) + if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult'])) { switch ($jsonData['searchResult']['resultArticleNumberStatus']) { @@ -278,7 +278,7 @@ public function getArticleNumberStatus() public function isSearchTimedOut() { $jsonData = $this->getResponseContent(); - if (isset($jsonData['searchResult'])) + if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult'])) { return $jsonData['searchResult']['timedOut']; } @@ -305,7 +305,7 @@ private function createAfterSearchNavigation() $filterGroups = array(); - if (isset($jsonData['searchResult']['groups'])) { + if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']['groups'])) { foreach ($jsonData['searchResult']['groups'] as $groupData) $filterGroups[] = $this->createFilterGroup($groupData); } @@ -503,7 +503,7 @@ public function createResultsPerPageOptions() $jsonData = $this->getResponseContent(); - if (isset($jsonData['searchResult'])) + if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult'])) { $rppData = $jsonData['searchResult']['resultsPerPageList']; if (!empty($rppData)) @@ -559,7 +559,7 @@ private function createPaging() $jsonData = $this->getResponseContent(); - if (isset($jsonData['searchResult'])) + if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult'])) { $pagingData = $jsonData['searchResult']['paging']; if (!empty($pagingData)) @@ -644,7 +644,7 @@ private function createSorting() $jsonData = $this->getResponseContent(); - if (isset($jsonData['searchResult'])) + if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult'])) { $sortingData = $jsonData['searchResult']['sortsList']; if (!empty($sortingData)) @@ -692,7 +692,7 @@ private function createBreadCrumbTrail() $jsonData = $this->getResponseContent(); - if (isset($jsonData['searchResult'])) + if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult'])) { $breadCrumbTrailData = $jsonData['searchResult']['breadCrumbTrailItems']; if (!empty($breadCrumbTrailData)) @@ -749,7 +749,7 @@ private function createCampaigns() $campaigns = array(); $jsonData = $this->getResponseContent(); - if (isset($jsonData['searchResult']['campaigns'])) { + if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']['campaigns'])) { foreach ($jsonData['searchResult']['campaigns'] as $campaignData) { $campaign = $this->createEmptyCampaignObject($campaignData); @@ -970,7 +970,7 @@ public function getFollowSearchValue() { $jsonData = $this->getResponseContent(); //use searchParams of result if available - if($jsonData && $jsonData['searchResult'] && isset($jsonData['searchResult']['searchParams'])) { + if (parent::isValidResponse($jsonData) && $jsonData['searchResult'] && isset($jsonData['searchResult']['searchParams'])) { $parameters = FF::getInstance( 'Util\Parameters', $jsonData['searchResult']['searchParams'] diff --git a/FACTFinder/Adapter/SimilarRecords.php b/FACTFinder/Adapter/SimilarRecords.php index cb6e036..be28c2e 100644 --- a/FACTFinder/Adapter/SimilarRecords.php +++ b/FACTFinder/Adapter/SimilarRecords.php @@ -139,9 +139,12 @@ private function createSimilarAttributes() else { $jsonData = $this->getResponseContent(); - foreach($jsonData['attributes'] as $attributeData) + if(parent::isValidResponse($jsonData)) { - $attributes[$attributeData['name']] = $attributeData['value']; + foreach($jsonData['attributes'] as $attributeData) + { + $attributes[$attributeData['name']] = $attributeData['value']; + } } } @@ -182,12 +185,15 @@ private function createSimilarRecords() { $position = 1; $jsonData = $this->getResponseContent(); - foreach($jsonData['records'] as $recordData) + if(parent::isValidResponse($jsonData)) { - if ($this->idsOnly) - $records[] = $this->createSparseRecord($recordData); - else - $records[] = $this->createRecord($recordData, $position++); + foreach($jsonData['records'] as $recordData) + { + if ($this->idsOnly) + $records[] = $this->createSparseRecord($recordData); + else + $records[] = $this->createRecord($recordData, $position++); + } } } diff --git a/FACTFinder/Adapter/Suggest.php b/FACTFinder/Adapter/Suggest.php index 1d63653..8eb0a7b 100644 --- a/FACTFinder/Adapter/Suggest.php +++ b/FACTFinder/Adapter/Suggest.php @@ -61,7 +61,7 @@ private function createSuggestions() $this->parameters['format'] = 'json'; $suggestData = $this->getResponseContent(); - if (!empty($suggestData)) + if (parent::isValidResponse($suggestData)) { if (isset($suggestData['suggestions'])) { diff --git a/FACTFinder/Adapter/TagCloud.php b/FACTFinder/Adapter/TagCloud.php index d943cfb..c85e7ae 100644 --- a/FACTFinder/Adapter/TagCloud.php +++ b/FACTFinder/Adapter/TagCloud.php @@ -88,7 +88,7 @@ private function createTagCloud($requestQuery = null) $tagCloud = array(); $tagCloudData = $this->getResponseContent(); - if (!empty($tagCloudData)) + if (parent::isValidResponse($tagCloudData)) { foreach ($tagCloudData as $tagQueryData) {