Skip to content

Instantly share code, notes, and snippets.

@sandipklevu
Created June 5, 2023 12:56
Show Gist options
  • Save sandipklevu/57372b8ee8068b5e1f0042148fa00a3e to your computer and use it in GitHub Desktop.
Save sandipklevu/57372b8ee8068b5e1f0042148fa00a3e to your computer and use it in GitHub Desktop.
<magento-root>/app/design/frontend/rwd/default/template/klevu/search/v2/js-init.phtml For e.g. `rwd/default` is a active theme
<?php
/** @var Mage_Core_Block_Template $this */
/** @var Klevu_Search_Helper_Config $config */
/** @var Klevu_Search_Helper_Data $helper */
?>
<?php $config = Mage::helper('klevu_search/config'); ?>
<?php $helper = Mage::helper('klevu_search'); ?>
<?php if ($config->isExtensionConfigured()): ?>
<?php $urlRoute = 'catalogsearch/result/'; ?>
<?php if ($config->isLandingEnabled() === 2): ?>
<?php $urlRoute = 'search'; ?>
<?php endif; ?>
<?php $landingURL = Mage::getUrl($urlRoute, [
'_secure' => Mage::app()->getFrontController()->getRequest()->isSecure(),
]); ?>
<script src="https://js.klevu.com/core/v2/klevu.js"></script>
<script type="text/javascript" id="klevu_jsmoi_enabled">
var klevu_moi = {
"enabled": true
};
</script>
<script type="text/javascript" id="klevu_jsvars">
if (typeof klevu_lang === "undefined") {
var klevu_lang = '<?php echo $helper->getStoreLanguage() ?>';
}
</script>
<script type="text/javascript" id="klevu_jsapikeys">
klevu({
"analytics": {"apiKey": "<?php echo $config->getJsApiKey() ?>"},
"search": {"apiKey": "<?php echo $config->getJsApiKey() ?>"},
"moi": {"apiKey": "<?php echo $config->getJsApiKey() ?>"}
});
</script>
<script src="https://js.klevu.com/theme/default/v2/quick-search.js"></script>
<script type="text/javascript">
klevu.interactive(function () {
var searchBoxSelector = 'input[name="q"]';
var APIv2CloudSearchURL = "eucs31v2.ksearchnet.com"; //APIv2 Cloud Search URL, Change the value
var options = {
url: {
protocol: "https:",
landing: '<?php echo $landingURL;?>',
search: 'https://' + APIv2CloudSearchURL + '/cs/v2/search'
},
search: {
minChars: 0,
searchBoxSelector: searchBoxSelector + ',.kuSearchInput',
},
moi: {
active: true
}
};
klevu(options);
});
</script>
<?php $customerSession = Mage::getSingleton('customer/session'); ?>
<?php $isLoggedIn = $customerSession->isLoggedIn(); ?>
<?php if ($isLoggedIn): ?>
<script type="text/javascript">
var klevu_loginCustomerGroup = "<?php echo $customerSession->getCustomerGroupId(); ?>";
var klevu_idCode = "<?php echo "enc-" . md5($customerSession->getCustomer()->getEmail()); ?>";
</script>
<?php endif; ?>
<?php $currency = $helper->getCurrencyData(); ?>
<?php if (!empty($currency)): ?>
<script type="text/javascript">
var klevu_currentCurrencyCode = "<?php echo Mage::app()->getStore()->getCurrentCurrencyCode(); ?>";
var klevu_currentCurrencyRates = {<?php echo $currency;?>};
</script>
<?php endif; ?>
<?php endif; ?>
@sandipklevu
Copy link
Author

Replace the value for variable var APIv2CloudSearchURL available on box.klevu.com > Store Settings > APIv2 Cloud Search URL:

https://gist.github.com/sandipklevu/57372b8ee8068b5e1f0042148fa00a3e#file-js-init-phtml-L38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment