<?php /** * 2007-2018 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * https://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2018 PrestaShop SA * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ use Symfony\Component\Translation\TranslatorInterface; class CustomerFormatterCore implements FormFormatterInterface { private $translator; private $language; private $ask_for_birthdate = true; private $ask_for_partner_optin = true; private $partner_optin_is_required = true; private $ask_for_password = true; private $password_is_required = true; private $ask_for_new_password = false; public function __construct( TranslatorInterface $translator, Language $language ) { $this->translator = $translator; $this->language = $language; } public function setAskForBirthdate($ask_for_birthdate) { $this->ask_for_birthdate = $ask_for_birthdate; return $this; } public function setAskForPartnerOptin($ask_for_partner_optin) { $this->ask_for_partner_optin = $ask_for_partner_optin; return $this; } public function setPartnerOptinRequired($partner_optin_is_required) { $this->partner_optin_is_required = $partner_optin_is_required; return $this; } public function setAskForPassword($ask_for_password) { $this->ask_for_password = $ask_for_password; return $this; } public function setAskForNewPassword($ask_for_new_password) { $this->ask_for_new_password = $ask_for_new_password; return $this; } public function setPasswordRequired($password_is_required) { $this->password_is_required = $password_is_required; return $this; } public function getFormat() { $format = []; $format['id_customer'] = (new FormField) ->setName('id_customer') ->setType('hidden') ; $format['nombre_negocio'] = (new FormField) ->setName('nombre_negocio') ->setType('text') ->setLabel( $this->translator->trans( 'Nombre del Negocio', [], 'Shop.Forms.Labels' ) ) ->setRequired(true) ; $format['firstname'] = (new FormField) ->setName('firstname') ->setLabel( $this->translator->trans( 'Nombre de contacto', [], 'Shop.Forms.Labels' ) ) ->setRequired(true) ; $format['atendido'] = (new FormField) ->setName('atendido') ->setType('text') ->setLabel( $this->translator->trans( 'Atendido por', [], 'Shop.Forms.Labels' ) ) ->setRequired(true); $genderField = (new FormField) ->setName('id_gender') ->setType('radio-buttons') ->setLabel( $this->translator->trans( 'Social title', [], 'Shop.Forms.Labels' ) ) ; foreach (Gender::getGenders($this->language->id) as $gender) { $genderField->addAvailableValue($gender->id, $gender->name); } $format['lastname'] = (new FormField) ->setName('lastname') ->setLabel( $this->translator->trans( 'Last name', [], 'Shop.Forms.Labels' ) ) ->setType('hidden') ->setRequired(true) ->setValue('Actualizar') ; if (Configuration::get('PS_B2B_ENABLE')) { $format['company'] = (new FormField) ->setName('company') ->setType('text') ->setType('hidden') ->setLabel($this->translator->trans( 'Company', [], 'Shop.Forms.Labels' )); } $format['email'] = (new FormField) ->setName('email') ->setType('email') ->setLabel( $this->translator->trans( 'Correo Electronico', [], 'Shop.Forms.Labels' ) ) ->setRequired(true) ; $format['tlf_movil'] = (new FormField) ->setName('tlf_movil') ->setType('text') ->setLabel( $this->translator->trans( 'Telefono Movil', [], 'Shop.Forms.Labels' ) ); $format['recomendado'] = (new FormField) ->setName('recomendado') ->setType('checkbox') ->setLabel( $this->translator->trans( 'Recomendado', [], 'Shop.Theme.Customeraccount' ) ) ; $format['google'] = (new FormField) ->setName('google') ->setType('checkbox') ->setLabel( $this->translator->trans( 'Google', [], 'Shop.Theme.Customeraccount' ) ) ; $format['facebook'] = (new FormField) ->setName('facebook') ->setType('checkbox') ->setLabel( $this->translator->trans( 'Facebook', [], 'Shop.Theme.Customeraccount' ) ) ; $format['folleto'] = (new FormField) ->setName('folleto') ->setType('checkbox') ->setLabel( $this->translator->trans( 'Buzoneo', [], 'Shop.Theme.Customeraccount' ) ) ; $format['telemarketing'] = (new FormField) ->setName('telemarketing') ->setType('checkbox') ->setLabel( $this->translator->trans( 'Telemarketing', [], 'Shop.Theme.Customeraccount' ) ) ; $format['visita'] = (new FormField) ->setName('visita') ->setType('checkbox') ->setLabel( $this->translator->trans( 'Visita', [], 'Shop.Theme.Customeraccount' ) ) ; $format['violocal'] = (new FormField) ->setName('violocal') ->setType('checkbox') ->setLabel( $this->translator->trans( 'Vio el local', [], 'Shop.Theme.Customeraccount' ) ) ; $format['tlf_fijo'] = (new FormField) ->setName('tlf_fijo') ->setType('text') ->setLabel( $this->translator->trans( 'Telefono Fijo', [], 'Shop.Forms.Labels' ) ); $format['direccion_negocio'] = (new FormField) ->setName('direccion_negocio') ->setType('text') ->setLabel($this->translator->trans('Direccion del Negocio', [], 'Shop.Forms.Labels')); $format['codigo_postal_negocio'] = (new FormField) ->setName('codigo_postal_negocio') ->setType('text') ->setLabel($this->translator->trans('Codigo posta del Negocio', [], 'Shop.Forms.Labels')); $format['localidad_negocio'] = (new FormField) ->setName('localidad_negocio') ->setType('text') ->setLabel($this->translator->trans('Localidad del Negocio', [], 'Shop.Forms.Labels')); $format['provincia_negocio'] = (new FormField) ->setName('provincia_negocio') ->setType('text') ->setLabel($this->translator->trans('Provincia del Negocio', [], 'Shop.Forms.Labels')); $format['contacto1'] = (new FormField) ->setName('contacto1') ->setType('text') ->setLabel($this->translator->trans('Contacto 2', [], 'Shop.Forms.Labels')); $format['telefono1'] = (new FormField) ->setName('telefono1') ->setType('text') ->setLabel($this->translator->trans('Telefono 2', [], 'Shop.Forms.Labels')); $format['mail1'] = (new FormField) ->setName('mail1') ->setType('mail') ->setLabel($this->translator->trans('Correo Electronico 2', [], 'Shop.Forms.Labels')); if ($this->ask_for_password) { $format['password'] = (new FormField) ->setName('password') ->setType('text') ->setValue('12345') ->setType('hidden') ->setLabel( $this->translator->trans( 'Password', [], 'Shop.Forms.Labels' ) ) ; } if ($this->ask_for_new_password) { $format['rason_social'] = (new FormField) ->setName('rason_social') ->setType('text') ->setLabel($this->translator->trans('Razón social', [], 'Shop.Forms.Labels')); $format['cif'] = (new FormField) ->setName('cif') ->setType('text') ->setLabel($this->translator->trans('CIF', [], 'Shop.Forms.Labels')); $format['direccion_fiscal'] = (new FormField) ->setName('direccion_fiscal') ->setType('text') ->setLabel($this->translator->trans('Direccion Fiscal', [], 'Shop.Forms.Labels')); $format['codigo_postal_fiscal'] = (new FormField) ->setName('codigo_postal_fiscal') ->setType('text') ->setLabel($this->translator->trans('Codigo postal Fiscal', [], 'Shop.Forms.Labels')); $format['localidad_fiscal'] = (new FormField) ->setName('localidad_fiscal') ->setType('text') ->setLabel($this->translator->trans('Localidad Fiscal', [], 'Shop.Forms.Labels')); $format['provincia_fiscal'] = (new FormField) ->setName('provincia_fiscal') ->setType('text') ->setLabel($this->translator->trans('Provincia Fiscal', [], 'Shop.Forms.Labels')); $format['contacto2'] = (new FormField) ->setName('contacto2') ->setType('text') ->setLabel($this->translator->trans('Contacto 3', [], 'Shop.Forms.Labels')); $format['telefono2'] = (new FormField) ->setName('telefono2') ->setType('text') ->setLabel($this->translator->trans('Telefono 3', [], 'Shop.Forms.Labels')); $format['mail2'] = (new FormField) ->setName('mail2') ->setType('mail') ->setLabel($this->translator->trans('Email 3', [], 'Shop.Forms.Labels')); $format['contacto3'] = (new FormField) ->setName('contacto3') ->setType('text') ->setLabel($this->translator->trans('Contacto 4', [], 'Shop.Forms.Labels')); $format['telefono3'] = (new FormField) ->setName('telefono3') ->setType('text') ->setLabel($this->translator->trans('Telefono 4', [], 'Shop.Forms.Labels')); $format['mail3'] = (new FormField) ->setName('mail3') ->setType('mail') ->setLabel($this->translator->trans('Email 4', [], 'Shop.Forms.Labels')); $format['contacto4'] = (new FormField) ->setName('contacto4') ->setType('text') ->setLabel($this->translator->trans('Contacto 5', [], 'Shop.Forms.Labels')); $format['telefono4'] = (new FormField) ->setName('telefono4') ->setType('text') ->setLabel($this->translator->trans('Telefono 5', [], 'Shop.Forms.Labels')); $format['mail4'] = (new FormField) ->setName('mail4') ->setType('mail') ->setLabel($this->translator->trans('Email 5', [], 'Shop.Forms.Labels')); $format['contacto5'] = (new FormField) ->setName('contacto5') ->setType('text') ->setLabel($this->translator->trans('Contacto 6', [], 'Shop.Forms.Labels')); $format['telefono5'] = (new FormField) ->setName('telefono5') ->setType('text') ->setLabel($this->translator->trans('Telefono 6', [], 'Shop.Forms.Labels')); $format['mail5'] = (new FormField) ->setName('mail5') ->setType('mail') ->setLabel($this->translator->trans('Email 6', [], 'Shop.Forms.Labels')); $format['new_password'] = (new FormField) ->setName('new_password') ->setType('password') ->setType('hidden') ->setLabel( $this->translator->trans( 'New password', [], 'Shop.Forms.Labels' ) ) ; } // ToDo, replace the hook exec with HookFinder when the associated PR will be merged $additionalCustomerFormFields = Hook::exec('additionalCustomerFormFields', array(), null, true); // TODO: TVA etc.? return $this->addConstraints($format); } private function addConstraints(array $format) { $constraints = Customer::$definition['fields']; foreach ($format as $field) { if (!empty($constraints[$field->getName()]['validate'])) { $field->addConstraint( $constraints[$field->getName()]['validate'] ); } } return $format; } }