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' => '( |
241
|
|
|
SELECT t3feuli_has."id" FROM fe_users_list AS t3feuli_has |
242
|
|
|
WHERE t3feu."uid" = t3feuli_has."parentid" AND :site AND :key LIMIT 1 |
243
|
|
|
)', |
244
|
|
|
'label' => 'Customer has list item, parameter(<domain>[,<list type>[,<reference ID>)]]', |
245
|
|
|
'type' => 'null', |
246
|
|
|
'internaltype' => 'null', |
247
|
|
|
'public' => false, |
248
|
|
|
), |
249
|
|
|
'customer:prop' => array( |
250
|
|
|
'code' => 'customer:prop()', |
251
|
|
|
'internalcode' => '( |
252
|
|
|
SELECT t3feupr_prop."id" FROM fe_users_property AS t3feupr_prop |
253
|
|
|
WHERE t3feu."uid" = t3feupr_prop."parentid" AND :site AND :key LIMIT 1 |
254
|
|
|
)', |
255
|
|
|
'label' => 'Customer has property item, parameter(<property type>[,<language code>[,<property value>]])', |
256
|
|
|
'type' => 'null', |
257
|
|
|
'internaltype' => 'null', |
258
|
|
|
'public' => false, |
259
|
|
|
), |
260
|
|
|
); |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
private $plugins = []; |
264
|
|
|
private $reverse = []; |
265
|
|
|
private $helper; |
266
|
|
|
private $pid; |
267
|
|
|
|
268
|
|
|
|
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Initializes a new customer manager object using the given context object. |
272
|
|
|
* |
273
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
274
|
|
|
*/ |
275
|
|
|
public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
276
|
|
|
{ |
277
|
|
|
parent::__construct( $context ); |
278
|
|
|
|
279
|
|
|
$plugin = new \Aimeos\MW\Criteria\Plugin\T3Salutation(); |
280
|
|
|
$this->plugins['customer.salutation'] = $this->reverse['gender'] = $plugin; |
281
|
|
|
|
282
|
|
|
$plugin = new \Aimeos\MW\Criteria\Plugin\T3Status(); |
283
|
|
|
$this->plugins['customer.status'] = $this->reverse['disable'] = $plugin; |
284
|
|
|
|
285
|
|
|
$plugin = new \Aimeos\MW\Criteria\Plugin\T3Date(); |
286
|
|
|
$this->plugins['customer.birthday'] = $this->reverse['date_of_birth'] = $plugin; |
287
|
|
|
|
288
|
|
|
$plugin = new \Aimeos\MW\Criteria\Plugin\T3Datetime(); |
289
|
|
|
$this->plugins['customer.ctime'] = $this->reverse['crdate'] = $plugin; |
290
|
|
|
$this->plugins['customer.mtime'] = $this->reverse['tstamp'] = $plugin; |
291
|
|
|
|
292
|
|
|
$this->pid = $context->getConfig()->get( 'mshop/customer/manager/typo3/pid-default', 0 ); |
293
|
|
|
|
294
|
|
|
|
295
|
|
|
$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
296
|
|
|
$level = $context->getConfig()->get( 'mshop/customer/manager/sitemode', $level ); |
297
|
|
|
|
298
|
|
|
$siteIds = $this->getSiteIds( $level ); |
299
|
|
|
$self = $this; |
300
|
|
|
|
301
|
|
|
|
302
|
|
|
$this->searchConfig['customer:has']['function'] = function( &$source, array $params ) use ( $self, $siteIds ) { |
303
|
|
|
|
304
|
|
|
foreach( $params as $key => $param ) { |
305
|
|
|
$params[$key] = trim( $param, '\'' ); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
$source = str_replace( ':site', $self->toExpression( 't3feuli_has."siteid"', $siteIds ), $source ); |
309
|
|
|
$str = $self->toExpression( 't3feuli_has."key"', join( '|', $params ), isset( $params[2] ) ? '==' : '=~' ); |
310
|
|
|
$source = str_replace( ':key', $str, $source ); |
311
|
|
|
|
312
|
|
|
return $params; |
313
|
|
|
}; |
314
|
|
|
|
315
|
|
|
|
316
|
|
|
$this->searchConfig['customer:prop']['function'] = function( &$source, array $params ) use ( $self, $siteIds ) { |
317
|
|
|
|
318
|
|
|
foreach( $params as $key => $param ) { |
319
|
|
|
$params[$key] = trim( $param, '\'' ); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
$params[2] = ( isset( $params[2] ) ? md5( $params[2] ) : null ); |
323
|
|
|
$source = str_replace( ':site', $self->toExpression( 't3feupr_prop."siteid"', $siteIds ), $source ); |
324
|
|
|
$str = $self->toExpression( 't3feupr_prop."key"', join( '|', $params ), isset( $params[2] ) ? '==' : '=~' ); |
325
|
|
|
$source = str_replace( ':key', $str, $source ); |
326
|
|
|
|
327
|
|
|
return $params; |
328
|
|
|
}; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Removes old entries from the storage. |
334
|
|
|
* |
335
|
|
|
* @param array $siteids List of IDs for sites whose entries should be deleted |
336
|
|
|
*/ |
337
|
|
|
public function clear( array $siteids ) |
338
|
|
|
{ |
339
|
|
|
$path = 'mshop/customer/manager/submanagers'; |
340
|
|
|
$default = ['address', 'group', 'lists', 'property']; |
341
|
|
|
|
342
|
|
|
foreach( $this->getContext()->getConfig()->get( $path, $default ) as $domain ) { |
343
|
|
|
$this->getObject()->getSubManager( $domain )->clear( $siteids ); |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Creates a new empty item instance |
350
|
|
|
* |
351
|
|
|
* @param array $values Values the item should be initialized with |
352
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface New site item object |
353
|
|
|
*/ |
354
|
|
|
public function createItem( array $values = [] ) |
355
|
|
|
{ |
356
|
|
|
$values['customer.siteid'] = $this->getContext()->getLocale()->getSiteId(); |
357
|
|
|
return $this->createItemBase( $values ); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* Deletes a customer item object from the permanent storage. |
363
|
|
|
* |
364
|
|
|
* @param array $ids List of customer IDs |
365
|
|
|
*/ |
366
|
|
|
public function deleteItems( array $ids ) |
367
|
|
|
{ |
368
|
|
|
$path = 'mshop/customer/manager/typo3/delete'; |
369
|
|
|
$this->deleteItemsBase( $ids, $path, false, 'uid' ); |
370
|
|
|
|
371
|
|
|
$manager = $this->getObject()->getSubManager( 'address' ); |
372
|
|
|
$search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
373
|
|
|
$search->setConditions( $search->compare( '==', 'customer.address.parentid', $ids ) ); |
374
|
|
|
$manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
375
|
|
|
|
376
|
|
|
$manager = $this->getObject()->getSubManager( 'lists' ); |
377
|
|
|
$search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
378
|
|
|
$search->setConditions( $search->compare( '==', 'customer.lists.parentid', $ids ) ); |
379
|
|
|
$manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
380
|
|
|
|
381
|
|
|
$manager = $this->getObject()->getSubManager( 'property' ); |
382
|
|
|
$search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
383
|
|
|
$search->setConditions( $search->compare( '==', 'customer.property.parentid', $ids ) ); |
384
|
|
|
$manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Returns the list attributes that can be used for searching. |
390
|
|
|
* |
391
|
|
|
* @param boolean $withsub Return also attributes of sub-managers if true |
392
|
|
|
* @return array List of attribute items implementing \Aimeos\MW\Criteria\Attribute\Iface |
393
|
|
|
*/ |
394
|
|
|
public function getSearchAttributes( $withsub = true ) |
395
|
|
|
{ |
396
|
|
|
$path = 'mshop/customer/manager/submanagers'; |
397
|
|
|
return $this->getSearchAttributesBase( $this->searchConfig, $path, ['address'], $withsub ); |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Saves a customer item object. |
403
|
|
|
* |
404
|
|
|
* @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object |
405
|
|
|
* @param boolean $fetch True if the new ID should be returned in the item |
406
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface $item Updated item including the generated ID |
407
|
|
|
*/ |
408
|
|
|
public function saveItem( \Aimeos\MShop\Customer\Item\Iface $item, $fetch = true ) |
409
|
|
|
{ |
410
|
|
|
if( !$item->isModified() ) |
411
|
|
|
{ |
412
|
|
|
$item = $this->savePropertyItems( $item, 'customer' ); |
413
|
|
|
$item = $this->saveAddressItems( $item, 'customer' ); |
414
|
|
|
return $this->saveListItems( $item, 'customer' ); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
$context = $this->getContext(); |
418
|
|
|
$dbm = $context->getDatabaseManager(); |
419
|
|
|
$dbname = $this->getResourceName(); |
420
|
|
|
$conn = $dbm->acquire( $dbname ); |
421
|
|
|
|
422
|
|
|
try |
423
|
|
|
{ |
424
|
|
|
$id = $item->getId(); |
425
|
|
|
$billingAddress = $item->getPaymentAddress(); |
426
|
|
|
$columns = $this->getObject()->getSaveAttributes(); |
427
|
|
|
|
428
|
|
|
if( $id === null ) |
429
|
|
|
{ |
430
|
|
|
/** mshop/customer/manager/typo3/insert |
431
|
|
|
* Inserts a new customer record into the database table |
432
|
|
|
* |
433
|
|
|
* Items with no ID yet (i.e. the ID is NULL) will be created in |
434
|
|
|
* the database and the newly created ID retrieved afterwards |
435
|
|
|
* using the "newid" SQL statement. |
436
|
|
|
* |
437
|
|
|
* The SQL statement must be a string suitable for being used as |
438
|
|
|
* prepared statement. It must include question marks for binding |
439
|
|
|
* the values from the customer item to the statement before they are |
440
|
|
|
* sent to the database server. The number of question marks must |
441
|
|
|
* be the same as the number of columns listed in the INSERT |
442
|
|
|
* statement. The order of the columns must correspond to the |
443
|
|
|
* order in the saveItems() method, so the correct values are |
444
|
|
|
* bound to the columns. |
445
|
|
|
* |
446
|
|
|
* The SQL statement should conform to the ANSI standard to be |
447
|
|
|
* compatible with most relational database systems. This also |
448
|
|
|
* includes using double quotes for table and column names. |
449
|
|
|
* |
450
|
|
|
* @param string SQL statement for inserting records |
451
|
|
|
* @since 2014.03 |
452
|
|
|
* @category Developer |
453
|
|
|
* @see mshop/customer/manager/typo3/update |
454
|
|
|
* @see mshop/customer/manager/typo3/newid |
455
|
|
|
* @see mshop/customer/manager/typo3/delete |
456
|
|
|
* @see mshop/customer/manager/typo3/search |
457
|
|
|
* @see mshop/customer/manager/typo3/count |
458
|
|
|
*/ |
459
|
|
|
$path = 'mshop/customer/manager/typo3/insert'; |
460
|
|
|
$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ) ); |
461
|
|
|
} |
462
|
|
|
else |
463
|
|
|
{ |
464
|
|
|
/** mshop/customer/manager/typo3/update |
465
|
|
|
* Updates an existing customer record in the database |
466
|
|
|
* |
467
|
|
|
* Items which already have an ID (i.e. the ID is not NULL) will |
468
|
|
|
* be updated in the database. |
469
|
|
|
* |
470
|
|
|
* The SQL statement must be a string suitable for being used as |
471
|
|
|
* prepared statement. It must include question marks for binding |
472
|
|
|
* the values from the customer item to the statement before they are |
473
|
|
|
* sent to the database server. The order of the columns must |
474
|
|
|
* correspond to the order in the saveItems() method, so the |
475
|
|
|
* correct values are bound to the columns. |
476
|
|
|
* |
477
|
|
|
* The SQL statement should conform to the ANSI standard to be |
478
|
|
|
* compatible with most relational database systems. This also |
479
|
|
|
* includes using double quotes for table and column names. |
480
|
|
|
* |
481
|
|
|
* @param string SQL statement for updating records |
482
|
|
|
* @since 2014.03 |
483
|
|
|
* @category Developer |
484
|
|
|
* @see mshop/customer/manager/typo3/insert |
485
|
|
|
* @see mshop/customer/manager/typo3/newid |
486
|
|
|
* @see mshop/customer/manager/typo3/delete |
487
|
|
|
* @see mshop/customer/manager/typo3/search |
488
|
|
|
* @see mshop/customer/manager/typo3/count |
489
|
|
|
*/ |
490
|
|
|
$path = 'mshop/customer/manager/typo3/update'; |
491
|
|
|
$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ), false ); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
$address = $billingAddress->getAddress1(); |
495
|
|
|
|
496
|
|
|
if( ( $part = $billingAddress->getAddress2() ) != '' ) { |
497
|
|
|
$address .= ' ' . $part; |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
if( ( $part = $billingAddress->getAddress3() ) != '' ) { |
501
|
|
|
$address .= ' ' . $part; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
$idx = 1; |
505
|
|
|
$stmt = $this->getCachedStatement( $conn, $path, $sql ); |
506
|
|
|
|
507
|
|
|
foreach( $columns as $name => $entry ) { |
508
|
|
|
$stmt->bind( $idx++, $item->get( $name ), $entry->getInternalType() ); |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
// TYPO3 fe_users.static_info_country is a three letter ISO code instead a two letter one |
512
|
|
|
$stmt->bind( $idx++, $context->getLocale()->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
513
|
|
|
$stmt->bind( $idx++, $item->getLabel() ); |
514
|
|
|
$stmt->bind( $idx++, $item->getCode() ); |
515
|
|
|
$stmt->bind( $idx++, $this->plugins['customer.salutation']->translate( $billingAddress->getSalutation() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
516
|
|
|
$stmt->bind( $idx++, $billingAddress->getCompany() ); |
517
|
|
|
$stmt->bind( $idx++, $billingAddress->getVatID() ); |
518
|
|
|
$stmt->bind( $idx++, $billingAddress->getTitle() ); |
519
|
|
|
$stmt->bind( $idx++, $billingAddress->getFirstname() ); |
520
|
|
|
$stmt->bind( $idx++, $billingAddress->getLastname() ); |
521
|
|
|
$stmt->bind( $idx++, $address ); |
522
|
|
|
$stmt->bind( $idx++, $billingAddress->getPostal() ); |
523
|
|
|
$stmt->bind( $idx++, $billingAddress->getCity() ); |
524
|
|
|
$stmt->bind( $idx++, $billingAddress->getState() ); |
525
|
|
|
$stmt->bind( $idx++, $billingAddress->getLanguageId() ); |
526
|
|
|
$stmt->bind( $idx++, $billingAddress->getTelephone() ); |
527
|
|
|
$stmt->bind( $idx++, $billingAddress->getEmail() ); |
528
|
|
|
$stmt->bind( $idx++, $billingAddress->getTelefax() ); |
529
|
|
|
$stmt->bind( $idx++, $billingAddress->getWebsite() ); |
530
|
|
|
$stmt->bind( $idx++, $billingAddress->getLongitude(), \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT ); |
531
|
|
|
$stmt->bind( $idx++, $billingAddress->getLatitude(), \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT ); |
532
|
|
|
$stmt->bind( $idx++, $this->plugins['customer.birthday']->translate( $item->getBirthday() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
533
|
|
|
$stmt->bind( $idx++, $this->plugins['customer.status']->translate( $item->getStatus() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
534
|
|
|
$stmt->bind( $idx++, $item->getPassword() ); |
535
|
|
|
$stmt->bind( $idx++, time(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // Modification time |
536
|
|
|
$stmt->bind( $idx++, $billingAddress->getCountryId() ); |
537
|
|
|
$stmt->bind( $idx++, implode( ',', $item->getGroups() ) ); |
538
|
|
|
$stmt->bind( $idx++, $this->pid, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // TYPO3 PID value |
539
|
|
|
|
540
|
|
|
if( $id !== null ) { |
541
|
|
|
$stmt->bind( $idx, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
542
|
|
|
$item->setId( $id ); |
543
|
|
|
} else { |
544
|
|
|
$stmt->bind( $idx, time(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // Creation time |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
$stmt->execute()->finish(); |
548
|
|
|
|
549
|
|
|
if( $id === null && $fetch === true ) |
550
|
|
|
{ |
551
|
|
|
/** mshop/customer/manager/typo3/newid |
552
|
|
|
* Retrieves the ID generated by the database when inserting a new record |
553
|
|
|
* |
554
|
|
|
* As soon as a new record is inserted into the database table, |
555
|
|
|
* the database server generates a new and unique identifier for |
556
|
|
|
* that record. This ID can be used for retrieving, updating and |
557
|
|
|
* deleting that specific record from the table again. |
558
|
|
|
* |
559
|
|
|
* For MySQL: |
560
|
|
|
* SELECT LAST_INSERT_ID() |
561
|
|
|
* For PostgreSQL: |
562
|
|
|
* SELECT currval('seq_mcus_id') |
563
|
|
|
* For SQL Server: |
564
|
|
|
* SELECT SCOPE_IDENTITY() |
565
|
|
|
* For Oracle: |
566
|
|
|
* SELECT "seq_mcus_id".CURRVAL FROM DUAL |
567
|
|
|
* |
568
|
|
|
* There's no way to retrive the new ID by a SQL statements that |
569
|
|
|
* fits for most database servers as they implement their own |
570
|
|
|
* specific way. |
571
|
|
|
* |
572
|
|
|
* @param string SQL statement for retrieving the last inserted record ID |
573
|
|
|
* @since 2014.03 |
574
|
|
|
* @category Developer |
575
|
|
|
* @see mshop/customer/manager/typo3/insert |
576
|
|
|
* @see mshop/customer/manager/typo3/update |
577
|
|
|
* @see mshop/customer/manager/typo3/delete |
578
|
|
|
* @see mshop/customer/manager/typo3/search |
579
|
|
|
* @see mshop/customer/manager/typo3/count |
580
|
|
|
*/ |
581
|
|
|
$path = 'mshop/customer/manager/typo3/newid'; |
582
|
|
|
$item->setId( $this->newId( $conn, $path ) ); |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
$dbm->release( $conn, $dbname ); |
586
|
|
|
} |
587
|
|
|
catch( \Exception $e ) |
588
|
|
|
{ |
589
|
|
|
$dbm->release( $conn, $dbname ); |
590
|
|
|
throw $e; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
$item = $this->savePropertyItems( $item, 'customer' ); |
594
|
|
|
$item = $this->saveAddressItems( $item, 'customer' ); |
595
|
|
|
return $this->saveListItems( $item, 'customer' ); |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
|
599
|
|
|
/** |
600
|
|
|
* Returns the item objects matched by the given search criteria. |
601
|
|
|
* |
602
|
|
|
* @param \Aimeos\MW\Criteria\Iface $search Search criteria object |
603
|
|
|
* @param integer &$total Number of items that are available in total |
604
|
|
|
* @return array List of items implementing \Aimeos\MShop\Customer\Item\Iface |
605
|
|
|
* @throws \Aimeos\MShop\Customer\Exception If creating items failed |
606
|
|
|
*/ |
607
|
|
|
public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null ) |
608
|
|
|
{ |
609
|
|
|
$dbm = $this->getContext()->getDatabaseManager(); |
610
|
|
|
$dbname = $this->getResourceName(); |
611
|
|
|
$conn = $dbm->acquire( $dbname ); |
612
|
|
|
$map = []; |
613
|
|
|
|
614
|
|
|
try |
615
|
|
|
{ |
616
|
|
|
$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
617
|
|
|
$cfgPathSearch = 'mshop/customer/manager/typo3/search'; |
618
|
|
|
$cfgPathCount = 'mshop/customer/manager/typo3/count'; |
619
|
|
|
$required = array( 'customer' ); |
620
|
|
|
|
621
|
|
|
$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level, $this->plugins ); |
622
|
|
|
while( ( $row = $results->fetch() ) !== false ) { |
623
|
|
|
$map[(string) $row['customer.id']] = $row; |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
$dbm->release( $conn, $dbname ); |
627
|
|
|
} |
628
|
|
|
catch( \Exception $e ) |
629
|
|
|
{ |
630
|
|
|
$dbm->release( $conn, $dbname ); |
631
|
|
|
throw $e; |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
$addrItems = []; |
635
|
|
|
if( in_array( 'customer/address', $ref, true ) ) { |
636
|
|
|
$addrItems = $this->getAddressItems( array_keys( $map ), 'customer' ); |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
$propItems = []; $name = 'customer/property'; |
640
|
|
|
if( isset( $ref[$name] ) || in_array( $name, $ref, true ) ) |
641
|
|
|
{ |
642
|
|
|
$propTypes = isset( $ref[$name] ) && is_array( $ref[$name] ) ? $ref[$name] : null; |
643
|
|
|
$propItems = $this->getPropertyItems( array_keys( $map ), 'customer', $propTypes ); |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
return $this->buildItems( $map, $ref, 'customer', $addrItems, $propItems ); |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* Returns a new manager for customer extensions |
652
|
|
|
* |
653
|
|
|
* @param string $manager Name of the sub manager type in lower case |
654
|
|
|
* @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
655
|
|
|
* @return mixed Manager for different extensions, e.g stock, tags, locations, etc. |
656
|
|
|
*/ |
657
|
|
|
public function getSubManager( $manager, $name = null ) |
658
|
|
|
{ |
659
|
|
|
return $this->getSubManagerBase( 'customer', $manager, ( $name === null ? 'Typo3' : $name ) ); |
660
|
|
|
} |
661
|
|
|
|
662
|
|
|
|
663
|
|
|
/** |
664
|
|
|
* Creates a new customer item. |
665
|
|
|
* |
666
|
|
|
* @param array $values List of attributes for customer item |
667
|
|
|
* @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items |
668
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items |
669
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface[] $addrItems List of referenced address items |
670
|
|
|
* @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items |
671
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface New customer item |
672
|
|
|
*/ |
673
|
|
|
protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [], |
674
|
|
|
array $addrItems = [], array $propItems = [] ) |
675
|
|
|
{ |
676
|
|
|
$helper = $this->getPasswordHelper(); |
677
|
|
|
$values['customer.siteid'] = $this->getContext()->getLocale()->getSiteId(); |
678
|
|
|
|
679
|
|
|
if( array_key_exists( 'date_of_birth', $values ) ) { |
680
|
|
|
$values['customer.birthday'] = $this->reverse['date_of_birth']->reverse( $values['date_of_birth'] ); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
if( array_key_exists( 'gender', $values ) ) { |
684
|
|
|
$values['customer.salutation'] = $this->reverse['gender']->reverse( $values['gender'] ); |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
if( array_key_exists( 'disable', $values ) ) { |
688
|
|
|
$values['customer.status'] = $this->reverse['disable']->reverse( $values['disable'] ); |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
if( array_key_exists( 'tstamp', $values ) ) { |
692
|
|
|
$values['customer.mtime'] = $this->reverse['tstamp']->reverse( $values['tstamp'] ); |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
if( array_key_exists( 'crdate', $values ) ) { |
696
|
|
|
$values['customer.ctime'] = $this->reverse['crdate']->reverse( $values['crdate'] ); |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
if( array_key_exists( 'groups', $values ) && $values['groups'] !== '' ) { |
700
|
|
|
$values['customer.groups'] = explode( ',', $values['groups'] ); |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
|
704
|
|
|
$address = new \Aimeos\MShop\Common\Item\Address\Simple( 'customer.', $values ); |
705
|
|
|
|
706
|
|
|
return new \Aimeos\MShop\Customer\Item\Standard( |
707
|
|
|
$address, $values, $listItems, $refItems, $addrItems, $propItems, $helper |
708
|
|
|
); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
|
712
|
|
|
/** |
713
|
|
|
* Returns a password helper object based on the configuration. |
714
|
|
|
* |
715
|
|
|
* @return \Aimeos\MShop\Common\Helper\Password\Iface Password helper object |
716
|
|
|
* @throws \Aimeos\MShop\Exception If the name is invalid or the class isn't found |
717
|
|
|
*/ |
718
|
|
|
protected function getPasswordHelper() |
719
|
|
|
{ |
720
|
|
|
if( $this->helper ) { |
721
|
|
|
return $this->helper; |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
$classname = \Aimeos\MShop\Common\Helper\Password\Typo3::class; |
725
|
|
|
|
726
|
|
|
if( class_exists( $classname ) === false ) { |
727
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Class "%1$s" not available', $classname ) ); |
728
|
|
|
} |
729
|
|
|
|
730
|
|
|
$context = $this->getContext(); |
731
|
|
|
$object = ( method_exists( $context, 'getHasherTypo3' ) ? $context->getHasherTypo3() : null ); |
732
|
|
|
|
733
|
|
|
$helper = new $classname( array( 'object' => $object ) ); |
734
|
|
|
|
735
|
|
|
return $this->helper = self::checkClass( \Aimeos\MShop\Common\Helper\Password\Iface::class, $helper ); |
736
|
|
|
} |
737
|
|
|
} |
738
|
|
|
|