在的Prestashop 1.6,使用鉤子函數,你可以做這樣的事情(actualy我使用一個自定義模塊內部):
public function hookHeader() {
//Jquery native Prestashop plugin
$this->context->controller->addJQueryPlugin('fancybox');
//CSS
$this->context->controller->addCSS('//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css', 'all');
$this->context->controller->addCSS('//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css', 'all');
$this->context->controller->addCSS('//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.15.35/css/bootstrap-datetimepicker.css', 'all');
$this->context->controller->addCSS('//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.15.35/css/bootstrap-datetimepicker.min.css', 'all');
//Javascript
$this->context->controller->addJS('//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', 'all');
$this->context->controller->addJS('//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js', 'all');
$this->context->controller->addJS('//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js', 'all');
$this->context->controller->addJS('//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js', 'all');
$this->context->controller->addJS('//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/locale/fr.js', 'all');
$this->context->controller->addJS('//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.15.35/js/bootstrap-datetimepicker.min.js', 'all');
}
正如你所看到的,我添加Fancybox,Bootstrap和DateTimePicker。 你應該在你的主題或模塊內的js目錄中添加自己的插件。
調用在主題插件很容易使用的Smarty($ js_dir我猜,或$ tpl_dir)
編輯:
下面是自動完成的的Prestashop樣本:
TPL:
<!-- Block eversearch module TOP -->
<div id="search_block_top" class="col-sm-4 clearfix">
<form id="searchbox" method="get" action="{$link->getPageLink('search')|escape:'html':'UTF-8'}" >
<input type="hidden" name="controller" value="search" />
<input type="hidden" name="orderby" value="position" />
<input type="hidden" name="orderway" value="desc" />
<input class="search_query form-control" type="text" id="search_query_top" name="search_query" placeholder="{l s='Search' mod='blocksearch'}" value="{$search_query|escape:'htmlall':'UTF-8'|stripslashes}" />
<button type="submit" name="submit_search" class="btn btn-default button-search">
<span>{l s='Search' mod='blocksearch'}</span>
</button>
</form>
這裏是使用Jquery的自動完成:
$(document).ready(function(){
//console.log('Autocomplete loaded');
var baseUrl = $('#baseURL').val();
var evertrade_module_dir = baseUrl+'/useful';
var form = $('.ever_search_query_top');
//console.log(baseUrl);
//Autocomplete
$('#ever_search_query_top').autocomplete(evertrade_module_dir+'/ajax_product_list.php', {
minChars: 1,
autoFill: true,
max:20,
matchContains: true,
mustMatch:true,
scroll:false,
cacheLength:0,
formatItem: function(item) {
return item[1];
}
}).result(function(e,i){
console.log(i);
if(i != undefined)
$('#ever_search_query_top').val(i[1]);
window.location.href = baseUrl+"recherche?orderby=position&orderway=desc&search_query="+i[1]+"";
});
假設你的php文件正在返回正確的值。 Prefere使用自己的HTML,覆蓋主題中的tpl。
謝謝,它適合我的完美。不幸的是,當Im試圖調用我的自動完成函數時,prestashop會在輸入字段中添加autocomplete =「off」。你知道我該如何解決它? – ecetera