Magento

There are some aspects of the Klevu Recommendations integration that are specific to Magento customers, which are detailed on this page.

Image URLs (/needtochange/ or /pub/)

In Magento, the base URL for images can contain /pub/ depending on your configuration, so we have some placeholders in our indexed image URLs which need to be replaced.

Please add the following code to your store, immediately after the inclusion of klevu-recs.js, and before you call klevu.interactive(), to inform our JS utility how to handle images in your store:

klevu.interactive(function () {
    klevu.coreEvent.attach("setRemoteConfigRecsBaseUpdates", {
        name: "klevuMagentoImage",
        fire: function () {
            klevu.recs.base.getScope().chains.search.control.add({
                name: "klevuMagentoImage",
                fire: function (data, scope) {
                    scope.recsScope.searchObject.getScope().chains.template.process.success.add({
                        name: "klevuMagentoImage",
                        fire: function (data, scope) {
                            if (typeof window.klevu_pubIsInUse == "undefined") {
                                window.klevu_pubIsInUse = true;
                            }
                            klevu.each(data.template.query, function (key, query) {
                                if (query.result.length > 0) {
                                    klevu.each(query.result, function (key, product) {
                                        if (window.klevu_pubIsInUse) {
                                            product.image = product.image.replace('pub/', '');
                                            product.image = product.image.replace('needtochange/', '');
                                        } else {
                                            product.image = product.image.replace('needtochange/', 'pub/');
                                        }
                                    });
                                }
                            });
                        }
                    });
                }
            });
        }
    });
});