在Prestashop 1.5中限制某个国家/地区的类别
我需要在Prestashop 1.5中将一个类别限制为一组国家。 这一限制将阻止运输属于这一类别的产品;因此,用户仍然能够看到产品,但无法购买 理想情况下,我想开发一个模块,在一个类别的编辑页面中插入一个国家列表(复选框样式,如模块->付款页面(AdminPayment))但我一直无法做到 为什么我不能简单地将以下代码粘贴到renderForm()函数中? 如果我这样做,只有描述才可见在Prestashop 1.5中限制某个国家/地区的类别,prestashop,Prestashop,我需要在Prestashop 1.5中将一个类别限制为一组国家。 这一限制将阻止运输属于这一类别的产品;因此,用户仍然能够看到产品,但无法购买 理想情况下,我想开发一个模块,在一个类别的编辑页面中插入一个国家列表(复选框样式,如模块->付款页面(AdminPayment))但我一直无法做到 为什么我不能简单地将以下代码粘贴到renderForm()函数中? 如果我这样做,只有描述才可见 array( 'items' =>Country::getCountries(Context::
array(
'items' =>Country::getCountries(Context::getContext()->language->id),
'title' => $this->l('Country restrictions'),
'desc' => $this->l('Please mark the checkbox(es) for the country or countries for which you want to block the shipping.'),
'name_id' => 'country',
'identifier' => 'id_country',
'icon' => 'world',
),
编辑:
我设法让名单上的国家发挥作用:
array(
'type' => 'checkbox',
'label' => $this->l('Restricted Countries').':',
'class' => 'sel_country',
'name' => 'restricted_countries',
'values' => array(
'query' => Country::getCountries(Context::getContext()->language->id),
'id' => 'id_country',
'name' => 'name'
),
'desc' => $this->l('Mark all the countries you want to block the selling to. The restrictions will always be applied to every subcategory as well')
),
现在,我可以通过检查值“submitAddcategory”是否在后处理函数中提交并在那里运行insert查询来保存这些值。同样,我也可以从数据库中加载被阻止国家的ID,但是如何勾选国家列表中相应的选择框
我最初的“快速而肮脏”想法是在document.ready()中使用jQuery选择器,但是代码在插入其他代码之前就被插入了,因此,它无法工作,因为jQuery甚至还没有加载
如何做到这一点
干杯在renderForm()函数结束之前,我使用以下代码解决了这个问题。 电阻是$this->fieldsèu值,遗憾的是我不知道它的存在
public function getRestrictedCountries($obj)
{
// Loading blacklisted countries
$country = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT id_country
FROM `'._DB_PREFIX_.'category_country_restriction`
WHERE id_category = ' . (int)Tools::getValue('id_category') . ';');
$blacklisted_countries = array();
if (is_array($country))
foreach ($country as $cnt)
$blacklisted_countries[] = $cnt['id_country'];
// Global country list
$c_todos = Country::getCountries(Context::getContext()->language->id);
// Crossmatching everything
foreach ($c_todos as $c)
$this->fields_value['restricted_countries_'.$c['id_country']] = Tools::getValue('restricted_countries_'.$c['id_country'], (in_array($c['id_country'], $blacklisted_countries)));
}
PS:我从中读取的表基本上是“category”和“country”之间的关联表。在renderForm()函数结束之前,我使用以下代码解决了这个问题。 电阻是$this->fieldsèu值,遗憾的是我不知道它的存在
public function getRestrictedCountries($obj)
{
// Loading blacklisted countries
$country = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT id_country
FROM `'._DB_PREFIX_.'category_country_restriction`
WHERE id_category = ' . (int)Tools::getValue('id_category') . ';');
$blacklisted_countries = array();
if (is_array($country))
foreach ($country as $cnt)
$blacklisted_countries[] = $cnt['id_country'];
// Global country list
$c_todos = Country::getCountries(Context::getContext()->language->id);
// Crossmatching everything
foreach ($c_todos as $c)
$this->fields_value['restricted_countries_'.$c['id_country']] = Tools::getValue('restricted_countries_'.$c['id_country'], (in_array($c['id_country'], $blacklisted_countries)));
}
PS:我读的表格基本上是一个“类别”和“国家”之间的关联表格