public static
getAddressDataForm
(mixed $form, mixed $fields, mixed $user, mixed $billingSuffix = '', mixed $shippingSuffix = '_phs', mixed $guestUser = 0)
public static function getAddressDataForm($form, $fields, $user, $billingSuffix = '', $shippingSuffix = '_phs', $guestUser = 0)
{
$o['b'] = '';
// Output Billing
$o['s'] = '';
// Output Shipping
$o['bsch'] = '';
// B S Checked? Is the billing address the same like shipping address
$o['filled'] = 1;
// Is every form input filled out
$app = Factory::getApplication();
$s = PhocacartRenderStyle::getStyles();
$baSa = $form->getValue('ba_sa');
// Setting "Delivery and billing addresses are the same" - enable or disabled
// This can be set for new users who didn't set the address yet and for gest only. Not for users how added the address as they made the choice which is saved and cannot be changed
$pC = PhocacartUtils::getComponentParameters();
$delivery_billing_same_enabled = $pC->get('delivery_billing_same_enabled', 0);
// 1) GUEST USER (no preference stored)
if ($guestUser > 0 && !PhocacartUserGuestuser::getAddress() && ($delivery_billing_same_enabled == 2 || $delivery_billing_same_enabled == 3)) {
$o['bsch'] = 'checked="checked"';
}
// 1) NEW LOGGED IN USER (no preference stored)
$userIdAddress = $form->getValue('id');
if (!(int) $userIdAddress > 0 && !$guestUser && ($delivery_billing_same_enabled == 1 || $delivery_billing_same_enabled == 3)) {
$o['bsch'] = 'checked="checked"';
}
// 3) STANDARD USER WHO ADDED ADDRESS AND PREFERENCES WERE SAVED - now this is only stored preference of the user
if ($baSa == 1) {
$o['bsch'] = 'checked="checked"';
}
// This feature is completely disabled
if ($delivery_billing_same_enabled == -1) {
$o['bsch'] = '';
}
if (!empty($fields)) {
foreach ($fields as $k => $v) {
if ($v->display_billing == 1 || $app->isClient('administrator') && $v->title == 'id') {
$value = $form->getValue($v->title);
// If form input is required but it is empty, this is wrong
if ($v->type == 'checkbox:text') {
// Checkbox field can have set default value e.g. to 1 - that in default it is enabled
// so such checkbox is set as checked as default so if we stored that it is disabled, we need to remove checked
if (!$value || $value == false || $value == 0 || $value == null || is_null($value)) {
$form->setFieldAttribute($v->title . $billingSuffix, 'checked', 'false');
}
}
if ($v->required == 1 && $value == '') {
$o['filled'] = 0;
}
if ($v->title == 'email' && $guestUser == 0) {
$form->setValue($v->title . $billingSuffix, null, $user->email);
}
if (!$app->isClient('administrator')) {
// change general xml class to general variable
$input = str_replace('form-control', $s['c']['inputbox.form-control'], $form->getInput($v->title . $billingSuffix));
$input = str_replace('form-select', $s['c']['inputbox.form-select'], $input);
$o['b'] .= '<div class="' . $s['c']['row'] . ' ' . $s['c']['form-group'] . '">';
$o['b'] .= '<div class="' . $s['c']['col.xs12.sm5.md5'] . ' ' . $s['c']['control-label'] . '">' . $form->getLabel($v->title . $billingSuffix) . '</div>';
$o['b'] .= '<div class="' . $s['c']['col.xs12.sm7.md7'] . '">' . $input . '</div>';
$o['b'] .= '</div>' . "\n";
/*
$form->setFieldAttribute($v->title, 'hint', ' ');
$o['b'] .= '<div class="'.$s['c']['row'].' '.$s['c']['form-group'].'">';
$o['b'] .= '<div class="'.$s['c']['col.xs12.sm12.md12'].'">'.$form->getInput($v->title . $billingSuffix) . '' .$form->getLabel($v->title . $billingSuffix).'</div>';
$o['b'] .= '</div>' . "\n";*/
} else {
// Admin uses obsolete bootstrap
$o['b'] .= '<div class="control-group">';
$o['b'] .= '<div class="control-label"><label>' . $form->getLabel($v->title . $billingSuffix) . '</label></div>';
$o['b'] .= '<div class="controls">' . $form->getInput($v->title . $billingSuffix) . '</div>';
$o['b'] .= '</div>' . "\n";
}
}
if ($v->display_shipping == 1 || $app->isClient('administrator') && $v->title == 'id') {
$value = $form->getValue($v->title . $shippingSuffix);
// Form input value is required but it is empty
if ($v->type == 'checkbox:text') {
// Checkbox field can have set default value e.g. to 1 - that in default it is enabled
// so such checkbox is set as checked as default so if we stored that it is disabled, we need to remove checked
if (!$value || $value == false || $value == 0 || $value == null || is_null($value)) {
$form->setFieldAttribute($v->title . $shippingSuffix, 'checked', 'false');
}
}
if ($v->required == 1 && $value == '' && $baSa == 0) {
// and we have set that the shipping address
$o['filled'] = 0;
// is other than billing
}
if ($v->title == 'email' && $guestUser == 0) {
$form->setValue($v->title . $shippingSuffix, null, $user->email);
}
if (!$app->isClient('administrator')) {
// change general xml class to general variable
$input = str_replace('form-control', $s['c']['inputbox.form-control'], $form->getInput($v->title . $shippingSuffix));
$input = str_replace('form-select', $s['c']['inputbox.form-select'], $input);
$o['s'] .= '<div class="' . $s['c']['row'] . ' ' . $s['c']['form-group'] . '">';
$o['s'] .= '<div class="' . $s['c']['col.xs12.sm5.md5'] . ' ' . $s['c']['control-label'] . '">' . $form->getLabel($v->title . $shippingSuffix) . '</div>';
$o['s'] .= '<div class="' . $s['c']['col.xs12.sm7.md7'] . '">' . $input . '</div>';
$o['s'] .= '</div>' . "\n";
/*
$form->setFieldAttribute($v->title, 'hint', ' ');
$o['s'] .= '<div class="'.$s['c']['row'].' '.$s['c']['form-group'].'">';
$o['s'] .= '<div class="'.$s['c']['col.xs12.sm12.md12'].'">'.$form->getInput($v->title . $shippingSuffix) . '' .$form->getLabel($v->title . $shippingSuffix).'</div>';
$o['s'] .= '</div>' . "\n";*/
} else {
// Admin uses obsolete bootstrap
$o['s'] .= '<div class="control-group">';
$o['s'] .= '<div class="control-label"><label>' . $form->getLabel($v->title . $shippingSuffix) . '</label></div>';
$o['s'] .= '<div class="controls">' . $form->getInput($v->title . $shippingSuffix) . '</div>';
$o['s'] .= '</div>' . "\n";
}
}
}
}
return $o;
}