HelperForm 中的商店关联

Shop association in HelperForm

在我的 prestashop helperForm 中,我想使用内置商店 select 或者。 select 树出现了,但我无法正确设置 tpl_vars。奇怪的是,我把什么放在 'name' (blabla) 下并不重要。复选框的名称始终为 "checkBoxShopAsso_configuration".

    if (Shop::isFeatureActive()) {
        $inputs[] = array(
            'type' => 'shop',
            'label' => $this->l('Shop association:'),
            'name' => 'genzo_link',
        );
    }

    $fields_form = array(
        'form' => array(
            'legend' => array(
                'title' => ('Add Link'),
                'icon' => 'icon-cogs'
            ),
            'input' => $inputs,
            'submit' => array(
                'title' => ('Update'),
                'class' => 'btn btn-default pull-right'
            )
        )
    );

    $helper = new HelperForm();
    $helper->submit_action = 'saveLink';
    $helper->default_form_language = $this->context->language->id;
    $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name .'&module_name=' . $this->name;
    $helper->token = Tools::getAdminTokenLite('AdminModules');

    $vars['blabla'][3] = 0;

    $helper->tpl_vars = array(
        'fields_value' => $vars,
        'languages' => $this->context->controller->getLanguages(),
        'id_language' => $this->context->language->id,
    );

我需要如何设置 tpl_vars,以便只 select 编辑有条目的商店?假设我有 3 家商店,并且只有前两家商店有一个条目。我以为我必须这样做:

$vars['blabla'][1] = 1;
$vars['blabla'][2] = 1;
$vars['blabla'][3] = 0;

但这不起作用。它 select 总是所有 3 家商店。

感谢您的帮助!如果有什么不清楚的地方,请告诉我哪里需要更好的解释。

更新: 对于其他人。您只需要使用这三个信息来设置您的对象。

$helper->table = 'genzo_link';
$helper->id = $id_genzo_link;
$helper->identifier = 'id_genzo_link';

您没有(或不能)在表单创建中输入所选商店。它会从数据库中为您完成。

当类型为'shop'时,它将执行:

$params['html'] = $this->renderAssoShop($disable_shops);

HelperForm::renderAssoShop($disable_shared = false, $template_directory = null) 中它将检查该功能是否处于活动状态,然后:

 if ((int)$this->id) {
      $sql = 'SELECT `id_shop`, `'.bqSQL($this->identifier).'`
              FROM `'._DB_PREFIX_.bqSQL($this->table).'_shop`
              WHERE `'.bqSQL($this->identifier).'` = '.(int)$this->id;

      foreach (Db::getInstance()->executeS($sql) as $row) {
          $assos[$row['id_shop']] = $row['id_shop'];
      }
  }

因此,如果您的对象 table 是 blabla,您只需使用 id_blabla 和 id_shop 创建 blabla_shop。 顺便说一句,如果 (int)$this->id 为 0,它将从上下文中预选所有商店。