Skip to content

Commit

Permalink
Disable searchbanners when disabeling search (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-net committed Dec 8, 2023
1 parent e778ed4 commit f5f5f9a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Block/Catalog/Product/ProductList/Toolbar/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface;
use Tweakwise\Magento2Tweakwise\Model\Catalog\Layer\NavigationContext\CurrentContext;
use Tweakwise\Magento2Tweakwise\Model\Client\Request\ProductSearchRequest;
use Tweakwise\Magento2Tweakwise\Model\Client\Type\SortFieldType;
use Tweakwise\Magento2Tweakwise\Model\Config;
use Magento\Catalog\Block\Product\ProductList\Toolbar;
Expand Down Expand Up @@ -73,6 +74,13 @@ public function __construct(
public function aroundGetAvailableOrders(Toolbar $subject, Closure $proceed)
{
if (!$this->config->isLayeredEnabled()) {
if (!$this->config->isSearchEnabled() || !($this->context->getRequest() instanceof ProductSearchRequest)) {
return $proceed();
}
}

//page is search and search is not enabled
if ((!$this->config->isSearchEnabled()) && ($this->context->getRequest() instanceof ProductSearchRequest)) {
return $proceed();
}

Expand Down
7 changes: 6 additions & 1 deletion Model/Catalog/Layer/FilterList/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ public function aroundGetFilters(FilterList $subject, Closure $proceed, Layer $l
}
}

//no api responseA
//page is search and search is not enabled
if (!$this->config->isSearchEnabled() && ($layer instanceof Layer\Search)) {
return $proceed($layer);
}

//no api response
if($this->config->getTweakwiseExceptionTrown()) {
return $proceed($layer);
}
Expand Down
3 changes: 3 additions & 0 deletions Model/Catalog/Layer/ItemCollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public function getCollection(Category $category)
return $this->originalProvider->getCollection($category);
}
}
if (!$this->config->isSearchEnabled() && ($this->navigationContext->getRequest() instanceof ProductSearchRequest)) {
return $this->originalProvider->getCollection($category);
}

//no api response
if($this->config->getTweakwiseExceptionTrown()) {
Expand Down
3 changes: 2 additions & 1 deletion Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ public function isPersonalMerchandisingActive(Store $store = null)
*/
public function isSearchBannersActive(Store $store = null)
{
return (bool) $this->getStoreConfig('tweakwise/search/searchbanner', $store);
return (bool) $this->getStoreConfig('tweakwise/search/searchbanner', $store)
&& $this->isSearchEnabled();
}

/**
Expand Down

0 comments on commit f5f5f9a

Please sign in to comment.