Hello,
Does anyone have an ideea how we can re-initialize a javascript shopware plugin after an own ajax search inside a list of products?
We are using jquery for that:
$(document).ready(function() {
var LoaderShowBusy = function () {
var $busy = $("#loader-busy");
if ($busy.length === 0) {
$busy = $('');
$busy
.css("display", "none")
.css("position", "fixed")
.css("top", "0")
.css("left", "0")
.css("z-index", "9999");
$busy.appendTo($("body:first"));
}
$busy
.width($(window).width())
.height($(window).height())
$busy.show();
};
var LoaderHideBusy = function () {
$("#loader-busy").hide();
$("#loader-busy").remove();
};
$('body').on('keyup', '.search-term', function (e) {
e.preventDefault();
var searchTerm = $(this).val();
var form = $(this).closest('form');
if (searchTerm.length > 2) {
LoaderShowBusy();
var searchURL = form.attr('action');
$.ajax({
cache: false,
url: searchURL,
async: true,
beforeSend: function(xhr){
xhr.setRequestHeader('sw-access-key', window.accessKey);
xhr.setRequestHeader('sw-context-token', window.contextToken);
xhr.setRequestHeader('Content-Type', 'application/json');
},
data: 'term=' + searchTerm,
success: function (data) {
$('#ajax-search-result').html(data);
LoaderHideBusy();
//how re-initialize AddToCart plugin here
}
});
}
});
});
The search is working ok, but after writing the search result, the add to basket doesn’t work anymore.
Best regards,
Sorin