Skip to content

Commit

Permalink
Merge pull request #1425 from androshchuk/1419-fix-error-in-optimizer
Browse files Browse the repository at this point in the history
add check empty array in optimizer preview and code optimization
  • Loading branch information
romainruaud authored Jul 8, 2019
2 parents e82e5fa + 311ce3e commit b39afe4
Show file tree
Hide file tree
Showing 2 changed files with 488 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,25 +161,34 @@ private function getOptimizedResults()
}

/**
* Indicates if the current optmizer can be applied to the search context.
* Indicates if the current optimizer can be applied to the search context.
*
* @return boolean
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function canApply()
private function canApply() : bool
{
$canApply = in_array($this->containerConfiguration->getName(), $this->optimizer->getSearchContainer());

if ($canApply && $this->containerConfiguration->getName() == 'quick_search_container') {
$config = $this->optimizer->getQuickSearchContainer();
if ($config['apply_to'] == 1) {
$queries = array_column($config['query_ids'], 'query_text');
$canApply = in_array($this->queryText, $queries);
}
} elseif ($canApply && $this->containerConfiguration->getName() == 'catalog_view_container') {
$config = $this->optimizer->getCatalogViewContainer();
if ($config['apply_to'] == 1) {
$categoryIds = array_filter($config['category_ids']);
$canApply = in_array($this->category->getId(), $categoryIds);
$canApply = false;
if (!empty($this->optimizer->getSearchContainer())
&& in_array($this->containerConfiguration->getName(), $this->optimizer->getSearchContainer(), true)) {
switch ($this->containerConfiguration->getName()) {
case 'catalog_product_autocomplete':
$canApply = true;
break;
case 'quick_search_container':
$config = $this->optimizer->getQuickSearchContainer();
if ((int) $config['apply_to'] === 1 && !empty($config['query_ids'])) {
$queries = array_column($config['query_ids'], 'query_text');
$canApply = in_array($this->queryText, $queries, true);
}
break;
case 'catalog_view_container':
$config = $this->optimizer->getCatalogViewContainer();
if ((int) $config['apply_to'] === 1 && !empty($config['category_ids'])) {
$categoryIds = array_filter($config['category_ids']);
$canApply = in_array($this->category->getId(), $categoryIds, true);
}
break;
}
}

Expand Down
Loading

0 comments on commit b39afe4

Please sign in to comment.