1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2018 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Customer |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Customer\Manager; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Typo3 implementation of the customer class. |
17
|
|
|
* |
18
|
|
|
* @package MShop |
19
|
|
|
* @subpackage Customer |
20
|
|
|
*/ |
21
|
|
|
class Typo3 |
22
|
|
|
extends \Aimeos\MShop\Customer\Manager\Standard |
23
|
|
|
{ |
24
|
|
|
private $searchConfig = array( |
25
|
|
|
// customer.siteid is only for informational purpuse, not for filtering |
26
|
|
|
'customer.id' => array( |
27
|
|
|
'label' => 'Customer ID', |
28
|
|
|
'code' => 'customer.id', |
29
|
|
|
'internalcode' => 't3feu."uid"', |
30
|
|
|
'type' => 'integer', |
31
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
32
|
|
|
'public' => false, |
33
|
|
|
), |
34
|
|
|
'customer.code' => array( |
35
|
|
|
'label' => 'Customer username', |
36
|
|
|
'code' => 'customer.code', |
37
|
|
|
'internalcode' => 't3feu."username"', |
38
|
|
|
'type' => 'string', |
39
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR |
40
|
|
|
), |
41
|
|
|
'customer.label' => array( |
42
|
|
|
'label' => 'Customer name', |
43
|
|
|
'code' => 'customer.label', |
44
|
|
|
'internalcode' => 't3feu."name"', |
45
|
|
|
'type' => 'string', |
46
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR |
47
|
|
|
), |
48
|
|
|
'customer.salutation' => array( |
49
|
|
|
'label' => 'Customer salutation', |
50
|
|
|
'code' => 'customer.salutation', |
51
|
|
|
'internalcode' => 't3feu."gender"', |
52
|
|
|
'type' => 'string', |
53
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
54
|
|
|
), |
55
|
|
|
'customer.company'=> array( |
56
|
|
|
'label' => 'Customer company', |
57
|
|
|
'code' => 'customer.company', |
58
|
|
|
'internalcode' => 't3feu."company"', |
59
|
|
|
'type' => 'string', |
60
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
61
|
|
|
), |
62
|
|
|
'customer.vatid'=> array( |
63
|
|
|
'label' => 'Customer VAT ID', |
64
|
|
|
'code' => 'customer.vatid', |
65
|
|
|
'internalcode' => 't3feu."vatid"', |
66
|
|
|
'type' => 'string', |
67
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
68
|
|
|
), |
69
|
|
|
'customer.title' => array( |
70
|
|
|
'label' => 'Customer title', |
71
|
|
|
'code' => 'customer.title', |
72
|
|
|
'internalcode' => 't3feu."title"', |
73
|
|
|
'type' => 'string', |
74
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
75
|
|
|
), |
76
|
|
|
'customer.firstname' => array( |
77
|
|
|
'label' => 'Customer firstname', |
78
|
|
|
'code' => 'customer.firstname', |
79
|
|
|
'internalcode' => 't3feu."first_name"', |
80
|
|
|
'type' => 'string', |
81
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
82
|
|
|
), |
83
|
|
|
'customer.lastname' => array( |
84
|
|
|
'label' => 'Customer lastname', |
85
|
|
|
'code' => 'customer.lastname', |
86
|
|
|
'internalcode' => 't3feu."last_name"', |
87
|
|
|
'type' => 'string', |
88
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
89
|
|
|
), |
90
|
|
|
'customer.address1' => array( |
91
|
|
|
'label' => 'Customer address part one', |
92
|
|
|
'code' => 'customer.address1', |
93
|
|
|
'internalcode' => 't3feu."address"', |
94
|
|
|
'type' => 'string', |
95
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
96
|
|
|
), |
97
|
|
|
'customer.address2' => array( |
98
|
|
|
'label' => 'Customer address part two', |
99
|
|
|
'code' => 'customer.address2', |
100
|
|
|
'internalcode' => 't3feu."address"', |
101
|
|
|
'type' => 'string', |
102
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
103
|
|
|
), |
104
|
|
|
'customer.address3' => array( |
105
|
|
|
'label' => 'Customer address part three', |
106
|
|
|
'code' => 'customer.address3', |
107
|
|
|
'internalcode' => 't3feu."address"', |
108
|
|
|
'type' => 'string', |
109
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
110
|
|
|
), |
111
|
|
|
'customer.postal' => array( |
112
|
|
|
'label' => 'Customer postal', |
113
|
|
|
'code' => 'customer.postal', |
114
|
|
|
'internalcode' => 't3feu."zip"', |
115
|
|
|
'type' => 'string', |
116
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
117
|
|
|
), |
118
|
|
|
'customer.city' => array( |
119
|
|
|
'label' => 'Customer city', |
120
|
|
|
'code' => 'customer.city', |
121
|
|
|
'internalcode' => 't3feu."city"', |
122
|
|
|
'type' => 'string', |
123
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
124
|
|
|
), |
125
|
|
|
'customer.state' => array( |
126
|
|
|
'label' => 'Customer state', |
127
|
|
|
'code' => 'customer.state', |
128
|
|
|
'internalcode' => 't3feu."zone"', |
129
|
|
|
'type' => 'string', |
130
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
131
|
|
|
), |
132
|
|
|
'customer.languageid' => array( |
133
|
|
|
'label' => 'Customer language', |
134
|
|
|
'code' => 'customer.languageid', |
135
|
|
|
'internalcode' => 't3feu."language"', |
136
|
|
|
'type' => 'string', |
137
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
138
|
|
|
), |
139
|
|
|
'customer.countryid' => array( |
140
|
|
|
'label' => 'Customer country', |
141
|
|
|
'code' => 'customer.countryid', |
142
|
|
|
'internalcode' => 'tsc."cn_iso_2"', |
143
|
|
|
'type' => 'string', |
144
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
145
|
|
|
), |
146
|
|
|
'customer.telephone' => array( |
147
|
|
|
'label' => 'Customer telephone', |
148
|
|
|
'code' => 'customer.telephone', |
149
|
|
|
'internalcode' => 't3feu."telephone"', |
150
|
|
|
'type' => 'string', |
151
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
152
|
|
|
), |
153
|
|
|
'customer.email' => array( |
154
|
|
|
'label' => 'Customer email', |
155
|
|
|
'code' => 'customer.email', |
156
|
|
|
'internalcode' => 't3feu."email"', |
157
|
|
|
'type' => 'string', |
158
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
159
|
|
|
), |
160
|
|
|
'customer.telefax' => array( |
161
|
|
|
'label' => 'Customer telefax', |
162
|
|
|
'code' => 'customer.telefax', |
163
|
|
|
'internalcode' => 't3feu."fax"', |
164
|
|
|
'type' => 'string', |
165
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
166
|
|
|
), |
167
|
|
|
'customer.website' => array( |
168
|
|
|
'label' => 'Customer website', |
169
|
|
|
'code' => 'customer.website', |
170
|
|
|
'internalcode' => 't3feu."www"', |
171
|
|
|
'type' => 'string', |
172
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
173
|
|
|
), |
174
|
|
|
'customer.longitude' => array( |
175
|
|
|
'label' => 'Customer longitude', |
176
|
|
|
'code' => 'customer.longitude', |
177
|
|
|
'internalcode' => 't3feu."longitude"', |
178
|
|
|
'type' => 'float', |
179
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT, |
180
|
|
|
), |
181
|
|
|
'customer.latitude' => array( |
182
|
|
|
'label' => 'Customer latitude', |
183
|
|
|
'code' => 'customer.latitude', |
184
|
|
|
'internalcode' => 't3feu."latitude"', |
185
|
|
|
'type' => 'float', |
186
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT, |
187
|
|
|
), |
188
|
|
|
'customer.birthday' => array( |
189
|
|
|
'label' => 'Customer birthday', |
190
|
|
|
'code' => 'customer.birthday', |
191
|
|
|
'internalcode' => 't3feu."date_of_birth"', |
192
|
|
|
'type' => 'string', |
193
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
194
|
|
|
), |
195
|
|
|
'customer.password'=> array( |
196
|
|
|
'label' => 'Customer password', |
197
|
|
|
'code' => 'customer.password', |
198
|
|
|
'internalcode' => 't3feu."password"', |
199
|
|
|
'type' => 'string', |
200
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
201
|
|
|
), |
202
|
|
|
'customer.status'=> array( |
203
|
|
|
'label' => 'Customer status', |
204
|
|
|
'code' => 'customer.status', |
205
|
|
|
'internalcode' => 't3feu."disable"', |
206
|
|
|
'type' => 'integer', |
207
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT |
208
|
|
|
), |
209
|
|
|
'customer.dateverified'=> array( |
210
|
|
|
'label' => 'Customer verification date', |
211
|
|
|
'code' => 'customer.dateverified', |
212
|
|
|
'internalcode' => 't3feu."vdate"', |
213
|
|
|
'type' => 'date', |
214
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
215
|
|
|
), |
216
|
|
|
'customer.ctime'=> array( |
217
|
|
|
'label' => 'Customer creation time', |
218
|
|
|
'code' => 'customer.ctime', |
219
|
|
|
'internalcode' => 't3feu."crdate"', |
220
|
|
|
'type' => 'datetime', |
221
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
222
|
|
|
), |
223
|
|
|
'customer.mtime'=> array( |
224
|
|
|
'label' => 'Customer modification time', |
225
|
|
|
'code' => 'customer.mtime', |
226
|
|
|
'internalcode' => 't3feu."tstamp"', |
227
|
|
|
'type' => 'datetime', |
228
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
229
|
|
|
), |
230
|
|
|
// not available |
231
|
|
|
'customer.editor'=> array( |
232
|
|
|
'label' => 'Customer editor', |
233
|
|
|
'code' => 'customer.editor', |
234
|
|
|
'internalcode' => null, |
235
|
|
|
'type' => 'string', |
236
|
|
|
'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
237
|
|
|
), |
238
|
|
|
'customer:has' => array( |
239
|
|
|
'code' => 'customer:has()', |
240
|
|
|
'internalcode' => ':site :key AND t3feuli."id"', |
241
|
|
|
'internaldeps' => ['LEFT JOIN "fe_users_list" AS t3feuli ON ( t3feuli."parentid" = t3feu."uid" )'], |
242
|
|
|
'label' => 'Customer has list item, parameter(<domain>[,<list type>[,<reference ID>)]]', |
243
|
|
|
'type' => 'null', |
244
|
|
|
'internaltype' => 'null', |
245
|
|
|
'public' => false, |
246
|
|
|
), |
247
|
|
|
'customer:prop' => array( |
248
|
|
|
'code' => 'customer:prop()', |
249
|
|
|
'internalcode' => ':site :key AND t3feupr."id"', |
250
|
|
|
'internaldeps' => ['LEFT JOIN "fe_users_property" AS t3feupr ON ( t3feupr."parentid" = t3feu."uid" )'], |
251
|
|
|
'label' => 'Customer has property item, parameter(<property type>[,<language code>[,<property value>]])', |
252
|
|
|
'type' => 'null', |
253
|
|
|
'internaltype' => 'null', |
254
|
|
|
'public' => false, |
255
|
|
|
), |
256
|
|
|
); |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
private $plugins = []; |
260
|
|
|
private $reverse = []; |
261
|
|
|
private $helper; |
262
|
|
|
private $pid; |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Initializes a new customer manager object using the given context object. |
268
|
|
|
* |
269
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
270
|
|
|
*/ |
271
|
|
|
public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
272
|
|
|
{ |
273
|
|
|
parent::__construct( $context ); |
274
|
|
|
|
275
|
|
|
$plugin = new \Aimeos\MW\Criteria\Plugin\T3Salutation(); |
276
|
|
|
$this->plugins['customer.salutation'] = $this->reverse['gender'] = $plugin; |
277
|
|
|
|
278
|
|
|
$plugin = new \Aimeos\MW\Criteria\Plugin\T3Status(); |
279
|
|
|
$this->plugins['customer.status'] = $this->reverse['disable'] = $plugin; |
280
|
|
|
|
281
|
|
|
$plugin = new \Aimeos\MW\Criteria\Plugin\T3Date(); |
282
|
|
|
$this->plugins['customer.birthday'] = $this->reverse['date_of_birth'] = $plugin; |
283
|
|
|
|
284
|
|
|
$plugin = new \Aimeos\MW\Criteria\Plugin\T3Datetime(); |
285
|
|
|
$this->plugins['customer.ctime'] = $this->reverse['crdate'] = $plugin; |
286
|
|
|
$this->plugins['customer.mtime'] = $this->reverse['tstamp'] = $plugin; |
287
|
|
|
|
288
|
|
|
$this->pid = $context->getConfig()->get( 'mshop/customer/manager/typo3/pid-default', 0 ); |
289
|
|
|
|
290
|
|
|
|
291
|
|
|
$self = $this; |
292
|
|
|
$locale = $context->getLocale(); |
293
|
|
|
|
294
|
|
|
$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
295
|
|
|
$level = $context->getConfig()->get( 'mshop/customer/manager/sitemode', $level ); |
296
|
|
|
|
297
|
|
|
$siteIds = [$locale->getSiteId()]; |
298
|
|
|
|
299
|
|
|
if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_PATH ) { |
300
|
|
|
$siteIds = array_merge( $siteIds, $locale->getSitePath() ); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE ) { |
304
|
|
|
$siteIds = array_merge( $siteIds, $locale->getSiteSubTree() ); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
|
308
|
|
|
$this->searchConfig['customer:has']['function'] = function( &$source, array $params ) use ( $self, $siteIds ) { |
309
|
|
|
|
310
|
|
|
array_walk_recursive( $params, function( &$v ) { |
311
|
|
|
$v = trim( $v, '\'' ); |
312
|
|
|
} ); |
313
|
|
|
|
314
|
|
|
$keys = []; |
315
|
|
|
$params[1] = isset( $params[1] ) ? $params[1] : ''; |
316
|
|
|
$params[2] = isset( $params[2] ) ? $params[2] : ''; |
317
|
|
|
|
318
|
|
|
foreach( (array) $params[1] as $type ) { |
319
|
|
|
foreach( (array) $params[2] as $id ) { |
320
|
|
|
$keys[] = $params[0] . '|' . ( $type ? $type . '|' : '' ) . $id; |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
$sitestr = $siteIds ? $self->toExpression( 't3feuli."siteid"', $siteIds ) . ' AND' : ''; |
325
|
|
|
$keystr = $self->toExpression( 't3feuli."key"', $keys, $params[2] !== '' ? '==' : '=~' ); |
326
|
|
|
$source = str_replace( [':site', ':key'], [$sitestr, $keystr], $source ); |
327
|
|
|
|
328
|
|
|
return $params; |
329
|
|
|
}; |
330
|
|
|
|
331
|
|
|
|
332
|
|
|
$this->searchConfig['customer:prop']['function'] = function( &$source, array $params ) use ( $self, $siteIds ) { |
333
|
|
|
|
334
|
|
|
array_walk_recursive( $params, function( &$v ) { |
335
|
|
|
$v = trim( $v, '\'' ); |
336
|
|
|
} ); |
337
|
|
|
|
338
|
|
|
$keys = []; |
339
|
|
|
$params[1] = array_key_exists( 1, $params ) ? $params[1] : ''; |
340
|
|
|
$params[2] = isset( $params[2] ) ? $params[2] : ''; |
341
|
|
|
|
342
|
|
|
foreach( (array) $params[1] as $lang ) { |
343
|
|
|
foreach( (array) $params[2] as $id ) { |
344
|
|
|
$keys[] = $params[0] . '|' . ( $lang ? $lang . '|' : '' ) . ( $id !== '' ? md5( $id ) : '' ); |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
$sitestr = $siteIds ? $self->toExpression( 't3feupr."siteid"', $siteIds ) . ' AND' : ''; |
349
|
|
|
$keystr = $self->toExpression( 't3feupr."key"', $keys, $params[2] !== '' ? '==' : '=~' ); |
350
|
|
|
$source = str_replace( [':site', ':key'], [$sitestr, $keystr], $source ); |
351
|
|
|
|
352
|
|
|
return $params; |
353
|
|
|
}; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Removes old entries from the storage. |
359
|
|
|
* |
360
|
|
|
* @param array $siteids List of IDs for sites whose entries should be deleted |
361
|
|
|
*/ |
362
|
|
|
public function cleanup( array $siteids ) |
363
|
|
|
{ |
364
|
|
|
$path = 'mshop/customer/manager/submanagers'; |
365
|
|
|
$default = ['address', 'group', 'lists', 'property']; |
366
|
|
|
|
367
|
|
|
foreach( $this->getContext()->getConfig()->get( $path, $default ) as $domain ) { |
368
|
|
|
$this->getObject()->getSubManager( $domain )->cleanup( $siteids ); |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Creates a new empty item instance |
375
|
|
|
* |
376
|
|
|
* @param array $values Values the item should be initialized with |
377
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface New site item object |
378
|
|
|
*/ |
379
|
|
|
public function createItem( array $values = [] ) |
380
|
|
|
{ |
381
|
|
|
$values['customer.siteid'] = $this->getContext()->getLocale()->getSiteId(); |
382
|
|
|
return $this->createItemBase( $values ); |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Deletes a customer item object from the permanent storage. |
388
|
|
|
* |
389
|
|
|
* @param array $ids List of customer IDs |
390
|
|
|
*/ |
391
|
|
|
public function deleteItems( array $ids ) |
392
|
|
|
{ |
393
|
|
|
$path = 'mshop/customer/manager/typo3/delete'; |
394
|
|
|
$this->deleteItemsBase( $ids, $path, false, 'uid' ); |
395
|
|
|
|
396
|
|
|
$manager = $this->getObject()->getSubManager( 'address' ); |
397
|
|
|
$search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
398
|
|
|
$search->setConditions( $search->compare( '==', 'customer.address.parentid', $ids ) ); |
399
|
|
|
$manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
400
|
|
|
|
401
|
|
|
$manager = $this->getObject()->getSubManager( 'lists' ); |
402
|
|
|
$search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
403
|
|
|
$search->setConditions( $search->compare( '==', 'customer.lists.parentid', $ids ) ); |
404
|
|
|
$manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
405
|
|
|
|
406
|
|
|
$manager = $this->getObject()->getSubManager( 'property' ); |
407
|
|
|
$search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
408
|
|
|
$search->setConditions( $search->compare( '==', 'customer.property.parentid', $ids ) ); |
409
|
|
|
$manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* Returns the list attributes that can be used for searching. |
415
|
|
|
* |
416
|
|
|
* @param boolean $withsub Return also attributes of sub-managers if true |
417
|
|
|
* @return array List of attribute items implementing \Aimeos\MW\Criteria\Attribute\Iface |
418
|
|
|
*/ |
419
|
|
|
public function getSearchAttributes( $withsub = true ) |
420
|
|
|
{ |
421
|
|
|
$path = 'mshop/customer/manager/submanagers'; |
422
|
|
|
return $this->getSearchAttributesBase( $this->searchConfig, $path, ['address'], $withsub ); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Saves a customer item object. |
428
|
|
|
* |
429
|
|
|
* @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object |
430
|
|
|
* @param boolean $fetch True if the new ID should be returned in the item |
431
|
|
|
* @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID |
432
|
|
|
*/ |
433
|
|
|
public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true ) |
434
|
|
|
{ |
435
|
|
|
self::checkClass( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $item ); |
436
|
|
|
|
437
|
|
|
if( !$item->isModified() ) |
438
|
|
|
{ |
439
|
|
|
$item = $this->savePropertyItems( $item, 'customer' ); |
440
|
|
|
$item = $this->saveAddressItems( $item, 'customer' ); |
441
|
|
|
return $this->saveListItems( $item, 'customer' ); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
$context = $this->getContext(); |
445
|
|
|
$dbm = $context->getDatabaseManager(); |
446
|
|
|
$dbname = $this->getResourceName(); |
447
|
|
|
$conn = $dbm->acquire( $dbname ); |
448
|
|
|
|
449
|
|
|
try |
450
|
|
|
{ |
451
|
|
|
$id = $item->getId(); |
452
|
|
|
$billingAddress = $item->getPaymentAddress(); |
453
|
|
|
$columns = $this->getObject()->getSaveAttributes(); |
454
|
|
|
|
455
|
|
|
if( $id === null ) |
456
|
|
|
{ |
457
|
|
|
/** mshop/customer/manager/typo3/insert |
458
|
|
|
* Inserts a new customer record into the database table |
459
|
|
|
* |
460
|
|
|
* Items with no ID yet (i.e. the ID is NULL) will be created in |
461
|
|
|
* the database and the newly created ID retrieved afterwards |
462
|
|
|
* using the "newid" SQL statement. |
463
|
|
|
* |
464
|
|
|
* The SQL statement must be a string suitable for being used as |
465
|
|
|
* prepared statement. It must include question marks for binding |
466
|
|
|
* the values from the customer item to the statement before they are |
467
|
|
|
* sent to the database server. The number of question marks must |
468
|
|
|
* be the same as the number of columns listed in the INSERT |
469
|
|
|
* statement. The order of the columns must correspond to the |
470
|
|
|
* order in the saveItems() method, so the correct values are |
471
|
|
|
* bound to the columns. |
472
|
|
|
* |
473
|
|
|
* The SQL statement should conform to the ANSI standard to be |
474
|
|
|
* compatible with most relational database systems. This also |
475
|
|
|
* includes using double quotes for table and column names. |
476
|
|
|
* |
477
|
|
|
* @param string SQL statement for inserting records |
478
|
|
|
* @since 2014.03 |
479
|
|
|
* @category Developer |
480
|
|
|
* @see mshop/customer/manager/typo3/update |
481
|
|
|
* @see mshop/customer/manager/typo3/newid |
482
|
|
|
* @see mshop/customer/manager/typo3/delete |
483
|
|
|
* @see mshop/customer/manager/typo3/search |
484
|
|
|
* @see mshop/customer/manager/typo3/count |
485
|
|
|
*/ |
486
|
|
|
$path = 'mshop/customer/manager/typo3/insert'; |
487
|
|
|
$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ) ); |
488
|
|
|
} |
489
|
|
|
else |
490
|
|
|
{ |
491
|
|
|
/** mshop/customer/manager/typo3/update |
492
|
|
|
* Updates an existing customer record in the database |
493
|
|
|
* |
494
|
|
|
* Items which already have an ID (i.e. the ID is not NULL) will |
495
|
|
|
* be updated in the database. |
496
|
|
|
* |
497
|
|
|
* The SQL statement must be a string suitable for being used as |
498
|
|
|
* prepared statement. It must include question marks for binding |
499
|
|
|
* the values from the customer item to the statement before they are |
500
|
|
|
* sent to the database server. The order of the columns must |
501
|
|
|
* correspond to the order in the saveItems() method, so the |
502
|
|
|
* correct values are bound to the columns. |
503
|
|
|
* |
504
|
|
|
* The SQL statement should conform to the ANSI standard to be |
505
|
|
|
* compatible with most relational database systems. This also |
506
|
|
|
* includes using double quotes for table and column names. |
507
|
|
|
* |
508
|
|
|
* @param string SQL statement for updating records |
509
|
|
|
* @since 2014.03 |
510
|
|
|
* @category Developer |
511
|
|
|
* @see mshop/customer/manager/typo3/insert |
512
|
|
|
* @see mshop/customer/manager/typo3/newid |
513
|
|
|
* @see mshop/customer/manager/typo3/delete |
514
|
|
|
* @see mshop/customer/manager/typo3/search |
515
|
|
|
* @see mshop/customer/manager/typo3/count |
516
|
|
|
*/ |
517
|
|
|
$path = 'mshop/customer/manager/typo3/update'; |
518
|
|
|
$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ), false ); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
$address = $billingAddress->getAddress1(); |
522
|
|
|
|
523
|
|
|
if( ( $part = $billingAddress->getAddress2() ) != '' ) { |
524
|
|
|
$address .= ' ' . $part; |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
if( ( $part = $billingAddress->getAddress3() ) != '' ) { |
528
|
|
|
$address .= ' ' . $part; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
$idx = 1; |
532
|
|
|
$stmt = $this->getCachedStatement( $conn, $path, $sql ); |
533
|
|
|
|
534
|
|
|
foreach( $columns as $name => $entry ) { |
535
|
|
|
$stmt->bind( $idx++, $item->get( $name ), $entry->getInternalType() ); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
// TYPO3 fe_users.static_info_country is a three letter ISO code instead a two letter one |
539
|
|
|
$stmt->bind( $idx++, $context->getLocale()->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
540
|
|
|
$stmt->bind( $idx++, $item->getLabel() ); |
541
|
|
|
$stmt->bind( $idx++, $item->getCode() ); |
542
|
|
|
$stmt->bind( $idx++, $this->plugins['customer.salutation']->translate( $billingAddress->getSalutation() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
543
|
|
|
$stmt->bind( $idx++, $billingAddress->getCompany() ); |
544
|
|
|
$stmt->bind( $idx++, $billingAddress->getVatID() ); |
545
|
|
|
$stmt->bind( $idx++, $billingAddress->getTitle() ); |
546
|
|
|
$stmt->bind( $idx++, $billingAddress->getFirstname() ); |
547
|
|
|
$stmt->bind( $idx++, $billingAddress->getLastname() ); |
548
|
|
|
$stmt->bind( $idx++, $address ); |
549
|
|
|
$stmt->bind( $idx++, $billingAddress->getPostal() ); |
550
|
|
|
$stmt->bind( $idx++, $billingAddress->getCity() ); |
551
|
|
|
$stmt->bind( $idx++, $billingAddress->getState() ); |
552
|
|
|
$stmt->bind( $idx++, $billingAddress->getLanguageId() ); |
553
|
|
|
$stmt->bind( $idx++, $billingAddress->getTelephone() ); |
554
|
|
|
$stmt->bind( $idx++, $billingAddress->getEmail() ); |
555
|
|
|
$stmt->bind( $idx++, $billingAddress->getTelefax() ); |
556
|
|
|
$stmt->bind( $idx++, $billingAddress->getWebsite() ); |
557
|
|
|
$stmt->bind( $idx++, $billingAddress->getLongitude(), \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT ); |
558
|
|
|
$stmt->bind( $idx++, $billingAddress->getLatitude(), \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT ); |
559
|
|
|
$stmt->bind( $idx++, $this->plugins['customer.birthday']->translate( $item->getBirthday() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
560
|
|
|
$stmt->bind( $idx++, $this->plugins['customer.status']->translate( $item->getStatus() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
561
|
|
|
$stmt->bind( $idx++, $item->getPassword() ); |
562
|
|
|
$stmt->bind( $idx++, time(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // Modification time |
563
|
|
|
$stmt->bind( $idx++, $billingAddress->getCountryId() ); |
564
|
|
|
$stmt->bind( $idx++, implode( ',', $item->getGroups() ) ); |
565
|
|
|
$stmt->bind( $idx++, $this->pid, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // TYPO3 PID value |
566
|
|
|
|
567
|
|
|
if( $id !== null ) { |
568
|
|
|
$stmt->bind( $idx, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
569
|
|
|
$item->setId( $id ); |
570
|
|
|
} else { |
571
|
|
|
$stmt->bind( $idx, time(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // Creation time |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
$stmt->execute()->finish(); |
575
|
|
|
|
576
|
|
|
if( $id === null && $fetch === true ) |
577
|
|
|
{ |
578
|
|
|
/** mshop/customer/manager/typo3/newid |
579
|
|
|
* Retrieves the ID generated by the database when inserting a new record |
580
|
|
|
* |
581
|
|
|
* As soon as a new record is inserted into the database table, |
582
|
|
|
* the database server generates a new and unique identifier for |
583
|
|
|
* that record. This ID can be used for retrieving, updating and |
584
|
|
|
* deleting that specific record from the table again. |
585
|
|
|
* |
586
|
|
|
* For MySQL: |
587
|
|
|
* SELECT LAST_INSERT_ID() |
588
|
|
|
* For PostgreSQL: |
589
|
|
|
* SELECT currval('seq_mcus_id') |
590
|
|
|
* For SQL Server: |
591
|
|
|
* SELECT SCOPE_IDENTITY() |
592
|
|
|
* For Oracle: |
593
|
|
|
* SELECT "seq_mcus_id".CURRVAL FROM DUAL |
594
|
|
|
* |
595
|
|
|
* There's no way to retrive the new ID by a SQL statements that |
596
|
|
|
* fits for most database servers as they implement their own |
597
|
|
|
* specific way. |
598
|
|
|
* |
599
|
|
|
* @param string SQL statement for retrieving the last inserted record ID |
600
|
|
|
* @since 2014.03 |
601
|
|
|
* @category Developer |
602
|
|
|
* @see mshop/customer/manager/typo3/insert |
603
|
|
|
* @see mshop/customer/manager/typo3/update |
604
|
|
|
* @see mshop/customer/manager/typo3/delete |
605
|
|
|
* @see mshop/customer/manager/typo3/search |
606
|
|
|
* @see mshop/customer/manager/typo3/count |
607
|
|
|
*/ |
608
|
|
|
$path = 'mshop/customer/manager/typo3/newid'; |
609
|
|
|
$item->setId( $this->newId( $conn, $path ) ); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
$dbm->release( $conn, $dbname ); |
613
|
|
|
} |
614
|
|
|
catch( \Exception $e ) |
615
|
|
|
{ |
616
|
|
|
$dbm->release( $conn, $dbname ); |
617
|
|
|
throw $e; |
618
|
|
|
} |
619
|
|
|
|
620
|
|
|
$item = $this->savePropertyItems( $item, 'customer' ); |
621
|
|
|
$item = $this->saveAddressItems( $item, 'customer' ); |
622
|
|
|
return $this->saveListItems( $item, 'customer' ); |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* Returns the item objects matched by the given search criteria. |
628
|
|
|
* |
629
|
|
|
* @param \Aimeos\MW\Criteria\Iface $search Search criteria object |
630
|
|
|
* @param integer &$total Number of items that are available in total |
631
|
|
|
* @return array List of items implementing \Aimeos\MShop\Customer\Item\Iface |
632
|
|
|
* @throws \Aimeos\MShop\Customer\Exception If creating items failed |
633
|
|
|
*/ |
634
|
|
|
public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null ) |
635
|
|
|
{ |
636
|
|
|
$dbm = $this->getContext()->getDatabaseManager(); |
637
|
|
|
$dbname = $this->getResourceName(); |
638
|
|
|
$conn = $dbm->acquire( $dbname ); |
639
|
|
|
$map = []; |
640
|
|
|
|
641
|
|
|
try |
642
|
|
|
{ |
643
|
|
|
$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
644
|
|
|
$cfgPathSearch = 'mshop/customer/manager/typo3/search'; |
645
|
|
|
$cfgPathCount = 'mshop/customer/manager/typo3/count'; |
646
|
|
|
$required = array( 'customer' ); |
647
|
|
|
|
648
|
|
|
$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level, $this->plugins ); |
649
|
|
|
while( ( $row = $results->fetch() ) !== false ) { |
650
|
|
|
$map[(string) $row['customer.id']] = $row; |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
$dbm->release( $conn, $dbname ); |
654
|
|
|
} |
655
|
|
|
catch( \Exception $e ) |
656
|
|
|
{ |
657
|
|
|
$dbm->release( $conn, $dbname ); |
658
|
|
|
throw $e; |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
$addrItems = []; |
662
|
|
|
if( in_array( 'customer/address', $ref, true ) ) { |
663
|
|
|
$addrItems = $this->getAddressItems( array_keys( $map ), 'customer' ); |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
$propItems = []; |
667
|
|
|
if( in_array( 'customer/property', $ref, true ) ) { |
668
|
|
|
$propItems = $this->getPropertyItems( array_keys( $map ), 'customer' ); |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
return $this->buildItems( $map, $ref, 'customer', $addrItems, $propItems ); |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
|
675
|
|
|
/** |
676
|
|
|
* Returns a new manager for customer extensions |
677
|
|
|
* |
678
|
|
|
* @param string $manager Name of the sub manager type in lower case |
679
|
|
|
* @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
680
|
|
|
* @return mixed Manager for different extensions, e.g stock, tags, locations, etc. |
681
|
|
|
*/ |
682
|
|
|
public function getSubManager( $manager, $name = null ) |
683
|
|
|
{ |
684
|
|
|
return $this->getSubManagerBase( 'customer', $manager, ( $name === null ? 'Typo3' : $name ) ); |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
|
688
|
|
|
/** |
689
|
|
|
* Creates a new customer item. |
690
|
|
|
* |
691
|
|
|
* @param array $values List of attributes for customer item |
692
|
|
|
* @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items |
693
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items |
694
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface[] $addrItems List of referenced address items |
695
|
|
|
* @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items |
696
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface New customer item |
697
|
|
|
*/ |
698
|
|
|
protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [], |
699
|
|
|
array $addrItems = [], array $propItems = [] ) |
700
|
|
|
{ |
701
|
|
|
$helper = $this->getPasswordHelper(); |
702
|
|
|
$values['customer.siteid'] = $this->getContext()->getLocale()->getSiteId(); |
703
|
|
|
|
704
|
|
|
if( array_key_exists( 'date_of_birth', $values ) ) { |
705
|
|
|
$values['customer.birthday'] = $this->reverse['date_of_birth']->reverse( $values['date_of_birth'] ); |
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
if( array_key_exists( 'gender', $values ) ) { |
709
|
|
|
$values['customer.salutation'] = $this->reverse['gender']->reverse( $values['gender'] ); |
710
|
|
|
} |
711
|
|
|
|
712
|
|
|
if( array_key_exists( 'disable', $values ) ) { |
713
|
|
|
$values['customer.status'] = $this->reverse['disable']->reverse( $values['disable'] ); |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
if( array_key_exists( 'tstamp', $values ) ) { |
717
|
|
|
$values['customer.mtime'] = $this->reverse['tstamp']->reverse( $values['tstamp'] ); |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
if( array_key_exists( 'crdate', $values ) ) { |
721
|
|
|
$values['customer.ctime'] = $this->reverse['crdate']->reverse( $values['crdate'] ); |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
if( array_key_exists( 'groups', $values ) && $values['groups'] !== '' ) { |
725
|
|
|
$values['customer.groups'] = explode( ',', $values['groups'] ); |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
|
729
|
|
|
$address = new \Aimeos\MShop\Common\Item\Address\Simple( 'customer.', $values ); |
730
|
|
|
|
731
|
|
|
return new \Aimeos\MShop\Customer\Item\Standard( |
732
|
|
|
$address, $values, $listItems, $refItems, $addrItems, $propItems, $helper |
733
|
|
|
); |
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
|
737
|
|
|
/** |
738
|
|
|
* Returns a password helper object based on the configuration. |
739
|
|
|
* |
740
|
|
|
* @return \Aimeos\MShop\Common\Helper\Password\Iface Password helper object |
741
|
|
|
* @throws \Aimeos\MShop\Exception If the name is invalid or the class isn't found |
742
|
|
|
*/ |
743
|
|
|
protected function getPasswordHelper() |
744
|
|
|
{ |
745
|
|
|
if( $this->helper ) { |
746
|
|
|
return $this->helper; |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
$classname = \Aimeos\MShop\Common\Helper\Password\Typo3::class; |
750
|
|
|
|
751
|
|
|
if( class_exists( $classname ) === false ) { |
752
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Class "%1$s" not available', $classname ) ); |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
$context = $this->getContext(); |
756
|
|
|
$object = ( method_exists( $context, 'getHasherTypo3' ) ? $context->getHasherTypo3() : null ); |
757
|
|
|
|
758
|
|
|
$helper = new $classname( array( 'object' => $object ) ); |
759
|
|
|
|
760
|
|
|
return $this->helper = self::checkClass( \Aimeos\MShop\Common\Helper\Password\Iface::class, $helper ); |
761
|
|
|
} |
762
|
|
|
} |
763
|
|
|
|