Jump to content

[HELP] Add <select> on the registration page


Recommended Posts

Hi guys, I'm adding a select on the registration page, also in the back office.
 
 
The guide explains how to do a simple text field, but I managed to make the selector.
 
What I did was change this:
{if $field_name eq 'my_custom_field'}
    <div id="vat_area">
        <div id="my_custom_field">
            <div class="form-group">
                <label for="my-custom-field">{l s='My Custom Field'}</label>
                <input type="text" class="form-control validate" data-validate="{$address_validation.$field_name.validate}" id="my-custom-field" name="my_custom_field" value="{if isset($smarty.post.my_custom_field)}{$smarty.post.my_custom_field}{else}{if isset($address->my_custom_field)}{$address->my_custom_field|escape:'html':'UTF-8'}{/if}{/if}" />
            </div>
        </div>
    </div>
{/if}

for this:

{if $field_name eq 'condicion_fiscal'}
    <div id="condicion_fiscal">					        	
        <div class="required form-group selector2">
			<label for="condicion_fiscal" class="i-other f-label">{l s='Condicion Fiscal'} <sup>*</sup></label>
			<select name="condicion_fiscal" id="condicion_fiscal" class="form-control">
				<option value="">-</option>
				<option value="Monotributista" {if ($smarty.post.condicion_fiscal == 'Monotributista')} selected="selected" {/if}>Monotributista</option>
				<option value="Responsable inscripto" {if ($smarty.post.condicion_fiscal == 'Responsable inscripto')} selected="selected" {/if}>Responsable inscripto</option>
				<option value="Consumidor final" {if ($smarty.post.condicion_fiscal == 'Consumidor final')} selected="selected" {/if}>Consumidor final</option>
				<option value="Exento" {if ($smarty.post.condicion_fiscal == 'Exento')} selected="selected" {/if}>Exento</option>
			</select>
        </div>					            
    </div>
{/if}

This looks perfect in the front office, but in the backoffice not know how to change this because it looks something like this (other than the select above)

 

in file AdminAddressesController.php ( override/controllers/admin/ )

array(
    'type' => 'select',
    'label' => $this->l('Condicion Fiscal'),
    'name' => 'condicion_fiscal',
    'required' => true,
    'col' => '4',
	'hint' => $this->l('Some custom text!')
),

country selector looks something like:

$temp_fields[] = array(
	'type' => 'select',
	'label' => $this->l('Country'),
	'name' => 'id_country',
	'required' => in_array('Country:name', $required_fields) || in_array('country', $required_fields),
	'col' => '4',
	'default_value' => (int)$this->context->country->id,
	'options' => array(
		'query' => Country::getCountries($this->context->language->id),
		'id' => 'id_country',
		'name' => 'name'
	)
);
This is an array, which can not be copied.
 
How could it? I come from wordpress and do not know well format prestashop.
 
I hope you can help me, thank you!

 

Edited by CriterioNet (see edit history)
Link to comment
Share on other sites

You shouldn't use words as values, especially if split with a space

Try with

 

"something"

another_value"

 

etc.

 

Use the underscore instead.

Anyway it could even work with it, but did you add that condicion_fiscal as new property of the address object? And to the database of course

Link to comment
Share on other sites

You shouldn't use words as values, especially if split with a space

Try with

 

"something"

another_value"

 

etc.

 

Use the underscore instead.

Anyway it could even work with it, but did you add that condicion_fiscal as new property of the address object? And to the database of course

 

is correct as I did in address.tpl?
 
And AdminAddressesController.php ( override/controllers/admin/ ) as it would have to do? I imagine something like this:
$temp_fields[] = array(
	'type' => 'select',
	'label' => $this->l('Condicion Fiscal'),
	'name' => 'id_country',
	'required' => true,
	'col' => '4',
	'default_value' => '-',
	'options' => array(
		'query' => array('Monotributista','Responsable inscripto','Consumidor final','Exento')
		'id' => 'id_country',
		'name' => 'name'
	)
);
Or as would have to be? I'm lost in this.
Link to comment
Share on other sites

I solved the code, searching I found something and modify it to my needs.

	array(
	    'type' => 'select',
	    'label' => $this->l('Condicion Fiscal'),
	    'name' => 'condicion_fiscal',
	    'required' => true,                            
	    'options' => array(
	                'query' => $options = array(
	                            array(
	                              'id_option' => 'Monotributista', // The value of the 'value' attribute of the <option> tag.
	                              'name' => 'Monotributista' // The value of the text content of the  <option> tag.
	                            ),
	                            array(
	                              'id_option' => 'Responsable inscripto',
	                              'name' => 'Responsable inscripto'
	                            ),
	                            array(
	                              'id_option' => 'Consumidor final',
	                              'name' => 'Consumidor final'
	                            ),
	                            array(
	                              'id_option' => 'Exento',
	                              'name' => 'Exento'
	                            ),
	                ),
	                'id' => 'id_option',
	                'name' => 'name' 
	               )
	),

But still have a problem Adress.tpl the selector value is null, apparently does not bring the data from the db:

 

BC509FAAD.jpg

 

This is the code:

<div id="condicion_fiscal">					        	
    <div class="required form-group selector2">
		<label for="condicion_fiscal" class="i-other f-label">{l s='Condicion Fiscal'} <sup>*</sup></label>
		<select name="condicion_fiscal" id="condicion_fiscal" class="form-control">
			<option value="">-</option>
			<option value="Monotributista" {if ($smarty.post.condicion_fiscal == 'Monotributista')} selected="selected" {/if}>Monotributista</option>
			<option value="Responsable inscripto" {if ($smarty.post.condicion_fiscal == 'Responsable inscripto')} selected="selected" {/if}>Responsable inscripto</option>
			<option value="Consumidor final" {if ($smarty.post.condicion_fiscal == 'Consumidor final')} selected="selected" {/if}>Consumidor final</option>
			<option value="Exento" {if ($smarty.post.condicion_fiscal == 'Exento')} selected="selected" {/if}>Exento</option>
		</select>
    </div>					            
</div>

Please I only need this step, happy when finished will arm a guide to extend his.

Edited by CriterioNet (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...