You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PrestaShop自定义模块中添加带搜索功能的产品选择框

给PrestaShop自定义模块的产品选择框添加搜索功能

要给你的Bootstrap Select选择框启用实时搜索,只需要在表单字段的配置数组中添加data属性配置即可。PrestaShop的表单生成器会自动将data数组中的键值对转换为对应的HTML data-*属性。

修改后的代码

$fields_form = [
    'form' => [
        'legend' => [
            'title' => $this->trans('Settings', [], 'Admin.Global'),
            'icon' => 'icon-cogs',
        ],

        'description' => $this->trans('Add products to your homepage', [], 'Modules.Featuredproducts.Admin'),
        'input' => [
            [
                'type' => 'select',
                'label' => $this->l('Select a Product'),
                'name' => 'id_product',
                'required' => false,
                'col' => '8',
                'class' => 'selectpicker',
                'bootstrap' => true,
                // 添加这一行启用实时搜索
                'data' => ['live-search' => 'true'],
                'options' => [
                    'query' => Product::getProducts($this->context->language->id, 0, 0, "id_product", "desc"),
                    'id' => 'id_product',
                    'name' => 'name',
                    'default' => [
                        'value' => '',
                        'label' => $this->l('--')
                    ]
                ]
            ]
        ],
        'submit' => [
            'title' => $this->trans('Save', [], 'Admin.Actions'),
        ],
    ],
];

补充说明

  • 如果需要同时选择4个产品,可以在字段配置中添加'multiple' => true,让选择框支持多选,配合实时搜索能进一步提升操作效率。
  • 确认后台已正确加载Bootstrap Select的JS和CSS文件,PrestaShop默认后台通常已集成,但自定义主题可能需要额外检查。

内容的提问来源于stack exchange,提问作者MPN7

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 13:42:40