如何编辑地址前置表-Prestashop

2022-03-25 00:00:00 php smarty prestashop

我正在尝试使用"City"字段的下拉列表而不是文本框。(如"Country List")。我尝试编辑address-form.tpl文件。但它包含智能值。我不知道要编辑哪个.tpl/Controller。

address-form.tpl

<section class="form-fields">
      {block name='form_fields'}
        {foreach from=$formFields item="field"}
          {block name='form_field'}
            {form_field field=$field}
          {/block}
        {/foreach}
      {/block}
    </section>


解决方案

最终我得到了解决方案

1)将表单类型添加到城市字段 classes/form/CustomerAddressFormatter.php

if ($field === 'city') {
                    $formField->setType('select');
                    $formField->setType('citySelect');
                    $formField->setRequired(true);

                    $loc=new Location();         //load data from db
                    $result=$loc->getLocations();

                    foreach ($result as $value) {
                        $formField->addAvailableValue(
                            $value['area'],
                            $value['area']
                        );
                    }
            }
2)编辑.tpl文件 themes/yourtheme/templates/_partials/form-fields.tpl

{elseif $field.type === 'citySelect'}

          <select
            class="form-control form-control-select chosen-select"
            name="{$field.name}"
            {if $field.required}required{/if}
          >
            <option value disabled selected>{l s='-- please choose --' d='Shop.Forms.Labels'}</option>
            {foreach from=$field.availableValues item="label" key="value"}
              <option value="{$value}" {if $value eq $field.value} selected {/if}>{$label}</option>
            {/foreach}
          </select>

相关文章