Jump to content

Freeze postcode,City and state TextBox on Checkout Page


Recommended Posts

Hi Guys,

I am so new to Prestashop and i would like to edit the "postcode" , "City" and "state" textbox on the checkout page. I would like to put a default un-editable entry to the textbox(I would like to freeze the textbox with a single value) on the checkout page. I have attached the pdf of that page i wish to edit. Please let me know which file to edit and how...please.

Decathlon.pdf

Link to comment
Share on other sites

ya I got the solution.

you can do one-thing inside your form-fields.tpl which is inside this directory-

..../templates/_partials/form-fields.tpl:

{block name='form_field_item_other'}
          <input
            class="form-control input-box"
            name="{$field.name}"
            type="{$field.type}"
            placeholder="{$field.name}"
            value="{$field.value}"
            {if isset($field.availableValues.placeholder)}placeholder="{$field.availableValues.placeholder}"{/if}
            {if $field.maxLength}maxlength="{$field.maxLength}"{/if}
            {if $field.required}required{/if}
            
             {if $field.readonly}readonly{/if}   // add this line

          >

after that is customerAddressFormatter.php set 

$formField->setReadonly(true);

in city and state inside validation part,

file path is -  ...override/classes/forms,

after that in formfields.php write get and set methods for readonly like......

class FormFieldCore
{

private $readonly        = false;

public function toArray()
    {
        return [
            'required' => $this->isRequired(),
            'readonly' => $this->isReadonly(),
        ];
    }

public function setReadonly($readonly)
    {
        $this->readonly = $readonly;
        return $this;
    }

    public function isReadonly()
    {
        return $this->readonly;
    }

}

 

 

Link to comment
Share on other sites

Hi

Thank you for your answer
You are on prestashop 1.7.5 because I can not find the same files as you ?

for : ../themes/xxxxxxxx/templates/_partials/form-fields.tpl  I added the line as you say
{if $field.readonly}readonly{/if}   // add this line 

then i do not understand where you find the file customerAddressFormatter.php and what needs to be done.
Could you be more precise?

 

 

 

 

Link to comment
Share on other sites

inside clases/form/ directory there is a file names as customerAddressFormatter.php

there is a function getFormate() inside that function a foreach loop like foreach ($fields as $field) {

//inside this something like this

if ( xxxxxxxxx) {
                    if ($field === 'city') {
                        $formField->setType('text');
                        $formField->setReadonly(true);                      //add this line
                        $formField->setName(strtolower($field));
                    }
                     if ($field === 'other') {
                        if($autopincodecity && !($OtherFiledEnable)){
                            $formField->setType('select');
                        }
                        if($autopincodecity && $OtherFiledEnable){
                            $formField->setType('hidden');
                        }
                    }
                }

 

if ($entity === 'Country') {
                    $formField->setType('countrySelect');
                    $formField->setValue($this->country->id);
                    foreach ($this->availableCountries as $country) {
                        $formField->addAvailableValue(
                            $country['id_country'],
                            $country[$entityField]
                        );
                    }
                } elseif ($entity === 'State') {
                    $formField->setType('text');
                        $formField->setRequired(true);
                        $formField->setReadonly(true);     //add this line 
                    // if ($this->country->contains_states) {
                    //     $states = State::getStatesByIdCountry($this->country->id, true);
                    //     foreach ($states as $state) {
                    //         $formField->addAvailableValue(
                    //             $state['id_state'],
                    //             $state[$entityField]
                    //         );
                    //     }
                    //     $formField->setRequired(true);
                    // }
                }

}

 

and after this classes/formfield.php  inside this file

difine variable like private $readonly        = false;

inside toArray() function  'readonly' => $this->isReadonly().

after that add get and set property...

public function setReadonly($readonly)
    {
        $this->readonly = $readonly;
        return $this;
    }

    public function isReadonly()
    {
        return $this->readonly;
    }

 

 

 

 

hope you understand now..

Thanks

 

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...