|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2024 |
|
6
|
|
|
* @package MShop |
|
7
|
|
|
* @subpackage Coupon |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\MShop\Coupon\Item; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Default coupon item implementation. |
|
16
|
|
|
* |
|
17
|
|
|
* @package MShop |
|
18
|
|
|
* @subpackage Coupon |
|
19
|
|
|
*/ |
|
20
|
|
|
class Standard |
|
21
|
|
|
extends \Aimeos\MShop\Common\Item\Base |
|
22
|
|
|
implements \Aimeos\MShop\Coupon\Item\Iface |
|
23
|
|
|
{ |
|
24
|
|
|
use \Aimeos\MShop\Common\Item\Config\Traits; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Returns the label of the coupon item. |
|
29
|
|
|
* |
|
30
|
|
|
* @return string Name/label for this coupon |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getLabel() : string |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->get( 'coupon.label', '' ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Sets the label of the coupon item. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $name Coupon name, esp. short coupon class name |
|
42
|
|
|
* @return \Aimeos\MShop\Coupon\Item\Iface Coupon item for chaining method calls |
|
43
|
|
|
*/ |
|
44
|
|
|
public function setLabel( string $name ) : \Aimeos\MShop\Coupon\Item\Iface |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->set( 'coupon.label', $name ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns the starting point of time, in which the coupon is available. |
|
52
|
|
|
* |
|
53
|
|
|
* @return string|null ISO date in YYYY-MM-DD hh:mm:ss format |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getDateStart() : ?string |
|
56
|
|
|
{ |
|
57
|
|
|
$value = $this->get( 'coupon.datestart' ); |
|
58
|
|
|
return $value ? substr( $value, 0, 19 ) : null; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Sets a new starting point of time, in which the coupon is available. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $date New ISO date in YYYY-MM-DD hh:mm:ss format |
|
66
|
|
|
* @return \Aimeos\MShop\Coupon\Item\Iface Coupon item for chaining method calls |
|
67
|
|
|
*/ |
|
68
|
|
|
public function setDateStart( ?string $date ) : \Aimeos\MShop\Common\Item\Iface |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->set( 'coupon.datestart', $this->checkDateFormat( $date ) ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Returns the ending point of time, in which the coupon is available. |
|
76
|
|
|
* |
|
77
|
|
|
* @return string|null ISO date in YYYY-MM-DD hh:mm:ss format |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getDateEnd() : ?string |
|
80
|
|
|
{ |
|
81
|
|
|
$value = $this->get( 'coupon.dateend' ); |
|
82
|
|
|
return $value ? substr( $value, 0, 19 ) : null; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Sets a new ending point of time, in which the coupon is available. |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $date New ISO date in YYYY-MM-DD hh:mm:ss format |
|
90
|
|
|
* @return \Aimeos\MShop\Coupon\Item\Iface Coupon item for chaining method calls |
|
91
|
|
|
*/ |
|
92
|
|
|
public function setDateEnd( ?string $date ) : \Aimeos\MShop\Common\Item\Iface |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->set( 'coupon.dateend', $this->checkDateFormat( $date ) ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Returns the name of the provider class name to be used. |
|
100
|
|
|
* |
|
101
|
|
|
* @return string Returns the provider class name |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getProvider() : string |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->get( 'coupon.provider', '' ); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Set the name of the provider class name to be used. |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $provider Provider class name |
|
113
|
|
|
* @return \Aimeos\MShop\Coupon\Item\Iface Coupon item for chaining method calls |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setProvider( string $provider ) : \Aimeos\MShop\Coupon\Item\Iface |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->set( 'coupon.provider', $provider ); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Returns the configuration of the coupon item. |
|
123
|
|
|
* |
|
124
|
|
|
* @return array Custom configuration values |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getConfig() : array |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->get( 'coupon.config', [] ); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Sets the new configuration for the coupon item. |
|
134
|
|
|
* |
|
135
|
|
|
* @param array $config Custom configuration values |
|
136
|
|
|
* @return \Aimeos\MShop\Coupon\Item\Iface Coupon item for chaining method calls |
|
137
|
|
|
*/ |
|
138
|
|
|
public function setConfig( array $config ) : \Aimeos\MShop\Common\Item\Iface |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->set( 'coupon.config', $config ); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Returns the status of the coupon item. |
|
146
|
|
|
* |
|
147
|
|
|
* @return int Status of the item |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getStatus() : int |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->get( 'coupon.status', 1 ); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Sets the new status of the coupon item. |
|
157
|
|
|
* |
|
158
|
|
|
* @param int $status Status of the item |
|
159
|
|
|
* @return \Aimeos\MShop\Coupon\Item\Iface Coupon item for chaining method calls |
|
160
|
|
|
*/ |
|
161
|
|
|
public function setStatus( int $status ) : \Aimeos\MShop\Common\Item\Iface |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->set( 'coupon.status', $status ); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Tests if the item is available based on status, time, language and currency |
|
169
|
|
|
* |
|
170
|
|
|
* @return bool True if available, false if not |
|
171
|
|
|
*/ |
|
172
|
|
|
public function isAvailable() : bool |
|
173
|
|
|
{ |
|
174
|
|
|
return parent::isAvailable() && $this->getStatus() > 0 |
|
175
|
|
|
&& ( $this->getDateStart() === null || $this->getDateStart() < $this->date ) |
|
|
|
|
|
|
176
|
|
|
&& ( $this->getDateEnd() === null || $this->getDateEnd() > $this->date ); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
/* |
|
181
|
|
|
* Sets the item values from the given array and removes that entries from the list |
|
182
|
|
|
* |
|
183
|
|
|
* @param array &$list Associative list of item keys and their values |
|
184
|
|
|
* @param bool True to set private properties too, false for public only |
|
185
|
|
|
* @return \Aimeos\MShop\Coupon\Item\Iface Coupon item for chaining method calls |
|
186
|
|
|
*/ |
|
187
|
|
|
public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface |
|
188
|
|
|
{ |
|
189
|
|
|
$item = parent::fromArray( $list, $private ); |
|
190
|
|
|
|
|
191
|
|
|
foreach( $list as $key => $value ) |
|
192
|
|
|
{ |
|
193
|
|
|
switch( $key ) |
|
194
|
|
|
{ |
|
195
|
|
|
case 'coupon.label': $item = $item->setLabel( $value ); break; |
|
196
|
|
|
case 'coupon.datestart': $item = $item->setDateStart( $value ); break; |
|
197
|
|
|
case 'coupon.dateend': $item = $item->setDateEnd( $value ); break; |
|
198
|
|
|
case 'coupon.provider': $item = $item->setProvider( $value ); break; |
|
199
|
|
|
case 'coupon.status': $item = $item->setStatus( (int) $value ); break; |
|
200
|
|
|
case 'coupon.config': $item = $item->setConfig( (array) $value ); break; |
|
201
|
|
|
default: continue 2; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
unset( $list[$key] ); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
return $item; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Returns the item values as array. |
|
213
|
|
|
* |
|
214
|
|
|
* @param bool True to return private properties, false for public only |
|
215
|
|
|
* @return array Associative list of item properties and their values |
|
216
|
|
|
*/ |
|
217
|
|
|
public function toArray( bool $private = false ) : array |
|
218
|
|
|
{ |
|
219
|
|
|
$list = parent::toArray( $private ); |
|
220
|
|
|
|
|
221
|
|
|
$list['coupon.config'] = $this->getConfig(); |
|
222
|
|
|
$list['coupon.label'] = $this->getLabel(); |
|
223
|
|
|
$list['coupon.datestart'] = $this->getDateStart(); |
|
224
|
|
|
$list['coupon.dateend'] = $this->getDateEnd(); |
|
225
|
|
|
$list['coupon.provider'] = $this->getProvider(); |
|
226
|
|
|
$list['coupon.status'] = $this->getStatus(); |
|
227
|
|
|
|
|
228
|
|
|
return $list; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
} |
|
232
|
|
|
|