Created
November 9, 2021 23:01
-
-
Save UbaldoRosas/75b5f6dbfa2583b2cfbfeb4d18300906 to your computer and use it in GitHub Desktop.
Add conditionals for Products, Collections or Pages at search suggestions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var instantSearchTemplate = InstantSearchResultBlock.prototype.getTemplate; | |
InstantSearchResultBlock.prototype.getTemplate = function(tempType) { | |
if (['products', 'collections'].indexOf(tempType) === -1) return instantSearchTemplate.call(this, tempType); | |
return '<li class="{{class.searchSuggestionGroup}} ' + tempType + '" data-group="{{type}}" aria-label="{{label}}">' + | |
'<ul class="default">' + | |
'<li class="{{class.searchSuggestionHeader}}-{{type}} {{class.searchSuggestionHeader}}" aria-label="{{label}}">{{label}}</li>' + | |
'{{resultItems}}' + | |
'</ul>' + | |
'</li>'; | |
} | |
InstantSearchResultBlock.prototype.compileTemplate = function() { | |
if ((this.status != 'active' || !this.isShow) && !this._isShowDYM()) { | |
return ''; | |
} | |
var label = this.isAllEmpty ? this.notFoundLabel : this.label; | |
return this.getTemplate(this.type) | |
.replace(/{{type}}/g, this.type) | |
.replace(/{{label}}/g, label) | |
.replace(/{{class.searchSuggestionHeader}}/g, Class.searchSuggestionHeader) | |
.replace(/{{class.searchSuggestionGroup}}/g, Class.searchSuggestionGroup) | |
.replace(/{{resultItems}}/g, ''); | |
} | |
/** | |
* Render the instant search result block | |
* @returns {Object} jQuery object | |
*/ | |
InstantSearchResultBlock.prototype.render = function() { | |
this.$element = jQ(this.compileTemplate()); | |
var self = this; | |
if (['products', 'collections'].indexOf(this.type) !== -1) { | |
this.children.forEach(function(child) { | |
if (child.$element) { | |
/* --- Your conditional --- */ | |
if (child.data.template_suffix == 'total-look') { | |
jQ(child.$element).find('.boost-pfs-search-suggestion-product-price').html('<span class="boost-pfs-search-suggestion-product-regular-price hide"></span>'); | |
self.$element.find('> ul.default').append(child.$element); | |
} else { | |
self.$element.find('> ul.default').append(child.$element); | |
} | |
/* --- end of Your conditional --- */ | |
} | |
}) | |
if (self.$element.find('ul.default').children().length <= 1) { | |
self.$element.find('ul.default').remove() | |
} | |
if (self.$element.find('ul.default').children().length <= 1) { | |
self.$element.find('ul.default').remove() | |
} | |
} else { | |
this.children.forEach(function(child) { | |
if (child.$element) { | |
self.$element.find('> ul').append(child.$element); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment