commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
lib
commercetools-api
src
Models
Cart
EstimatedDeliveryModel.php
1
<?php
2
3
declare(strict_types=1);
9
namespace
Commercetools\Api\Models\Cart
;
10
11
use
Commercetools\Base\DateTimeImmutableCollection
;
12
use
Commercetools\Base\JsonObject
;
13
use
Commercetools\Base\JsonObjectModel
;
14
use
Commercetools\Base\MapperFactory
;
15
use DateTimeImmutable;
16
use stdClass;
17
21
final
class
EstimatedDeliveryModel
extends
JsonObjectModel
implements
EstimatedDelivery
22
{
27
protected
$from
;
28
33
protected
$until
;
34
35
39
public
function
__construct
(
40
?DateTimeImmutable
$from
=
null
,
41
?DateTimeImmutable
$until
=
null
42
) {
43
$this->from =
$from
;
44
$this->until =
$until
;
45
}
46
53
public
function
getFrom
()
54
{
55
if
(is_null($this->from)) {
57
$data = $this->
raw
(self::FIELD_FROM);
58
if
(is_null($data)) {
59
return
null
;
60
}
61
$data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
62
if
(
false
=== $data) {
63
return
null
;
64
}
65
$this->from = $data;
66
}
67
68
return
$this->from
;
69
}
70
78
public
function
getUntil
()
79
{
80
if
(is_null($this->until)) {
82
$data = $this->
raw
(self::FIELD_UNTIL);
83
if
(is_null($data)) {
84
return
null
;
85
}
86
$data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
87
if
(
false
=== $data) {
88
return
null
;
89
}
90
$this->until = $data;
91
}
92
93
return
$this->until
;
94
}
95
96
100
public
function
setFrom
(?DateTimeImmutable
$from
): void
101
{
102
$this->from =
$from
;
103
}
104
108
public
function
setUntil
(?DateTimeImmutable
$until
): void
109
{
110
$this->until =
$until
;
111
}
112
113
114
#[\ReturnTypeWillChange]
115
public
function
jsonSerialize
()
116
{
117
$data = $this->
toArray
();
118
if
(isset($data[
EstimatedDelivery::FIELD_FROM
]) && $data[
EstimatedDelivery::FIELD_FROM
] instanceof \DateTimeImmutable) {
119
$data[
EstimatedDelivery::FIELD_FROM
] = $data[
EstimatedDelivery::FIELD_FROM
]->setTimeZone(
new
\DateTimeZone(
'UTC'
))->format(
'c'
);
120
}
121
122
if
(isset($data[
EstimatedDelivery::FIELD_UNTIL
]) && $data[
EstimatedDelivery::FIELD_UNTIL
] instanceof \DateTimeImmutable) {
123
$data[
EstimatedDelivery::FIELD_UNTIL
] = $data[
EstimatedDelivery::FIELD_UNTIL
]->setTimeZone(
new
\DateTimeZone(
'UTC'
))->format(
'c'
);
124
}
125
return
(
object
) $data;
126
}
127
}
Commercetools\Api\Models\Cart\EstimatedDeliveryModel
Definition
EstimatedDeliveryModel.php:22
Commercetools\Api\Models\Cart\EstimatedDeliveryModel\setUntil
setUntil(?DateTimeImmutable $until)
Definition
EstimatedDeliveryModel.php:108
Commercetools\Api\Models\Cart\EstimatedDeliveryModel\jsonSerialize
jsonSerialize()
Definition
EstimatedDeliveryModel.php:115
Commercetools\Api\Models\Cart\EstimatedDeliveryModel\getUntil
getUntil()
Definition
EstimatedDeliveryModel.php:78
Commercetools\Api\Models\Cart\EstimatedDeliveryModel\__construct
__construct(?DateTimeImmutable $from=null, ?DateTimeImmutable $until=null)
Definition
EstimatedDeliveryModel.php:39
Commercetools\Api\Models\Cart\EstimatedDeliveryModel\$until
$until
Definition
EstimatedDeliveryModel.php:33
Commercetools\Api\Models\Cart\EstimatedDeliveryModel\$from
$from
Definition
EstimatedDeliveryModel.php:27
Commercetools\Api\Models\Cart\EstimatedDeliveryModel\getFrom
getFrom()
Definition
EstimatedDeliveryModel.php:53
Commercetools\Api\Models\Cart\EstimatedDeliveryModel\setFrom
setFrom(?DateTimeImmutable $from)
Definition
EstimatedDeliveryModel.php:100
Commercetools\Base\BaseJsonObject\raw
raw(string $field)
Definition
BaseJsonObject.php:57
Commercetools\Base\DateTimeImmutableCollection
Definition
DateTimeImmutableCollection.php:21
Commercetools\Base\JsonObjectModel
Definition
JsonObjectModel.php:15
Commercetools\Base\JsonObjectModel\toArray
toArray()
Definition
JsonObjectModel.php:32
Commercetools\Base\MapperFactory
Definition
MapperFactory.php:16
Commercetools\Api\Models\Cart\EstimatedDelivery
Definition
EstimatedDelivery.php:16
Commercetools\Api\Models\Cart\EstimatedDelivery\FIELD_UNTIL
const FIELD_UNTIL
Definition
EstimatedDelivery.php:18
Commercetools\Api\Models\Cart\EstimatedDelivery\FIELD_FROM
const FIELD_FROM
Definition
EstimatedDelivery.php:17
Commercetools\Base\JsonObject
Definition
JsonObject.php:15
Commercetools\Api\Models\Cart
Definition
AbsoluteAllocation.php:9
Generated by
1.9.8