Skip to content

Commit b14d086

Browse files
committed
wip: Heavily refactor Location, Address and Marker objects and factories
1 parent 15025e4 commit b14d086

6 files changed

Lines changed: 61 additions & 18 deletions

File tree

Location/Address.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22

33
namespace Loki\Components\Location;
44

5-
class Address
5+
use Magento\Framework\DataObject;
6+
7+
class Address extends DataObject
68
{
79
public function __construct(
810
private readonly AddressRenderer $addressRenderer,
911
private readonly string $street,
1012
private readonly string $houseNumber,
13+
private readonly string $houseNumberAddition,
1114
private readonly string $postcode,
1215
private readonly string $city,
1316
private readonly string $countryId,
1417
private readonly ?float $latitude = null,
1518
private readonly ?float $longitude = null,
19+
private readonly string $phone = '',
1620
private readonly string $comment = '',
21+
private readonly string $company = '',
22+
array $data = []
1723
) {
24+
parent::__construct($data);
1825
}
1926

2027
public function getStreet(): string
@@ -61,4 +68,19 @@ public function getInnerHtml(): string
6168
{
6269
return $this->addressRenderer->getHtml($this);
6370
}
71+
72+
public function getCompany(): string
73+
{
74+
return $this->company;
75+
}
76+
77+
public function getHouseNumberAddition(): string
78+
{
79+
return $this->houseNumberAddition;
80+
}
81+
82+
public function getPhone(): string
83+
{
84+
return $this->phone;
85+
}
6486
}

Location/Address/BusinessHourSegment.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
namespace Loki\Components\Location\Address;
44

5-
class BusinessHourSegment
5+
use Magento\Framework\DataObject;
6+
7+
class BusinessHourSegment extends DataObject
68
{
79
public function __construct(
810
private readonly string $day,
911
private readonly string $openingHour,
1012
private readonly string $closingHour,
1113
private readonly string $comment = '',
14+
array $data = [],
1215
) {
16+
parent::__construct($data);
1317
}
1418

1519
public function getDay(): string

Location/Address/BusinessHours.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
namespace Loki\Components\Location\Address;
44

5-
class BusinessHours
5+
use Magento\Framework\DataObject;
6+
7+
class BusinessHours extends DataObject
68
{
79
private array $businessHourSegments = [];
810

911
public function __construct(
10-
private readonly BusinessHourSegmentFactory $businessHourSegmentFactory
12+
private readonly BusinessHourSegmentFactory $businessHourSegmentFactory,
13+
array $data = [],
1114
) {
15+
parent::__construct($data);
1216
}
1317

1418
public function addSegment(BusinessHourSegment $businessHourSegment): void

Location/AddressFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,30 @@ public function __construct(
1414
public function create(
1515
string $street,
1616
string $houseNumber,
17+
string $houseNumberAddition,
1718
string $postcode,
1819
string $city,
1920
string $countryId,
2021
?float $latitude = null,
2122
?float $longitude = null,
23+
string $phone = '',
2224
string $comment = '',
25+
string $company = '',
26+
array $data = [],
2327
): Address {
2428
return $this->objectManager->create(Address::class, [
2529
'street' => $street,
2630
'houseNumber' => $houseNumber,
31+
'houseNumberAddition' => $houseNumberAddition,
2732
'postcode' => $postcode,
2833
'city' => $city,
2934
'countryId' => $countryId,
3035
'latitude' => $latitude,
3136
'longitude' => $longitude,
37+
'phone' => $phone,
3238
'comment' => $comment,
39+
'company' => $company,
40+
'data' => $data,
3341
]);
3442
}
3543
}

Location/Location.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,37 @@
33
namespace Loki\Components\Location;
44

55
use Loki\Components\Location\Address\BusinessHours;
6+
use Magento\Framework\DataObject;
67

7-
class Location
8+
class Location extends DataObject
89
{
910
public function __construct(
10-
private readonly string $id,
11-
private readonly string $code,
12-
private readonly string $label,
13-
private readonly int $distance,
1411
private readonly Address $address,
1512
private readonly ?BusinessHours $businessHours = null,
13+
private readonly string $id = '',
14+
private readonly string $code = '',
15+
private readonly string $label = '',
16+
private readonly int $distance = 0,
1617
private readonly ?string $pickupFrom = null,
1718
private readonly ?int $price = null,
19+
array $data = []
1820
) {
21+
parent::__construct($data);
1922
}
2023

2124
public function getId(): string
2225
{
23-
return $this->id;
26+
return $this->id ?? $this->getLabel();
2427
}
2528

2629
public function getCode(): string
2730
{
28-
return $this->code;
31+
return $this->code ?? $this->getId();
2932
}
3033

3134
public function getLabel(): string
3235
{
33-
return $this->label;
36+
return $this->label ?? $this->address->getCompany();
3437
}
3538

3639
public function getDistance(): int

Location/LocationFactory.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@ public function __construct(
1313
}
1414

1515
public function create(
16-
string $id,
17-
string $code,
18-
string $label,
19-
int $distance,
2016
Address $address,
2117
?BusinessHours $businessHours = null,
18+
string $id = '',
19+
string $code = '',
20+
string $label = '',
21+
int $distance = 0,
2222
?string $pickupFrom = null,
2323
?int $price = null,
24+
array $data = [],
2425
): Location {
2526
return $this->objectManager->create(Location::class, [
27+
'address' => $address,
28+
'businessHours' => $businessHours,
2629
'id' => $id,
2730
'code' => $code,
2831
'label' => $label,
2932
'distance' => $distance,
30-
'address' => $address,
31-
'businessHours' => $businessHours,
3233
'pickupFrom' => $pickupFrom,
3334
'price' => $price,
35+
'data' => $data
3436
]);
3537
}
3638
}

0 commit comments

Comments
 (0)