Files
wyczarujprezent.pl/modules/thecheckout/classes/CheckoutCustomerFormatter.php
Jacek Pyziak d39433f0d4 Add new payment and shipping parsers for various integrations
- Implemented Google Pay parser in bongooglepay.js
- Added Buckaroo 3 payment parser in buckaroo3.js
- Introduced DataTrans CW Mastercard parser in datatranscw.js
- Created DataTrans CW Credit Card parser in datatranscw_creditcard.js
- Developed DHL Assistant shipping parser in dhlassistant.js
- Added Estimated Delivery parser in estimateddelivery.js
- Implemented Floapay payment parser in floapay.js
- Created FS Pickup at Store shipping parser in fspickupatstore.js
- Developed Generic Iframe parser in generic_iframe_parser.js
- Added Geodis Officiel shipping parser in geodisofficiel.js
- Implemented Glob Kurier module shipping parser in globkuriermodule.js
- Created Latvija Post Express Pickup Terminal parser in latvijaspastsexpresspastspostterminalslv.js
- Developed LP Shipping parser in lpshipping.js
- Added Mijora Venipak parser in mijoravenipak.js
- Implemented Apple Pay parser in pm_applepay.js
- Created Przelewy24 payment parser in przelewy24.js
- Developed Pshugls shipping parser in pshugls.js
- Added Redsys Insite payment parser in redsysinsite.js
- Implemented Tpay payment parser in tpay.js
- Updated third-party integration documentation for FedEx DotCom
2025-08-04 23:10:27 +02:00

270 lines
8.7 KiB
PHP

<?php
/**
* 2007-2017 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 license@prestashop.com 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 <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_')) {
exit;
}
use Symfony\Component\Translation\TranslatorInterface;
class CheckoutCustomerFormatter implements FormFormatterInterface
{
private $translator;
private $language;
private $ask_for_birthdate = true;
private $ask_for_partner_optin = true;
private $partner_optin_is_required = false;
private $ask_for_password = true;
private $password_is_required = false;
private $ask_for_new_password = false;
private $id_gender_required = false;
private $birthday_required = false;
public function __construct(
TranslatorInterface $translator,
Language $language
) {
$this->translator = $translator;
$this->language = $language;
}
public function setBirthdayRequired($birthday_required)
{
$this->birthday_required = $birthday_required;
return $this;
}
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 setIdGenderRequired($id_gender_required)
{
$this->id_gender_required = $id_gender_required;
return $this;
}
public function getFormat()
{
$format = array();
$format['id_customer'] = (new FormField)
->setName('id_customer')
->setType('hidden');
$genderField = (new FormField)
->setName('id_gender')
->setType('radio-buttons')
->setLabel(
$this->translator->trans(
'Social title', array(), 'Shop.Forms.Labels'
)
)
->setRequired($this->id_gender_required);
foreach (Gender::getGenders($this->language->id) as $gender) {
$genderField->addAvailableValue($gender->id, $gender->name);
}
$format[$genderField->getName()] = $genderField;
$format['firstname'] = (new FormField)
->setName('firstname')
->setLabel(
$this->translator->trans(
'First name', array(), 'Shop.Forms.Labels'
)
)
->setRequired(true);
$format['lastname'] = (new FormField)
->setName('lastname')
->setLabel(
$this->translator->trans(
'Last name', array(), 'Shop.Forms.Labels'
)
)
->setRequired(true);
// if (Configuration::get('PS_B2B_ENABLE')) {
$format['company'] = (new FormField)
->setName('company')
->setType('text')
->setLabel($this->translator->trans(
'Company', array(), 'Shop.Forms.Labels'
));
$format['siret'] = (new FormField)
->setName('siret')
->setType('text')
->setLabel($this->translator->trans(
// Please localize this string with the applicable registration number type in your country. For example : "SIRET" in France and "Código fiscal" in Spain.
'Identification number', array(), 'Shop.Forms.Labels'
));
// }
$format['email'] = (new FormField)
->setName('email')
->setType('email')
->setLabel(
$this->translator->trans(
'Email', array(), 'Shop.Forms.Labels'
)
)
->setRequired(true);
if ($this->ask_for_password) {
$format['password'] = (new FormField)
->setName('password')
->setType('password')
->setLabel(
$this->translator->trans(
'Password', array(), 'Shop.Forms.Labels'
)
)
->setRequired($this->password_is_required)
->addConstraint('isPlaintextPassword');
}
if ($this->ask_for_new_password) {
$format['new_password'] = (new FormField)
->setName('new_password')
->setType('password')
->setLabel(
$this->translator->trans(
'New password', array(), 'Shop.Forms.Labels'
)
);
}
if ($this->ask_for_birthdate) {
$format['birthday'] = (new FormField)
->setName('birthday')
->setType('text')
->setLabel(
$this->translator->trans(
'Birthdate', array(), 'Shop.Forms.Labels'
)
)
->setRequired($this->birthday_required)
->addAvailableValue('placeholder', Tools::getDateFormat())
->addAvailableValue(
'comment',
$this->translator->trans('(E.g.: %date_format%)',
array('%date_format%' => Tools::formatDateStr('31 May 1970')), 'Shop.Forms.Help')
);
}
if ($this->ask_for_partner_optin) {
$format['optin'] = (new FormField)
->setName('optin')
->setType('checkbox')
->setLabel(
$this->translator->trans(
'Receive offers from our partners', array(), 'Shop.Theme.Customeraccount'
)
)
->setRequired($this->partner_optin_is_required);
}
$additionalCustomerFormFields = Hook::exec(
'additionalCustomerFormFields',
array('get-tc-required-checkboxes' => 1),
null,
true
);
if (is_array($additionalCustomerFormFields)) {
foreach ($additionalCustomerFormFields as $moduleName => $additionnalFormFields) {
if (!is_array($additionnalFormFields)) {
continue;
}
foreach ($additionnalFormFields as $formField) {
$formField->moduleName = $moduleName;
// For logged in customer, make 'account' fields non-required
$thisContext = Context::getContext();
if (isset($thisContext)
&& isset($thisContext->customer)
&& $thisContext->customer->isLogged()
&& !in_array($moduleName, array("thecheckout"))) {
$formField->setRequired(false);
}
$format[$moduleName . '_' . $formField->getName()] = $formField;
}
}
}
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;
}
}