Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check empty array in optimizer preview and code optimization #1425

Merged
merged 3 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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