No l'ovverride di una classe si fá cosí te lo faccio al volo giá pronto da incollare nel nuovo file che avrá lo stesso nome CustomerAddressFormatter.php e che caricherai in /override/classes/form...segue codice!:
Attenzione io non l'ho provato sulla 1.7.6..per cui non garantisco che funzioni!!..te l'ho fatto ora senza test.
<?php
/*
* override per rendere il codice fiscale obbligatorio
* by Fabry 08/05/2020
*/
use Symfony\Component\Translation\TranslatorInterface;
class CustomerAddressFormatter extends CustomerAddressFormatterCore
{
public function getFormat()
{
$fields = AddressFormat::getOrderedAddressFields(
$this->country->id,
true,
true
);
$required = array_flip(AddressFormat::getFieldsRequired());
$format = [
'back' => (new FormField())
->setName('back')
->setType('hidden'),
'token' => (new FormField())
->setName('token')
->setType('hidden'),
'alias' => (new FormField())
->setName('alias')
->setLabel(
$this->getFieldLabel('alias')
),
];
foreach ($fields as $field) {
$formField = new FormField();
$formField->setName($field);
$fieldParts = explode(':', $field, 2);
if ($field === 'dni') {
if ($this-> country-> need_identification_number) {
$formField-> setRequired (true);
}
}
if (count($fieldParts) === 1) {
if ($field === 'postcode') {
if ($this->country->need_zip_code) {
$formField->setRequired(true);
}
} elseif ($field === 'phone') {
$formField->setType('tel');
} elseif ($field === 'dni' && null !== $this->country) {
if ($this->country->need_identification_number) {
$formField->setRequired(true);
}
}
} elseif (count($fieldParts) === 2) {
list($entity, $entityField) = $fieldParts;
// Fields specified using the Entity:field
// notation are actually references to other
// entities, so they should be displayed as a select
$formField->setType('select');
// Also, what we really want is the id of the linked entity
$formField->setName('id_' . strtolower($entity));
if ($entity === 'Country') {
$formField->setType('countrySelect');
$formField->setValue($this->country->id);
foreach ($this->availableCountries as $country) {
$formField->addAvailableValue(
$country['id_country'],
$country[$entityField]
);
}
} elseif ($entity === 'State') {
if ($this->country->contains_states) {
$states = State::getStatesByIdCountry($this->country->id, true);
foreach ($states as $state) {
$formField->addAvailableValue(
$state['id_state'],
$state[$entityField]
);
}
$formField->setRequired(true);
}
}
}
$formField->setLabel($this->getFieldLabel($field));
if (!$formField->isRequired()) {
// Only trust the $required array for fields
// that are not marked as required.
// $required doesn't have all the info, and fields
// may be required for other reasons than what
// AddressFormat::getFieldsRequired() says.
$formField->setRequired(
array_key_exists($field, $required)
);
}
$format[$formField->getName()] = $formField;
}
//To add the extra fields in address form
$additionalAddressFormFields = Hook::exec('additionalCustomerAddressFields', array(), null, true);
if (is_array($additionalAddressFormFields)) {
foreach ($additionalAddressFormFields as $moduleName => $additionnalFormFields) {
if (!is_array($additionnalFormFields)) {
continue;
}
foreach ($additionnalFormFields as $formField) {
$formField->moduleName = $moduleName;
$format[$moduleName . '_' . $formField->getName()] = $formField;
}
}
}
return $this->addConstraints(
$this->addMaxLength(
$format
)
);
}
}