Skip to content

Commit

Permalink
Fix issue with product limit on the search page
Browse files Browse the repository at this point in the history
  • Loading branch information
iGerchak committed Apr 27, 2022
1 parent d3ae5fe commit 39a1b76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions Observer/SearchResultObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Magento\Framework\Event\ObserverInterface;

/**
* Observer for `controller_action_layout_render_before_catalogsearch_result_index'
* Observer for `catalog_product_collection_load_after'
*
* @see http://developer.matomo.org/guides/tracking-javascript-guide#internal-search-tracking
*/
Expand Down Expand Up @@ -59,6 +59,11 @@ class SearchResultObserver implements ObserverInterface
*/
protected $_view;

/**
* @var \Magento\Framework\App\Request\Http $request
*/
private \Magento\Framework\App\Request\Http $request;

/**
* Constructor
*
Expand All @@ -71,12 +76,14 @@ public function __construct(
\Chessio\Matomo\Model\Tracker $matomoTracker,
\Chessio\Matomo\Helper\Data $dataHelper,
\Magento\Search\Model\QueryFactory $queryFactory,
\Magento\Framework\App\ViewInterface $view
\Magento\Framework\App\ViewInterface $view,
\Magento\Framework\App\Request\Http $request
) {
$this->_matomoTracker = $matomoTracker;
$this->_dataHelper = $dataHelper;
$this->_queryFactory = $queryFactory;
$this->_view = $view;
$this->request = $request;
}

/**
Expand All @@ -88,6 +95,11 @@ public function __construct(
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
// Skip executes in case the current page isn't the search result page
if ($this->request->getFullActionName() !== 'catalogsearch_result_index') {
return $this;
}

if (!$this->_dataHelper->isTrackingEnabled()) {
return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion etc/frontend/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<observer name="matomo_observer"
instance="Chessio\Matomo\Observer\CheckoutSuccessObserver" />
</event>
<event name="controller_action_layout_render_before_catalogsearch_result_index">
<event name="catalog_product_collection_load_after">
<observer name="matomo_observer"
instance="Chessio\Matomo\Observer\SearchResultObserver" />
</event>
Expand Down

0 comments on commit 39a1b76

Please sign in to comment.