Skip to content

Commit 9ecf92f

Browse files
committed
MAGE-675 - add the config in admin for customers to opt-in and consume that in the js
1 parent b93c64b commit 9ecf92f

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

Block/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public function getConfiguration()
154154
'infiniteScrollEnabled' => $config->isInfiniteScrollEnabled(),
155155
'urlTrackedParameters' => $this->getUrlTrackedParameters(),
156156
'isSearchBoxEnabled' => $config->isInstantSearchBoxEnabled(),
157+
'hidePagination' => $config->hidePaginationInInstantSearchPage()
157158
],
158159
'autocomplete' => [
159160
'enabled' => $config->isAutoCompleteEnabled(),
@@ -381,4 +382,4 @@ protected function getLandingPageConfiguration()
381382
{
382383
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getConfiguration() : json_encode([]);
383384
}
384-
}
385+
}

Helper/ConfigHelper.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ConfigHelper
3333
public const XML_ADD_TO_CART_ENABLE = 'algoliasearch_instant/instant/add_to_cart_enable';
3434
public const INFINITE_SCROLL_ENABLE = 'algoliasearch_instant/instant/infinite_scroll_enable';
3535
public const SEARCHBOX_ENABLE = 'algoliasearch_instant/instant/instantsearch_searchbox';
36+
public const HIDE_PAGINATION = 'algoliasearch_instant/instant/hide_pagination';
3637

3738
public const IS_POPUP_ENABLED = 'algoliasearch_autocomplete/autocomplete/is_popup_enabled';
3839
public const NB_OF_PRODUCTS_SUGGESTIONS = 'algoliasearch_autocomplete/autocomplete/nb_of_products_suggestions';
@@ -529,6 +530,16 @@ public function isInfiniteScrollEnabled($storeId = null)
529530
&& $this->configInterface->isSetFlag(self::INFINITE_SCROLL_ENABLE, ScopeInterface::SCOPE_STORE, $storeId);
530531
}
531532

533+
/**
534+
* @param $storeId
535+
* @return bool
536+
*/
537+
public function hidePaginationInInstantSearchPage($storeId = null)
538+
{
539+
return $this->isInstantEnabled($storeId)
540+
&& $this->configInterface->isSetFlag(self::HIDE_PAGINATION, ScopeInterface::SCOPE_STORE, $storeId);
541+
}
542+
532543
/**
533544
* @param $storeId
534545
* @return bool

etc/adminhtml/system.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,18 @@
399399
<field id="is_instant_enabled">1</field>
400400
</depends>
401401
</field>
402+
<field id="hide_pagination" translate="label comment" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="1">
403+
<label>Hide Pagination for Single Page Results</label>
404+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
405+
<comment>
406+
<![CDATA[
407+
Hide Pagination if there is only one page in the results
408+
]]>
409+
</comment>
410+
<depends>
411+
<field id="is_instant_enabled">1</field>
412+
</depends>
413+
</field>
402414
</group>
403415
</section>
404416
<section id="algoliasearch_products" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<sorts><![CDATA[{"_4581608784535_789":{"attribute":"price","sort":"asc","sortLabel":"Lowest price"},"_2541555584535_585":{"attribute":"price","sort":"desc","sortLabel":"Highest price"},"_5581608784535_898":{"attribute":"created_at","sort":"desc","sortLabel":"Newest first"}}]]></sorts>
2121
<instantsearch_searchbox>1</instantsearch_searchbox>
2222
<use_virtual_replica>0</use_virtual_replica>
23+
<hide_pagination>0</hide_pagination>
2324
</instant>
2425
</algoliasearch_instant>
2526
<algoliasearch_products>

view/frontend/web/instantsearch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ define(
392392
item: $('#instant-hit-template').html(),
393393
},
394394
transformItems: function (items, { results }) {
395-
if (results.nbPages <= 1){
395+
if (results.nbPages <= 1 && algoliaConfig.instant.hidePagination === true){
396396
document.getElementById('instant-search-pagination-container').style.display = "none";
397397
}else{
398398
document.getElementById('instant-search-pagination-container').style.display = "block";
@@ -695,4 +695,4 @@ define(
695695
return options;
696696
}
697697
}
698-
);
698+
);

0 commit comments

Comments
 (0)