Page 1 of 1

Customer Data v.s. Address Format

Posted: Mon Dec 19, 2022 3:47 am
by Moxamint
Hi,
In admin Customer Data, I can install new modules Company & Department, so that they are available for customers to fill in for registration. Company & Department also become part of customer address, for example:

Company
Department
My Name
My Street Address
My City, State Postpostcode
My Country

My questions are: Is there a way to change the format, such as listing Company & Department under My Name? Then this leads to my 2nd question: where in the core code parses the address format defined in the 'address_format' table? Maybe the code is where I can format the address the way I want?

Thanks in advance for any help.

Eddy

Re: Customer Data v.s. Address Format

Posted: Mon Dec 19, 2022 9:02 am
by ecartz
Moxamint wrote: Mon Dec 19, 2022 3:47 am where in the core code parses the address format defined in the 'address_format' table?
cd_traditional_address.php

If you need to add a new field (e.g. department), you could duplicate it as cd_moxamint_address.php and make edits to that. Uninstall the core module and install yours instead.

If you just need to reorder the fields, change them in the address_format table. E.g.

Code: Select all

INSERT INTO address_format VALUES (1, '$name$cr$company$cr$streets$cr$city, $postcode$cr$statecomma$country', '$city / $country');
INSERT INTO address_format VALUES (2, '$name$cr$company$cr$streets$cr$city, $state    $postcode$cr$country', '$city, $state / $country');
INSERT INTO address_format VALUES (3, '$name$cr$company$cr$streets$cr$city$cr$postcode - $statecomma$country', '$state / $country');
INSERT INTO address_format VALUES (4, '$name$cr$company$cr$streets$cr$city ($postcode)$cr$country', '$postcode / $country');
INSERT INTO address_format VALUES (5, '$name$cr$company$cr$streets$cr$postcode $city$cr$country', '$city / $country');
In some cases, you might modify both. For example, to add department:

Code: Select all

INSERT INTO address_format VALUES (1, '$name$cr$company$cr$department$cr$streets$cr$city, $postcode$cr$statecomma$country', '$city / $country');
INSERT INTO address_format VALUES (2, '$name$cr$company$cr$department$cr$streets$cr$city, $state    $postcode$cr$country', '$city, $state / $country');
INSERT INTO address_format VALUES (3, '$name$cr$company$cr$department$cr$streets$cr$city$cr$postcode - $statecomma$country', '$state / $country');
INSERT INTO address_format VALUES (4, '$name$cr$company$cr$department$cr$streets$cr$city ($postcode)$cr$country', '$postcode / $country');
INSERT INTO address_format VALUES (5, '$name$cr$company$cr$department$cr$streets$cr$postcode $city$cr$country', '$city / $country');
Then add

Code: Select all

$department = $address['department'] ?? '';
and remove lines 144-6 (which make $company appear first).

There might be some clever replacement for lines 91-7 and 109, like

Code: Select all

extract($address, EXTR_PREFIX_SAME | EXTR_REFS, 'address');
Then you could replace those eight lines with that and you wouldn't need to add a line for $department.

Re: Customer Data v.s. Address Format

Posted: Mon Dec 19, 2022 3:44 pm
by Moxamint
Thank you very much @ecartz !