Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k 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 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...