Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

php - How to edit Front Address form - Prestashop

I'm trying to use drop down list instead of textbox for 'City' field.(Like country list).I tried to edit address-form.tpl file.but it's contain smarty values.I don't know which .tpl/Controller i want to edit.

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>

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

finally i got a solution

1) add form type to city field 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) edit .tpl file 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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...