Advertisement
Guest User

Error

a guest
Dec 26th, 2017
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.57 KB | None | 0 0
  1. <?php
  2. /**
  3. * 2007-2017 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * https://opensource.org/licenses/OSL-3.0
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2017 PrestaShop SA
  23. * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26.  
  27. use Symfony\Component\Translation\TranslatorInterface;
  28.  
  29. class CustomerFormatterCore implements FormFormatterInterface
  30. {
  31. private $translator;
  32. private $language;
  33.  
  34. private $ask_for_birthdate = true;
  35. private $ask_for_partner_optin = true;
  36. private $partner_optin_is_required = true;
  37. private $ask_for_password = true;
  38. private $password_is_required = true;
  39. private $ask_for_new_password = false;
  40.  
  41. public function __construct(
  42. TranslatorInterface $translator,
  43. Language $language
  44. ) {
  45. $this->translator = $translator;
  46. $this->language = $language;
  47. }
  48.  
  49. public function setAskForBirthdate($ask_for_birthdate)
  50. {
  51. $this->ask_for_birthdate = $ask_for_birthdate;
  52. return $this;
  53. }
  54.  
  55. public function setAskForPartnerOptin($ask_for_partner_optin)
  56. {
  57. $this->ask_for_partner_optin = $ask_for_partner_optin;
  58. return $this;
  59. }
  60.  
  61. public function setPartnerOptinRequired($partner_optin_is_required)
  62. {
  63. $this->partner_optin_is_required = $partner_optin_is_required;
  64. return $this;
  65. }
  66.  
  67. public function setAskForPassword($ask_for_password)
  68. {
  69. $this->ask_for_password = $ask_for_password;
  70. return $this;
  71. }
  72.  
  73. public function setAskForNewPassword($ask_for_new_password)
  74. {
  75. $this->ask_for_new_password = $ask_for_new_password;
  76. return $this;
  77. }
  78.  
  79. public function setPasswordRequired($password_is_required)
  80. {
  81. $this->password_is_required = $password_is_required;
  82. return $this;
  83. }
  84.  
  85. public function getFormat()
  86. {
  87. $format = [];
  88.  
  89. $format['id_customer'] = (new FormField)
  90. ->setName('id_customer')
  91. ->setType('hidden')
  92. ;
  93.  
  94. $genderField = (new FormField)
  95. ->setName('id_gender')
  96. ->setType('radio-buttons')
  97. ->setLabel(
  98. $this->translator->trans(
  99. 'Social title', [], 'Shop.Forms.Labels'
  100. )
  101. )
  102. ;
  103. foreach (Gender::getGenders($this->language->id) as $gender) {
  104. $genderField->addAvailableValue($gender->id, $gender->name);
  105. }
  106. $format[$genderField->getName()] = $genderField;
  107.  
  108. $format['firstname'] = (new FormField)
  109. ->setName('firstname')
  110. ->setLabel(
  111. $this->translator->trans(
  112. 'First name', [], 'Shop.Forms.Labels'
  113. )
  114. )
  115. ->setRequired(true)
  116. ;
  117.  
  118. $format['lastname'] = (new FormField)
  119. ->setName('lastname')
  120. ->setLabel(
  121. $this->translator->trans(
  122. 'Last name', [], 'Shop.Forms.Labels'
  123. )
  124. )
  125. ->setRequired(true)
  126. ;
  127.  
  128. if (Configuration::get('PS_B2B_ENABLE')) {
  129. $format['company'] = (new FormField)
  130. ->setName('company')
  131. ->setType('text')
  132. ->setLabel($this->translator->trans(
  133. 'Company', [], 'Shop.Forms.Labels'
  134. ));
  135. $format['siret'] = (new FormField)
  136. ->setName('siret')
  137. ->setType('text')
  138. ->setLabel($this->translator->trans(
  139. // Please localize this string with the applicable registration number type in your country. For example : "SIRET" in France and "C贸digo fiscal" in Spain.
  140. 'Identification number', [], 'Shop.Forms.Labels'
  141. ));
  142. }
  143.  
  144. $format['email'] = (new FormField)
  145. ->setName('email')
  146. ->setType('email')
  147. ->setLabel(
  148. $this->translator->trans(
  149. 'Email', [], 'Shop.Forms.Labels'
  150. )
  151. )
  152. ->setRequired(true)
  153. ;
  154.  
  155. $format['rodado'] = (new FormField)
  156. ->setName('rodado')
  157. ->setLabel(
  158. $this->translator->trans(
  159. 'Rodado', [], 'Shop.Forms.Labels'
  160. )
  161. )
  162. ->setRequired(true)
  163. ->addAvailableValue(
  164. 'placeholder',
  165. '00000000A'
  166. )
  167. ->setMaxLength(9)
  168. ->addAvailableValue(
  169. 'comment',
  170. '(Ejemplo: 00000000A)'
  171. )
  172. ;
  173.  
  174. $format['Tvuelta'] = (new FormField)
  175. ->setName('Tvuelta')
  176. ->setLabel(
  177. $this->translator->trans(
  178. 'Tiempo de vuelta', [], 'Shop.Forms.Labels'
  179. )
  180. )
  181. ->setRequired(false)
  182. ->addAvailableValue(
  183. 'placeholder',
  184. '00000000A'
  185. )
  186. ->setMaxLength(9)
  187. ->addAvailableValue(
  188. 'comment',
  189. '(Ejemplo: 00000000A)'
  190. )
  191. ;
  192.  
  193. $format['Circuito'] = (new FormField)
  194. ->setName('Circuito')
  195. ->setLabel(
  196. $this->translator->trans(
  197. 'Circuito', [], 'Shop.Forms.Labels'
  198. )
  199. )
  200. ->setRequired(false)
  201. ->addAvailableValue(
  202. 'placeholder',
  203. '00000000A'
  204. )
  205. ->setMaxLength(9)
  206. ->addAvailableValue(
  207. 'comment',
  208. '(Ejemplo: 00000000A)'
  209. )
  210. ;
  211.  
  212. $format['forfait'] = (new FormField)
  213. ->setName('forfait')
  214. ->setLabel(
  215. $this->translator->trans(
  216. 'Forfait o Licencia', [], 'Shop.Forms.Labels'
  217. )
  218. )
  219. ->setRequired(true)
  220. ->addAvailableValue(
  221. 'placeholder',
  222. '00000000A'
  223. )
  224. ->setMaxLength(30)
  225. ->addAvailableValue(
  226. 'comment',
  227. '(Ejemplo: 00000000A)'
  228. )
  229. ;
  230.  
  231. if ($this->ask_for_password) {
  232. $format['password'] = (new FormField)
  233. ->setName('password')
  234. ->setType('password')
  235. ->setLabel(
  236. $this->translator->trans(
  237. 'Password', [], 'Shop.Forms.Labels'
  238. )
  239. )
  240. ->setRequired($this->password_is_required)
  241. ;
  242. }
  243.  
  244. if ($this->ask_for_new_password) {
  245. $format['new_password'] = (new FormField)
  246. ->setName('new_password')
  247. ->setType('password')
  248. ->setLabel(
  249. $this->translator->trans(
  250. 'New password', [], 'Shop.Forms.Labels'
  251. )
  252. )
  253. ;
  254. }
  255.  
  256. if ($this->ask_for_birthdate) {
  257. $format['birthday'] = (new FormField)
  258. ->setName('birthday')
  259. ->setType('text')
  260. ->setLabel(
  261. $this->translator->trans(
  262. 'Birthdate', [], 'Shop.Forms.Labels'
  263. )
  264. )
  265. ->addAvailableValue('placeholder', Tools::getDateFormat())
  266. ->addAvailableValue(
  267. 'comment',
  268. $this->translator->trans('(E.g.: %date_format%)', array('%date_format%' => Tools::formatDateStr('31 May 1970')), 'Shop.Forms.Help')
  269. )
  270. ;
  271. }
  272.  
  273. if ($this->ask_for_partner_optin) {
  274. $format['optin'] = (new FormField)
  275. ->setName('optin')
  276. ->setType('checkbox')
  277. ->setLabel(
  278. $this->translator->trans(
  279. 'Receive offers from our partners', [], 'Shop.Theme.Customeraccount'
  280. )
  281. )
  282. ->setRequired($this->partner_optin_is_required)
  283. ;
  284. }
  285.  
  286. // ToDo, replace the hook exec with HookFinder when the associated PR will be merged
  287. $additionalCustomerFormFields = Hook::exec('additionalCustomerFormFields', array(), null, true);
  288.  
  289. if (is_array($additionalCustomerFormFields)) {
  290. foreach ($additionalCustomerFormFields as $moduleName => $additionnalFormFields) {
  291. foreach ($additionnalFormFields as $formField) {
  292. $formField->moduleName = $moduleName;
  293. $format[$moduleName.'_'.$formField->getName()] = $formField;
  294. }
  295. }
  296. }
  297.  
  298. // TODO: TVA etc.?
  299.  
  300. return $this->addConstraints($format);
  301. }
  302.  
  303. private function addConstraints(array $format)
  304. {
  305. $constraints = Customer::$definition['fields'];
  306.  
  307. foreach ($format as $field) {
  308. if (!empty($constraints[$field->getName()]['validate'])) {
  309. $field->addConstraint(
  310. $constraints[$field->getName()]['validate']
  311. );
  312. }
  313. }
  314.  
  315. return $format;
  316. }
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement