public static
getAddressDataOutput
(mixed $data, mixed $fields, mixed $user, mixed $guestUser = 0)
public static function getAddressDataOutput($data, $fields, $user, $guestUser = 0)
{
$s = PhocacartRenderStyle::getStyles();
$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
$bNameO = '';
// join first, middle, last name and degree
$sNameO = '';
// join first, middle, last name and degree
$o['bregion'] = '';
// Return for shipping method (save database query)
$o['bcountry'] = '';
// Return for shipping method (save database query)
$o['bzip'] = '';
// Return for shipping method (save database query)
$o['sregion'] = '';
// Return for shipping method (save database query)
$o['scountry'] = '';
// Return for shipping method (save database query)
$o['szip'] = '';
// Return for shipping method (save database query)
// ba_sa = 0: billing and shipping addresses are NOT the same
// ba_sa = 1: billing and shipping addresses are same (don't check shipping fields)
if (empty($data[0])) {
// BILLING
// no billing return false
// No shipping data so test if we want any shipping data at all
$fI = new PhocacartFormItems();
$active = $fI->isFormFieldActive('billing');
if ($active) {
// there is active some form field, so vendor asks for some field but nothing was filled in
$o['filled'] = 0;
return $o;
}
} else {
if (!empty($data[0]) && isset($data[0]->ba_sa) && $data[0]->ba_sa == 0 && isset($data[0]->type) && $data[0]->type == 0 && empty($data[1])) {
// SHIPPING
// In words - we have billing data, so we check if billing data are the same like shipping (ba_sa = 1)
// If not then we check if we have shipping data, if not return false
// And check if array 0 is really billing - array 0 (first array) cannot be shpping as we order it by type ASC in db query
// type = 0 ... billing, type = 1 ... shipping
// No shipping data so test if we want any shipping data at all
$fI = new PhocacartFormItems();
$active = $fI->isFormFieldActive('shipping');
if ($active) {
// there is active some form field, so vendor asks for some field but nothing was filled in
$o['filled'] = 0;
return $o;
}
}
}
// Billing the same like shipping
if (isset($data[0]->ba_sa) && $data[0]->ba_sa == 1) {
$o['bsch'] = 1;
}
if (!empty($fields)) {
foreach ($fields as $k => $v) {
if ($v->display_billing == 1) {
$field = (string) $v->title;
if (isset($data[0]->{$field})) {
$value = $data[0]->{$field};
if ($v->required == 1 && $value == '') {
$o['filled'] = 0;
return $o;
//Don't check and list any other, form it not complete
}
if ($v->title == 'email' && $guestUser == 0) {
$value = $user->email;
}
if ($v->title == 'name_first' || $v->title == 'name_middle' || $v->title == 'name_last' || $v->title == 'name_degree') {
$bNameO .= $value . ' ';
} else {
if ($v->title == 'country') {
$o['bcountry'] = (int) $value;
// Return region and country
$countryTitle = isset($data[0]->countrytitle) ? $data[0]->countrytitle : PhocacartCountry::getCountryById((int) $value);
$o['b'] .= '<div class="' . $s['c']['col.xs12.sm12.md12'] . '">' . $countryTitle . '</div>';
} else {
if ($v->title == 'region') {
$o['bregion'] = (int) $value;
// Return region and country
$regionTitle = isset($data[0]->regiontitle) ? $data[0]->regiontitle : PhocacartRegion::getRegionById((int) $value);
$o['b'] .= '<div class="' . $s['c']['col.xs12.sm12.md12'] . '">' . $regionTitle . '</div>';
} else {
if ($v->title == 'zip') {
$o['bzip'] = $value;
// Return region and country or zip
$o['b'] .= '<div class="' . $s['c']['col.xs12.sm12.md12'] . '">' . $value . '</div>';
} else {
$o['b'] .= '<div class="' . $s['c']['col.xs12.sm12.md12'] . '">' . $value . '</div>';
}
}
}
}
}
}
if ($v->display_shipping == 1) {
$field = (string) $v->title;
if (isset($data[1]->{$field})) {
$value = $data[1]->{$field};
if ($v->required == 1 && $value == '' && $data[0]->ba_sa == 0 && $data[1]->ba_sa == 0) {
$o['filled'] = 0;
return $o;
//Don't check and list any other, form it not complete
}
if ($v->title == 'email' && $guestUser == 0) {
$value = $user->email;
}
if ($v->title == 'name_first' || $v->title == 'name_middle' || $v->title == 'name_last' || $v->title == 'name_degree') {
$sNameO .= $value . ' ';
} else {
if ($v->title == 'country') {
$o['scountry'] = (int) $value;
// Return region and country
$countryTitle = isset($data[1]->countrytitle) ? $data[1]->countrytitle : PhocacartCountry::getCountryById((int) $value);
$o['s'] .= '<div class="' . $s['c']['col.xs12.sm12.md12'] . '">' . $countryTitle . '</div>';
} else {
if ($v->title == 'region') {
$o['sregion'] = (int) $value;
// Return region and country
$regionTitle = isset($data[1]->regiontitle) ? $data[1]->regiontitle : PhocacartRegion::getRegionById((int) $value);
$o['s'] .= '<div class="' . $s['c']['col.xs12.sm12.md12'] . '">' . $regionTitle . '</div>';
} else {
if ($v->title == 'zip') {
$o['szip'] = $value;
// Return region and country or zip
$o['s'] .= '<div class="' . $s['c']['col.xs12.sm12.md12'] . '">' . $value . '</div>';
} else {
$o['s'] .= '<div class="' . $s['c']['col.xs12.sm12.md12'] . '">' . $value . '</div>';
}
}
}
}
}
}
}
if ($bNameO != '' && $o['b'] != '') {
$o['b'] = '<div class="' . $s['c']['col.xs12.sm12.md12'] . '">' . $bNameO . '</div>' . $o['b'];
}
if ($sNameO != '' && $o['s'] != '') {
$o['s'] = '<div class="' . $s['c']['col.xs12.sm12.md12'] . '">' . $sNameO . '</div>' . $o['s'];
}
}
return $o;
}