Jump to content

Edit History

quendi

quendi

Dodałem kilka pól w adresie klienta, ale podczas wprowadzania wartości nie zapisują się w bazie danych. Jak ręcznie wpiszę w tabelę (ps_address - pola wszędzie nazywają się tak samo), to wszystko ładnie potem widać w panelu. Gdzie robię błąd? Chciałbym też później dodawać kolejne pozycje poprzez import CSV, ten przechodzi bez błędów, ale również nie zapisuje do bazy. Niżej nadpisane pliki (w override):

Address.php

<?php
class Address extends AddressCore
{
 
    public $nr_faktury;
	public $symb_dok;
	public $data-wyst;
	public $termin;
	public $sposob_platnosci;
	public $opoznienie;
	public $kwota_faktury;
	public $nnaleznosc;
	public $nzobowiazanie;
	public $nn_razem;
	public $nz_razem;
	public $saldo;
 
 
    public static $definition = array(
        'table' => 'address',
        'primary' => 'id_address',
        'fields' => array(
            'id_customer' =>         array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_manufacturer' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_supplier' =>         array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_warehouse' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_country' =>      array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
            'id_state' =>            array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'),
            'alias' =>               array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
            'company' =>             array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
            'lastname' =>            array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
            'firstname' =>           array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
            'vat_number' =>          array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
            'address1' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128),
            'address2' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128),
            'postcode' =>            array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12),
            'city' =>                array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64),
            'other' =>               array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300),
            'phone' =>               array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
            'phone_mobile' =>        array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
            'dni' =>                 array('type' => self::TYPE_STRING, 'validate' => 'isDniLite', 'size' => 16),
            'deleted' =>             array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
            'date_add' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false),
            'date_upd' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false),
            'nr_faktury' =>          array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'symb_dok' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'data-wyst' =>           array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'termin' =>              array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
            'sposob_platnosci' =>    array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'opoznienie' =>          array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'kwota_faktury' =>       array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'nnaleznosc' =>          array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'nzobowiazanie' =>       array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'nn_razem' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'nz_razem' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'saldo' =>               array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
		
 
        ),
    );
} 

AdminAddressesController.php

<?php
Class AdminAddressesController extends AdminAddressesControllerCore
{
 
 
    public function renderForm()
    {
        $this->fields_form = array(
            'legend' => array(
                'title' => $this->l('Addresses'),
                'icon' => 'icon-envelope-alt'
            ),
            'input' => array(
                array(
                    'type' => 'text_customer',
                    'label' => $this->l('Customer'),
                    'name' => 'id_customer',
                    'required' => false,
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Identification Number'),
                    'name' => 'dni',
                    'required' => false,
                    'col' => '4',
                    'hint' => $this->l('DNI / NIF / NIE')
                ),          
				array(
					'type' => 'text',
					'label' => $this->l('Nr faktury'),
					'name' => 'nr_faktury',
					'required' => false,
					
				),
				array(
    'type' => 'text',
    'label' => $this->l('Symbol dokumentu'),
    'name' => 'symb_dok',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Data wystawienia'),
    'name' => 'data_wyst',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Termin płatności'),
    'name' => 'termin',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Sposób płatności'),
    'name' => 'sposob_platnosci',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Opóźnienie'),
    'name' => 'opoznienie',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Kwota faktury'),
    'name' => 'kwota_faktury',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Niezapłacona należność'),
    'name' => 'nnaleznosc',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Niezapłacone zobowiązanie'),
    'name' => 'nzobowiazanie',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Razem należność'),
    'name' => 'nn_razem',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Razem zobowiazanie'),
    'name' => 'nz_razem',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Saldo'),
    'name' => 'saldo',
    'required' => false,
)
),
                array(
                    'type' => 'text',
                    'label' => $this->l('Address alias'),
                    'name' => 'alias',
                    'required' => true,
                    'col' => '4',
                    'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Home phone'),
                    'name' => 'phone',
                    'required' => false,
                    'col' => '4',
                    'hint' => Configuration::get('PS_ONE_PHONE_AT_LEAST') ? sprintf($this->l('You must register at least one phone number.')) : ''
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Mobile phone'),
                    'name' => 'phone_mobile',
                    'required' => false,
                    'col' => '4',
                    'hint' => Configuration::get('PS_ONE_PHONE_AT_LEAST') ? sprintf($this->l('You must register at least one phone number.')) : ''
                ),
                array(
                    'type' => 'textarea',
                    'label' => $this->l('Other'),
                    'name' => 'other',
                    'required' => false,
                    'cols' => 15,
                    'rows' => 3,
                    'hint' => $this->l('Forbidden characters:').' &lt;&gt;;=#{}'
                ),
            ),
            'submit' => array(
                'title' => $this->l('Save'),
            )
        );
        $id_customer = (int)Tools::getValue('id_customer');
        if (!$id_customer && Validate::isLoadedObject($this->object))
            $id_customer = $this->object->id_customer;
        if ($id_customer)
        {
            $customer = new Customer((int)$id_customer);
            $token_customer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id);
        }
 
        $this->tpl_form_vars = array(
            'customer' => isset($customer) ? $customer : null,
            'tokenCustomer' => isset ($token_customer) ? $token_customer : null
        );
 
        // Order address fields depending on country format
        $addresses_fields = $this->processAddressFormat();
        // we use  delivery address
        $addresses_fields = $addresses_fields['dlv_all_fields'];
 
        $temp_fields = array();
 
        foreach ($addresses_fields as $addr_field_item)
        {
            if ($addr_field_item == 'company')
            {
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('Company'),
                    'name' => 'company',
                    'required' => false,
                    'col' => '4',
                    'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
                );
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('VAT number'),
                    'col' => '2',
                    'name' => 'vat_number'
                );
            }
            else if ($addr_field_item == 'lastname')
            {
                if (isset($customer) &&
                    !Tools::isSubmit('submit'.strtoupper($this->table)) &&
                    Validate::isLoadedObject($customer) &&
                    !Validate::isLoadedObject($this->object))
                    $default_value = $customer->lastname;
                else
                    $default_value = '';
 
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('Last Name'),
                    'name' => 'lastname',
                    'required' => true,
                    'col' => '4',
                    'hint' => $this->l('Invalid characters:').' 0-9!&amp;lt;&amp;gt;,;?=+()@#"�{}_$%:',
                    'default_value' => $default_value,
                );
            }
            else if ($addr_field_item == 'firstname')
            {
                if (isset($customer) &&
                    !Tools::isSubmit('submit'.strtoupper($this->table)) &&
                    Validate::isLoadedObject($customer) &&
                    !Validate::isLoadedObject($this->object))
                    $default_value = $customer->firstname;
                else
                    $default_value = '';
 
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('First Name'),
                    'name' => 'firstname',
                    'required' => true,
                    'col' => '4',
                    'hint' => $this->l('Invalid characters:').' 0-9!&amp;lt;&amp;gt;,;?=+()@#"�{}_$%:',
                    'default_value' => $default_value,
                );
            }
            else if ($addr_field_item == 'address1')
            {
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('Address'),
                    'name' => 'address1',
                    'col' => '6',
                    'required' => true,
                );
            }
            else if ($addr_field_item == 'address2')
            {
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('Address').' (2)',
                    'name' => 'address2',
                    'col' => '6',
                    'required' => false,
                );
            }
            elseif ($addr_field_item == 'postcode')
            {
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('Zip/Postal Code'),
                    'name' => 'postcode',
                    'col' => '2',
                    'required' => true,
                );
            }
            else if ($addr_field_item == 'city')
            {
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('City'),
                    'name' => 'city',
                    'col' => '4',
                    'required' => true,
                );
            }
            else if ($addr_field_item == 'country' || $addr_field_item == 'Country:name')
            {
                $temp_fields[] = array(
                    'type' => 'select',
                    'label' => $this->l('Country'),
                    'name' => 'id_country',
                    'required' => false,
                    'col' => '4',
                    'default_value' => (int)$this->context->country->id,
                    'options' => array(
                        'query' => Country::getCountries($this->context->language->id),
                        'id' => 'id_country',
                        'name' => 'name'
                    )
                );
                $temp_fields[] = array(
                    'type' => 'select',
                    'label' => $this->l('State'),
                    'name' => 'id_state',
                    'required' => false,
                    'col' => '4',
                    'options' => array(
                        'query' => array(),
                        'id' => 'id_state',
                        'name' => 'name'
                    )
                );
            }
        }
 
        // merge address format with the rest of the form
        array_splice($this->fields_form['input'], 3, 0, $temp_fields);
 
        return AdminController::renderForm();
    }
     
}

Fragment AdminImportController.php

       case $this->entities[$this->l('Addresses')]:
                //Overwrite required_fields
                $this->required_fields = array(
                    'alias',
                    'lastname',
                    'firstname',
                    'address1',
                    'postcode',
                    'country',
                    'customer_email',
                    'city'
                );

                $this->available_fields = array(
                    'no' => array('label' => $this->l('Ignore this column')),
                    'id' => array('label' => $this->l('ID')),
                    'alias' => array('label' => $this->l('Alias *')),
                    'active' => array('label' => $this->l('Active  (0/1)')),
                    'customer_email' => array('label' => $this->l('Customer email *')),
                    'id_customer' => array('label' => $this->l('Customer ID')),
                    'manufacturer' => array('label' => $this->l('Manufacturer')),
                    'supplier' => array('label' => $this->l('Supplier')),
                    'company' => array('label' => $this->l('Company')),
                    'lastname' => array('label' => $this->l('Last Name *')),
                    'firstname' => array('label' => $this->l('First Name *')),
                    'address1' => array('label' => $this->l('Address 1 *')),
                    'address2' => array('label' => $this->l('Address 2')),
                    'postcode' => array('label' => $this->l('Zip/postal code *')),
                    'city' => array('label' => $this->l('City *')),
                    'country' => array('label' => $this->l('Country *')),
                    'state' => array('label' => $this->l('State')),
                    'other' => array('label' => $this->l('Other')),
                    'phone' => array('label' => $this->l('Phone')),
                    'phone_mobile' => array('label' => $this->l('Mobile Phone')),
                    'vat_number' => array('label' => $this->l('VAT number')),
                    'dni' => array('label' => $this->l('DNI/NIF/NIE')),
					'nr_faktury' => array('label' => $this->l('Nr faktury')),
					'symb_dok' => array('label' => $this->l('Symbol dokumentu')),
					'data_wyst' => array('label' => $this->l('Data wystawienia')),
					'termin' => array('label' => $this->l('Termin płatności')),
					'sposob_platnosci' => array('label' => $this->l('Sposób płatności')),
					'opoznienie' => array('label' => $this->l('Opóźnienie')),
					'kwota_faktury' => array('label' => $this->l('Kwota faktury')),
					'nnaleznosc' => array('label' => $this->l('Niezapł. należ.')),
					'nzobowiazanie' => array('label' => $this->l('Niezapł. zobow.')),
					'nn_razem' => array('label' => $this->l('Razem niezpł. należ.')),
					'nz_razem' => array('label' => $this->l('Razem niezpł. zobow.')),
					'saldo' => array('label' => $this->l('Saldo')),
                );

                self::$default_values = array(
                    'alias' => 'Alias',
                    'postcode' => 'X'
                );
            break;

 

quendi

quendi

Dodałem kilka pól w adresie klienta, ale nie zapisują się w bazie danych. Jak ręcznie wpiszę w tabelę (ps_address - pola wszędzie nazywają się tak samo), to wszystko ładnie potem widać w panelu. Gdzie robię błąd? Chciałbym też później dodawać kolejne pozycje poprzez import CSV, ten przechodzi bez błędów, ale również nie zapisuje do bazy. Niżej nadpisane pliki (w override):

Address.php

<?php
class Address extends AddressCore
{
 
    public $nr_faktury;
	public $symb_dok;
	public $data-wyst;
	public $termin;
	public $sposob_platnosci;
	public $opoznienie;
	public $kwota_faktury;
	public $nnaleznosc;
	public $nzobowiazanie;
	public $nn_razem;
	public $nz_razem;
	public $saldo;
 
 
    public static $definition = array(
        'table' => 'address',
        'primary' => 'id_address',
        'fields' => array(
            'id_customer' =>         array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_manufacturer' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_supplier' =>         array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_warehouse' =>        array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
            'id_country' =>      array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
            'id_state' =>            array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'),
            'alias' =>               array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
            'company' =>             array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
            'lastname' =>            array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
            'firstname' =>           array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),
            'vat_number' =>          array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
            'address1' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128),
            'address2' =>            array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128),
            'postcode' =>            array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12),
            'city' =>                array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64),
            'other' =>               array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300),
            'phone' =>               array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
            'phone_mobile' =>        array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
            'dni' =>                 array('type' => self::TYPE_STRING, 'validate' => 'isDniLite', 'size' => 16),
            'deleted' =>             array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
            'date_add' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false),
            'date_upd' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_post' => false),
            'nr_faktury' =>          array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'symb_dok' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'data-wyst' =>           array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'termin' =>              array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
            'sposob_platnosci' =>    array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'opoznienie' =>          array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'kwota_faktury' =>       array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'nnaleznosc' =>          array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'nzobowiazanie' =>       array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'nn_razem' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'nz_razem' =>            array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
			'saldo' =>               array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
		
 
        ),
    );
} 

AdminAddressesController.php

<?php
Class AdminAddressesController extends AdminAddressesControllerCore
{
 
 
    public function renderForm()
    {
        $this->fields_form = array(
            'legend' => array(
                'title' => $this->l('Addresses'),
                'icon' => 'icon-envelope-alt'
            ),
            'input' => array(
                array(
                    'type' => 'text_customer',
                    'label' => $this->l('Customer'),
                    'name' => 'id_customer',
                    'required' => false,
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Identification Number'),
                    'name' => 'dni',
                    'required' => false,
                    'col' => '4',
                    'hint' => $this->l('DNI / NIF / NIE')
                ),          
				array(
					'type' => 'text',
					'label' => $this->l('Nr faktury'),
					'name' => 'nr_faktury',
					'required' => false,
					
				),
				array(
    'type' => 'text',
    'label' => $this->l('Symbol dokumentu'),
    'name' => 'symb_dok',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Data wystawienia'),
    'name' => 'data_wyst',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Termin płatności'),
    'name' => 'termin',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Sposób płatności'),
    'name' => 'sposob_platnosci',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Opóźnienie'),
    'name' => 'opoznienie',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Kwota faktury'),
    'name' => 'kwota_faktury',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Niezapłacona należność'),
    'name' => 'nnaleznosc',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Niezapłacone zobowiązanie'),
    'name' => 'nzobowiazanie',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Razem należność'),
    'name' => 'nn_razem',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Razem zobowiazanie'),
    'name' => 'nz_razem',
    'required' => false,
)
),
				array(
    'type' => 'text',
    'label' => $this->l('Saldo'),
    'name' => 'saldo',
    'required' => false,
)
),
                array(
                    'type' => 'text',
                    'label' => $this->l('Address alias'),
                    'name' => 'alias',
                    'required' => true,
                    'col' => '4',
                    'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Home phone'),
                    'name' => 'phone',
                    'required' => false,
                    'col' => '4',
                    'hint' => Configuration::get('PS_ONE_PHONE_AT_LEAST') ? sprintf($this->l('You must register at least one phone number.')) : ''
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Mobile phone'),
                    'name' => 'phone_mobile',
                    'required' => false,
                    'col' => '4',
                    'hint' => Configuration::get('PS_ONE_PHONE_AT_LEAST') ? sprintf($this->l('You must register at least one phone number.')) : ''
                ),
                array(
                    'type' => 'textarea',
                    'label' => $this->l('Other'),
                    'name' => 'other',
                    'required' => false,
                    'cols' => 15,
                    'rows' => 3,
                    'hint' => $this->l('Forbidden characters:').' &lt;&gt;;=#{}'
                ),
            ),
            'submit' => array(
                'title' => $this->l('Save'),
            )
        );
        $id_customer = (int)Tools::getValue('id_customer');
        if (!$id_customer && Validate::isLoadedObject($this->object))
            $id_customer = $this->object->id_customer;
        if ($id_customer)
        {
            $customer = new Customer((int)$id_customer);
            $token_customer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id);
        }
 
        $this->tpl_form_vars = array(
            'customer' => isset($customer) ? $customer : null,
            'tokenCustomer' => isset ($token_customer) ? $token_customer : null
        );
 
        // Order address fields depending on country format
        $addresses_fields = $this->processAddressFormat();
        // we use  delivery address
        $addresses_fields = $addresses_fields['dlv_all_fields'];
 
        $temp_fields = array();
 
        foreach ($addresses_fields as $addr_field_item)
        {
            if ($addr_field_item == 'company')
            {
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('Company'),
                    'name' => 'company',
                    'required' => false,
                    'col' => '4',
                    'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
                );
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('VAT number'),
                    'col' => '2',
                    'name' => 'vat_number'
                );
            }
            else if ($addr_field_item == 'lastname')
            {
                if (isset($customer) &&
                    !Tools::isSubmit('submit'.strtoupper($this->table)) &&
                    Validate::isLoadedObject($customer) &&
                    !Validate::isLoadedObject($this->object))
                    $default_value = $customer->lastname;
                else
                    $default_value = '';
 
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('Last Name'),
                    'name' => 'lastname',
                    'required' => true,
                    'col' => '4',
                    'hint' => $this->l('Invalid characters:').' 0-9!&amp;lt;&amp;gt;,;?=+()@#"�{}_$%:',
                    'default_value' => $default_value,
                );
            }
            else if ($addr_field_item == 'firstname')
            {
                if (isset($customer) &&
                    !Tools::isSubmit('submit'.strtoupper($this->table)) &&
                    Validate::isLoadedObject($customer) &&
                    !Validate::isLoadedObject($this->object))
                    $default_value = $customer->firstname;
                else
                    $default_value = '';
 
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('First Name'),
                    'name' => 'firstname',
                    'required' => true,
                    'col' => '4',
                    'hint' => $this->l('Invalid characters:').' 0-9!&amp;lt;&amp;gt;,;?=+()@#"�{}_$%:',
                    'default_value' => $default_value,
                );
            }
            else if ($addr_field_item == 'address1')
            {
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('Address'),
                    'name' => 'address1',
                    'col' => '6',
                    'required' => true,
                );
            }
            else if ($addr_field_item == 'address2')
            {
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('Address').' (2)',
                    'name' => 'address2',
                    'col' => '6',
                    'required' => false,
                );
            }
            elseif ($addr_field_item == 'postcode')
            {
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('Zip/Postal Code'),
                    'name' => 'postcode',
                    'col' => '2',
                    'required' => true,
                );
            }
            else if ($addr_field_item == 'city')
            {
                $temp_fields[] = array(
                    'type' => 'text',
                    'label' => $this->l('City'),
                    'name' => 'city',
                    'col' => '4',
                    'required' => true,
                );
            }
            else if ($addr_field_item == 'country' || $addr_field_item == 'Country:name')
            {
                $temp_fields[] = array(
                    'type' => 'select',
                    'label' => $this->l('Country'),
                    'name' => 'id_country',
                    'required' => false,
                    'col' => '4',
                    'default_value' => (int)$this->context->country->id,
                    'options' => array(
                        'query' => Country::getCountries($this->context->language->id),
                        'id' => 'id_country',
                        'name' => 'name'
                    )
                );
                $temp_fields[] = array(
                    'type' => 'select',
                    'label' => $this->l('State'),
                    'name' => 'id_state',
                    'required' => false,
                    'col' => '4',
                    'options' => array(
                        'query' => array(),
                        'id' => 'id_state',
                        'name' => 'name'
                    )
                );
            }
        }
 
        // merge address format with the rest of the form
        array_splice($this->fields_form['input'], 3, 0, $temp_fields);
 
        return AdminController::renderForm();
    }
     
}

Fragment AdminImportController.php

       case $this->entities[$this->l('Addresses')]:
                //Overwrite required_fields
                $this->required_fields = array(
                    'alias',
                    'lastname',
                    'firstname',
                    'address1',
                    'postcode',
                    'country',
                    'customer_email',
                    'city'
                );

                $this->available_fields = array(
                    'no' => array('label' => $this->l('Ignore this column')),
                    'id' => array('label' => $this->l('ID')),
                    'alias' => array('label' => $this->l('Alias *')),
                    'active' => array('label' => $this->l('Active  (0/1)')),
                    'customer_email' => array('label' => $this->l('Customer email *')),
                    'id_customer' => array('label' => $this->l('Customer ID')),
                    'manufacturer' => array('label' => $this->l('Manufacturer')),
                    'supplier' => array('label' => $this->l('Supplier')),
                    'company' => array('label' => $this->l('Company')),
                    'lastname' => array('label' => $this->l('Last Name *')),
                    'firstname' => array('label' => $this->l('First Name *')),
                    'address1' => array('label' => $this->l('Address 1 *')),
                    'address2' => array('label' => $this->l('Address 2')),
                    'postcode' => array('label' => $this->l('Zip/postal code *')),
                    'city' => array('label' => $this->l('City *')),
                    'country' => array('label' => $this->l('Country *')),
                    'state' => array('label' => $this->l('State')),
                    'other' => array('label' => $this->l('Other')),
                    'phone' => array('label' => $this->l('Phone')),
                    'phone_mobile' => array('label' => $this->l('Mobile Phone')),
                    'vat_number' => array('label' => $this->l('VAT number')),
                    'dni' => array('label' => $this->l('DNI/NIF/NIE')),
					'nr_faktury' => array('label' => $this->l('Nr faktury')),
					'symb_dok' => array('label' => $this->l('Symbol dokumentu')),
					'data_wyst' => array('label' => $this->l('Data wystawienia')),
					'termin' => array('label' => $this->l('Termin płatności')),
					'sposob_platnosci' => array('label' => $this->l('Sposób płatności')),
					'opoznienie' => array('label' => $this->l('Opóźnienie')),
					'kwota_faktury' => array('label' => $this->l('Kwota faktury')),
					'nnaleznosc' => array('label' => $this->l('Niezapł. należ.')),
					'nzobowiazanie' => array('label' => $this->l('Niezapł. zobow.')),
					'nn_razem' => array('label' => $this->l('Razem niezpł. należ.')),
					'nz_razem' => array('label' => $this->l('Razem niezpł. zobow.')),
					'saldo' => array('label' => $this->l('Saldo')),
                );

                self::$default_values = array(
                    'alias' => 'Alias',
                    'postcode' => 'X'
                );
            break;

 

×
×
  • Create New...