Module 特色类别PrestaShop 1.7
我想能够在前面显示几个类别(名称和我添加的自定义字段)。我创建了一个自定义模块,从中可以获得类别列表,并将其显示在后台,这样我就可以选择一些在前台使用它们Module 特色类别PrestaShop 1.7,module,categories,prestashop-1.7,Module,Categories,Prestashop 1.7,我想能够在前面显示几个类别(名称和我添加的自定义字段)。我创建了一个自定义模块,从中可以获得类别列表,并将其显示在后台,这样我就可以选择一些在前台使用它们 public function getContent() { if (((bool) Tools::isSubmit('submit_feaduredcategoriesModule')) == true) { $this->postProcess(); } $this->context-
public function getContent()
{
if (((bool) Tools::isSubmit('submit_feaduredcategoriesModule')) == true) {
$this->postProcess();
}
$this->context->smarty->assign('module_dir', $this->_path);
$output = $this->context->smarty->fetch($this->local_path . 'views/templates/admin/configure.tpl');
return $output . $this->renderForm();
}
protected function renderForm()
{
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$helper->module = $this;
$helper->default_form_language = $this->context->language->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submit_featuredcategoriesModule';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
. '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFormValues(), /* Add values for inputs */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
return $helper->generateForm(array($this->getConfigForm()));
}
protected function getConfigForm()
{
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'categories',
'label' => $this->l('Featured categories'),
'name' => 'FEATURED_CATEGORIES',
'tree' => array(
'id' => 'category',
'selected_categories' => array((int)Configuration::get('category')),
'use_checkbox' => true
)
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}
但从这里开始,我不确定在后处理或getConfigFormValues中放置什么,我也不属于getConfigForm中的“所选类别”:(
任何帮助、提示和建议都将不胜感激!提前感谢后处理和getConfigFormValues这两种方法实际上是标准的,但不是强制性的
顺便说一下,让我们从getConfigFormValues开始:
此方法应返回表单输入值的数组,索引作为输入的名称,输入所需的值,在您的情况下应类似于:
protected function getConfigFormValues()
{
return [
'FEATURED_CATEGORIES' => Category::getCategories() // Check the right method to use in the Category class
];
}
后处理方法用于在提交表单时执行所有操作。在您的情况下,应该是这样的:protected function postProcess()
{
if(Tools::isSumbit('submit_featuredcategoriesModule')) // Check if the form is submitted by checking the input name that you specify in $helper->submit_action
{
// Do your stuff
}
}
小贴士:
- 使用官方的devdocs,它确实充满了信息:
- Category类用于在数据库中存储任何类型的信息,它使用ps_Category表(如果ps_用作表前缀)。最常用的方法是get(KEY)检索信息,updateValue(KEY)在数据库中存储值
- 工具类有一整套与请求和PS生态系统交互的方法,即getValue(键)从POST或get请求(也上传文件等)获取值,或isSubmit(键)检查值是否已提交(也从get或POST提交)
类文件位于根/类中,请检查它们以发现所有方法Hi@marsaldev,谢谢您的回答。我是PS的新手:)我不知道如何做的是1。如何在getConfigFormValues和2中预先选择已保存的特色类别。如何在后处理中保存选定的类别:(嗨@Claire,不幸的是答案太宽了