Skip to content

Commit 6ab2562

Browse files
committed
refactor: Add numerous fields to Address-object
1 parent 3d49cf2 commit 6ab2562

2 files changed

Lines changed: 212 additions & 23 deletions

File tree

Location/Address.php

Lines changed: 161 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,125 @@ class Address extends DataObject
88
{
99
public function __construct(
1010
private readonly AddressRenderer $addressRenderer,
11-
private readonly string $street,
12-
private readonly string $houseNumber,
13-
private readonly string $houseNumberAddition,
14-
private readonly string $postcode,
15-
private readonly string $city,
16-
private readonly string $countryId,
17-
private readonly ?float $latitude = null,
18-
private readonly ?float $longitude = null,
19-
private readonly string $phone = '',
20-
private readonly string $comment = '',
21-
private readonly string $company = '',
11+
private string $street = '',
12+
private string $houseNumber = '',
13+
private string $houseNumberAddition = '',
14+
private string $postcode = '',
15+
private string $city = '',
16+
private string $region = '',
17+
private string $countryId = '',
18+
private ?float $latitude = null,
19+
private ?float $longitude = null,
20+
private string $telephone = '',
21+
private string $fax = '',
22+
private string $vatId = '',
23+
private string $comment = '',
24+
private string $company = '',
25+
private string $prefix = '',
26+
private string $firstname = '',
27+
private string $middlename = '',
28+
private string $lastname = '',
29+
private string $suffix = '',
2230
array $data = []
2331
) {
2432
parent::__construct($data);
2533
}
2634

35+
public function setStreet(string $street): void
36+
{
37+
$this->street = $street;
38+
}
39+
40+
public function setHouseNumber(string $houseNumber): void
41+
{
42+
$this->houseNumber = $houseNumber;
43+
}
44+
45+
public function setHouseNumberAddition(string $houseNumberAddition): void
46+
{
47+
$this->houseNumberAddition = $houseNumberAddition;
48+
}
49+
50+
public function setPostcode(string $postcode): void
51+
{
52+
$this->postcode = $postcode;
53+
}
54+
55+
public function setCity(string $city): void
56+
{
57+
$this->city = $city;
58+
}
59+
60+
public function setRegion(string $region): void
61+
{
62+
$this->region = $region;
63+
}
64+
65+
public function setCountryId(string $countryId): void
66+
{
67+
$this->countryId = $countryId;
68+
}
69+
70+
public function setLatitude(?float $latitude): void
71+
{
72+
$this->latitude = $latitude;
73+
}
74+
75+
public function setLongitude(?float $longitude): void
76+
{
77+
$this->longitude = $longitude;
78+
}
79+
80+
public function setTelephone(string $telephone): void
81+
{
82+
$this->telephone = $telephone;
83+
}
84+
85+
public function setFax(string $fax): void
86+
{
87+
$this->fax = $fax;
88+
}
89+
90+
public function setVatId(string $vatId): void
91+
{
92+
$this->vatId = $vatId;
93+
}
94+
95+
public function setComment(string $comment): void
96+
{
97+
$this->comment = $comment;
98+
}
99+
100+
public function setCompany(string $company): void
101+
{
102+
$this->company = $company;
103+
}
104+
105+
public function setPrefix(string $prefix): void
106+
{
107+
$this->prefix = $prefix;
108+
}
109+
110+
public function setFirstname(string $firstname): void
111+
{
112+
$this->firstname = $firstname;
113+
}
114+
115+
public function setMiddlename(string $middlename): void
116+
{
117+
$this->middlename = $middlename;
118+
}
119+
120+
public function setLastname(string $lastname): void
121+
{
122+
$this->lastname = $lastname;
123+
}
124+
125+
public function setSuffix(string $suffix): void
126+
{
127+
$this->suffix = $suffix;
128+
}
129+
27130
public function getStreet(): string
28131
{
29132
return $this->street;
@@ -64,6 +167,11 @@ public function getLongitude(): ?float
64167
return $this->longitude;
65168
}
66169

170+
public function getAddressLine(): string
171+
{
172+
return $this->addressRenderer->getLine($this);
173+
}
174+
67175
public function getInnerHtml(): string
68176
{
69177
return $this->addressRenderer->getHtml($this);
@@ -79,8 +187,48 @@ public function getHouseNumberAddition(): string
79187
return $this->houseNumberAddition;
80188
}
81189

82-
public function getPhone(): string
190+
public function getPrefix(): string
191+
{
192+
return $this->prefix;
193+
}
194+
195+
public function getFirstname(): string
196+
{
197+
return $this->firstname;
198+
}
199+
200+
public function getMiddlename(): string
201+
{
202+
return $this->middlename;
203+
}
204+
205+
public function getLastname(): string
206+
{
207+
return $this->lastname;
208+
}
209+
210+
public function getSuffix(): string
211+
{
212+
return $this->suffix;
213+
}
214+
215+
public function getRegion(): string
216+
{
217+
return $this->region;
218+
}
219+
220+
public function getTelephone(): string
221+
{
222+
return $this->telephone;
223+
}
224+
225+
public function getFax(): string
226+
{
227+
return $this->fax;
228+
}
229+
230+
public function getVatId(): string
83231
{
84-
return $this->phone;
232+
return $this->vatId;
85233
}
86234
}

Location/AddressFactory.php

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,82 @@
33
namespace Loki\Components\Location;
44

55
use Magento\Framework\ObjectManagerInterface;
6+
use Magento\Quote\Api\Data\AddressInterface;
67

78
class AddressFactory
89
{
910
public function __construct(
10-
private readonly ObjectManagerInterface $objectManager
11+
private readonly ObjectManagerInterface $objectManager,
12+
private readonly AddressParserComposite $addressParserComposite
1113
) {
1214
}
1315

1416
public function create(
15-
string $street,
16-
string $houseNumber,
17-
string $houseNumberAddition,
18-
string $postcode,
19-
string $city,
20-
string $countryId,
17+
string $street = '',
18+
string $houseNumber = '',
19+
string $houseNumberAddition = '',
20+
string $postcode = '',
21+
string $city = '',
22+
string $region = '',
23+
string $countryId = '',
2124
?float $latitude = null,
2225
?float $longitude = null,
23-
string $phone = '',
26+
string $telephone = '',
27+
string $fax = '',
28+
string $vatId = '',
2429
string $comment = '',
2530
string $company = '',
31+
string $prefix = '',
32+
string $firstname = '',
33+
string $middlename = '',
34+
string $lastname = '',
35+
string $suffix = '',
2636
array $data = [],
2737
): Address {
28-
return $this->objectManager->create(Address::class, [
38+
$address = $this->objectManager->create(Address::class, [
2939
'street' => $street,
3040
'houseNumber' => $houseNumber,
3141
'houseNumberAddition' => $houseNumberAddition,
3242
'postcode' => $postcode,
3343
'city' => $city,
44+
'region' => $region,
3445
'countryId' => $countryId,
3546
'latitude' => $latitude,
3647
'longitude' => $longitude,
37-
'phone' => $phone,
48+
'telephone' => $telephone,
49+
'fax' => $fax,
50+
'vatId' => $vatId,
3851
'comment' => $comment,
3952
'company' => $company,
53+
'prefix' => $prefix,
54+
'firstname' => $firstname,
55+
'middlename' => $middlename,
56+
'lastname' => $lastname,
57+
'suffix' => $suffix,
4058
'data' => $data,
4159
]);
60+
61+
return $this->addressParserComposite->parse($address);
62+
}
63+
64+
public function createFromQuoteAddress(AddressInterface $quoteAddress): Address
65+
{
66+
return $this->create(
67+
street: (string)$quoteAddress->getStreetLine(1),
68+
houseNumber: (string)$quoteAddress->getStreetLine(2),
69+
houseNumberAddition: (string)$quoteAddress->getStreetLine(3) ?? '',
70+
postcode: (string)$quoteAddress->getPostcode(),
71+
city: (string)$quoteAddress->getCity(),
72+
countryId: (string)$quoteAddress->getCountryId(),
73+
telephone: (string)$quoteAddress->getTelephone(),
74+
fax: (string)$quoteAddress->getFax(),
75+
vatId: (string)$quoteAddress->getVatId(),
76+
company: (string)$quoteAddress->getCompany(),
77+
prefix: (string)$quoteAddress->getPrefix(),
78+
firstname: (string)$quoteAddress->getFirstname(),
79+
middlename: (string)$quoteAddress->getMiddlename(),
80+
lastname: (string)$quoteAddress->getLastname(),
81+
suffix: (string)$quoteAddress->getSuffix(),
82+
);
4283
}
4384
}

0 commit comments

Comments
 (0)