Skip to content

Commit b2e2f67

Browse files
authored
Merge pull request #1372 from algolia/feature/MAGE-675
Hide Pagination if nbpages size is 1
2 parents 77a539c + 8704bb8 commit b2e2f67

File tree

7 files changed

+36
-5
lines changed

7 files changed

+36
-5
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+
}

Controller/Adminhtml/Queue/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function execute()
1111
{
1212
$job = $this->initJob();
1313
if (is_null($job)) {
14-
$this->messageManager->addErrorMessage(__('This job does not exists.'));
14+
$this->messageManager->addErrorMessage(__('This job does not exist.'));
1515
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
1616
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
1717

Controller/Adminhtml/QueueArchive/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function execute()
1313
{
1414
$job = $this->initJob();
1515
if (is_null($job)) {
16-
$this->messageManager->addErrorMessage(__('This job does not exists.'));
16+
$this->messageManager->addErrorMessage(__('This job does not exist.'));
1717
/** @var Redirect $resultRedirect */
1818
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
1919

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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,14 @@ define(
391391
empty: '',
392392
item: $('#instant-hit-template').html(),
393393
},
394-
transformItems: function (items) {
394+
transformItems: function (items, { results }) {
395+
if (results.nbPages <= 1 && algoliaConfig.instant.hidePagination === true){
396+
document.getElementById('instant-search-pagination-container').style.display = "none";
397+
}else{
398+
document.getElementById('instant-search-pagination-container').style.display = "block";
399+
}
395400
return items.map(function (item) {
401+
396402
item.__indexName = search.helper.lastResults.index;
397403
item = transformHit(item, algoliaConfig.priceKey, search.helper);
398404
// FIXME: transformHit is a global
@@ -689,4 +695,4 @@ define(
689695
return options;
690696
}
691697
}
692-
);
698+
);

0 commit comments

Comments
 (0)