Passed
Push — master ( c01485...43daff )
by Aimeos
01:37
created

Ezpublish::__construct()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 40
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 21
nc 4
nop 1
dl 0
loc 40
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2018
6
 * @package MShop
7
 * @subpackage Customer
8
 */
9
10
11
namespace Aimeos\MShop\Customer\Manager;
12
13
14
/**
15
 * Customer class implementation for ezPublish
16
 *
17
 * @package MShop
18
 * @subpackage Customer
19
 */
20
class Ezpublish
21
	extends \Aimeos\MShop\Customer\Manager\Standard
22
{
23
	private $searchConfig = array(
24
		'customer.id' => array(
25
			'label' => 'Customer ID',
26
			'code' => 'customer.id',
27
			'internalcode' => 'ezu."contentobject_id"',
28
			'type' => 'integer',
29
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT
30
		),
31
		// customer.siteid is not available
32
		'customer.label' => array(
33
			'label' => 'Customer label',
34
			'code' => 'customer.label',
35
			'internalcode' => 'ezu."login"',
36
			'type' => 'string',
37
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR
38
		),
39
		'customer.code' => array(
40
			'label' => 'Customer username',
41
			'code' => 'customer.code',
42
			'internalcode' => 'ezu."login_normalized"',
43
			'type' => 'string',
44
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR
45
		),
46
		'customer.salutation' => array(
47
			'label' => 'Customer salutation',
48
			'code' => 'customer.salutation',
49
			'internalcode' => 'ezu."salutation"',
50
			'type' => 'string',
51
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
52
		),
53
		'customer.company'=> array(
54
			'label' => 'Customer company',
55
			'code' => 'customer.company',
56
			'internalcode' => 'ezu."company"',
57
			'type' => 'string',
58
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
59
		),
60
		'customer.vatid'=> array(
61
			'label' => 'Customer VAT ID',
62
			'code' => 'customer.vatid',
63
			'internalcode' => 'ezu."vatid"',
64
			'type' => 'string',
65
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
66
		),
67
		'customer.title' => array(
68
			'label' => 'Customer title',
69
			'code' => 'customer.title',
70
			'internalcode' => 'ezu."title"',
71
			'type' => 'string',
72
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
73
		),
74
		'customer.firstname' => array(
75
			'label' => 'Customer firstname',
76
			'code' => 'customer.firstname',
77
			'internalcode' => 'ezu."firstname"',
78
			'type' => 'string',
79
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
80
		),
81
		'customer.lastname' => array(
82
			'label' => 'Customer lastname',
83
			'code' => 'customer.lastname',
84
			'internalcode' => 'ezu."lastname"',
85
			'type' => 'string',
86
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
87
		),
88
		'customer.address1' => array(
89
			'label' => 'Customer address part one',
90
			'code' => 'customer.address1',
91
			'internalcode' => 'ezu."address1"',
92
			'type' => 'string',
93
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
94
		),
95
		'customer.address2' => array(
96
			'label' => 'Customer address part two',
97
			'code' => 'customer.address2',
98
			'internalcode' => 'ezu."address2"',
99
			'type' => 'string',
100
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
101
		),
102
		'customer.address3' => array(
103
			'label' => 'Customer address part three',
104
			'code' => 'customer.address3',
105
			'internalcode' => 'ezu."address3"',
106
			'type' => 'string',
107
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
108
		),
109
		'customer.postal' => array(
110
			'label' => 'Customer postal',
111
			'code' => 'customer.postal',
112
			'internalcode' => 'ezu."postal"',
113
			'type' => 'string',
114
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
115
		),
116
		'customer.city' => array(
117
			'label' => 'Customer city',
118
			'code' => 'customer.city',
119
			'internalcode' => 'ezu."city"',
120
			'type' => 'string',
121
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
122
		),
123
		'customer.state' => array(
124
			'label' => 'Customer state',
125
			'code' => 'customer.state',
126
			'internalcode' => 'ezu."state"',
127
			'type' => 'string',
128
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
129
		),
130
		'customer.languageid' => array(
131
			'label' => 'Customer language',
132
			'code' => 'customer.languageid',
133
			'internalcode' => 'ezu."langid"',
134
			'type' => 'string',
135
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
136
		),
137
		'customer.countryid' => array(
138
			'label' => 'Customer country',
139
			'code' => 'customer.countryid',
140
			'internalcode' => 'ezu."countryid"',
141
			'type' => 'string',
142
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
143
		),
144
		'customer.telephone' => array(
145
			'label' => 'Customer telephone',
146
			'code' => 'customer.telephone',
147
			'internalcode' => 'ezu."telephone"',
148
			'type' => 'string',
149
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
150
		),
151
		'customer.email' => array(
152
			'label' => 'Customer email',
153
			'code' => 'customer.email',
154
			'internalcode' => 'ezu."email"',
155
			'type' => 'string',
156
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
157
		),
158
		'customer.telefax' => array(
159
			'label' => 'Customer telefax',
160
			'code' => 'customer.telefax',
161
			'internalcode' => 'ezu."telefax"',
162
			'type' => 'string',
163
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
164
		),
165
		'customer.website' => array(
166
			'label' => 'Customer website',
167
			'code' => 'customer.website',
168
			'internalcode' => 'ezu."website"',
169
			'type' => 'string',
170
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
171
		),
172
		'customer.birthday' => array(
173
			'label' => 'Customer birthday',
174
			'code' => 'customer.birthday',
175
			'internalcode' => 'ezu."birthday"',
176
			'type' => 'string',
177
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
178
		),
179
		'customer.password'=> array(
180
			'label' => 'Customer password',
181
			'code' => 'customer.password',
182
			'internalcode' => 'ezu."password_hash"',
183
			'type' => 'string',
184
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
185
		),
186
		'customer.status'=> array(
187
			'label' => 'Customer status',
188
			'code' => 'customer.status',
189
			'internalcode' => 'ezs."is_enabled"',
190
			'type' => 'integer',
191
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT
192
		),
193
		'customer.dateverified'=> array(
194
			'label' => 'Customer verification date',
195
			'code' => 'customer.dateverified',
196
			'internalcode' => 'ezu."vdate"',
197
			'type' => 'date',
198
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
199
		),
200
		'customer.ctime'=> array(
201
			'label' => 'Customer creation time',
202
			'code' => 'customer.ctime',
203
			'internalcode' => 'ezu."ctime"',
204
			'type' => 'datetime',
205
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
206
		),
207
		'customer.mtime'=> array(
208
			'label' => 'Customer modification time',
209
			'code' => 'customer.mtime',
210
			'internalcode' => 'ezu."mtime"',
211
			'type' => 'datetime',
212
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
213
		),
214
		'customer.editor'=> array(
215
			'label'=>'Customer editor',
216
			'code'=>'customer.editor',
217
			'internalcode' => 'ezu."editor"',
218
			'type'=> 'string',
219
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
220
		),
221
		'customer:has' => array(
222
			'code' => 'customer:has()',
223
			'internalcode' => '(
224
				SELECT ezuli_has."id" FROM ezuser_list AS ezuli_has
225
				WHERE ezu."id" = ezuli_has."parentid" AND :site AND ezuli_has."domain" = $1 :type :refid
226
				LIMIT 1
227
			)',
228
			'label' => 'Customer has list item, parameter(<domain>[,<list type>[,<reference ID>)]]',
229
			'type' => 'null',
230
			'internaltype' => 'null',
231
			'public' => false,
232
		),
233
		'customer:prop' => array(
234
			'code' => 'customer:prop()',
235
			'internalcode' => '(
236
				SELECT ezupr_prop."id" FROM ezuser_property AS ezupr_prop
237
				WHERE ezu."id" = ezupr_prop."parentid" AND :site AND ezupr_prop."type" = $1 :langid :value
238
				LIMIT 1
239
			)',
240
			'label' => 'Customer has property item, parameter(<property type>[,<language code>[,<property value>]])',
241
			'type' => 'null',
242
			'internaltype' => 'null',
243
			'public' => false,
244
		),
245
	);
246
247
248
	/**
249
	 * Initializes the object.
250
	 *
251
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
252
	 */
253
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
254
	{
255
		parent::__construct( $context );
256
257
		$locale = $context->getLocale();
258
		$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
259
		$level = $context->getConfig()->get( 'mshop/customer/manager/sitemode', $level );
260
261
		$siteIds = [$locale->getSiteId()];
262
263
		if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_PATH ) {
264
			$siteIds = array_merge( $siteIds, $locale->getSitePath() );
265
		}
266
267
		if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE ) {
268
			$siteIds = array_merge( $siteIds, $locale->getSiteSubTree() );
269
		}
270
271
		$this->replaceSiteMarker( $this->searchConfig['customer:has'], 'ezuli_has."siteid"', $siteIds, ':site' );
272
		$this->replaceSiteMarker( $this->searchConfig['customer:prop'], 'ezupr_prop."siteid"', $siteIds, ':site' );
273
274
275
		$this->searchConfig['customer:has']['function'] = function( &$source, array $params ) {
276
277
			$source = str_replace( ':type', isset( $params[1] ) ? 'AND ezuli_has."type" = $2' : '', $source );
278
			$source = str_replace( ':refid', isset( $params[2] ) ? 'AND ezuli_has."refid" = $3' : '', $source );
279
280
			return $params;
281
		};
282
283
284
		$this->searchConfig['customer:prop']['function'] = function( &$source, array $params ) {
285
286
			$lang = 'AND ezupr_prop."langid"';
287
			$lang = isset( $params[1] ) ? ( $params[1] !== 'null' ? $lang . ' = $2' : $lang . ' IS NULL' ) : '';
288
289
			$source = str_replace( ':langid', $lang, $source );
290
			$source = str_replace( ':value', isset( $params[2] ) ? 'AND ezupr_prop."value" = $3' : '', $source );
291
292
			return $params;
293
		};
294
	}
295
296
297
	/**
298
	 * Removes old entries from the storage.
299
	 *
300
	 * @param array $siteids List of IDs for sites whose entries should be deleted
301
	 */
302
	public function cleanup( array $siteids )
303
	{
304
		$path = 'mshop/customer/manager/submanagers';
305
		foreach( $this->getContext()->getConfig()->get( $path, ['address', 'group', 'lists', 'property'] ) as $domain ) {
306
			$this->getObject()->getSubManager( $domain )->cleanup( $siteids );
307
		}
308
	}
309
310
311
	/**
312
	 * Removes multiple items specified by ids in the array.
313
	 *
314
	 * @param array $ids List of IDs
315
	 */
316
	public function deleteItems( array $ids )
317
	{
318
		$service = $this->getContext()->getEzUserService();
0 ignored issues
show
Bug introduced by
The method getEzUserService() does not exist on Aimeos\MShop\Context\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Context\Item\Iface such as Aimeos\MShop\Context\Item\Ezpublish. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

318
		$service = $this->getContext()->/** @scrutinizer ignore-call */ getEzUserService();
Loading history...
319
320
		foreach( $ids as $id ) {
321
			$service->deleteUser( $service->loadUser( $id ) );
322
		}
323
	}
324
325
326
	/**
327
	 * Returns the list attributes that can be used for searching.
328
	 *
329
	 * @param boolean $withsub Return also attributes of sub-managers if true
330
	 * @return array List of attribute items implementing \Aimeos\MW\Criteria\Attribute\Iface
331
	 */
332
	public function getSearchAttributes( $withsub = true )
333
	{
334
		$path = 'mshop/customer/manager/submanagers';
335
336
		return $this->getSearchAttributesBase( $this->searchConfig, $path, ['address', 'group', 'lists', 'property'], $withsub );
337
	}
338
339
340
	/**
341
	 * Returns a new manager for customer extensions
342
	 *
343
	 * @param string $manager Name of the sub manager type in lower case
344
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
345
	 * @return mixed Manager for different extensions, e.g stock, tags, locations, etc.
346
	 */
347
	public function getSubManager( $manager, $name = null )
348
	{
349
		return $this->getSubManagerBase( 'customer', $manager, ( $name === null ? 'Ezpublish' : $name ) );
350
	}
351
352
353
	/**
354
	 * Saves a customer item object.
355
	 *
356
	 * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object
357
	 * @param boolean $fetch True if the new ID should be returned in the item
358
	 * @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID
359
	 */
360
	public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
361
	{
362
		self::checkClass( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $item );
363
364
		if( !$item->isModified() )
365
		{
366
			$item = $this->savePropertyItems( $item, 'customer' );
367
			$item = $this->saveAddressItems( $item, 'customer' );
0 ignored issues
show
Bug introduced by
$item of type Aimeos\MShop\Common\Item\PropertyRef\Iface is incompatible with the type Aimeos\MShop\Common\Item\AddressRef\Iface expected by parameter $item of Aimeos\MShop\Customer\Ma...ard::saveAddressItems(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

367
			$item = $this->saveAddressItems( /** @scrutinizer ignore-type */ $item, 'customer' );
Loading history...
368
			return $this->saveListItems( $item, 'customer' );
369
		}
370
371
		$context = $this->getContext();
372
373
		$class = '\Aimeos\MShop\Context\Item\Ezpublish';
374
		if( !is_a( $context, $class ) ) {
375
			throw new \Aimeos\MShop\Customer\Exception( sprintf( 'Object is not of required type "%1$s"', $class ) );
376
		}
377
378
		$service = $context->getEzUserService();
379
		$email = $item->getPaymentAddress()->getEmail();
0 ignored issues
show
Bug introduced by
The method getPaymentAddress() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

379
		$email = $item->/** @scrutinizer ignore-call */ getPaymentAddress()->getEmail();
Loading history...
380
381
		if( $item->getId() !== null )
382
		{
383
			$struct = $service->newUserUpdateStruct();
384
			$struct->password = $item->getPassword();
0 ignored issues
show
Bug introduced by
The method getPassword() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

384
			/** @scrutinizer ignore-call */ 
385
   $struct->password = $item->getPassword();
Loading history...
385
			$struct->enabled = $item->getStatus();
0 ignored issues
show
Bug introduced by
The method getStatus() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Order\Item\Base\Product\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Common\Item\Status\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Subscription\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Locale\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Order\Item\Base\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Plugin\Item\Standard or Aimeos\MShop\Media\Item\Standard or Aimeos\MAdmin\Job\Item\Standard or Aimeos\MShop\Common\Item\Type\Standard or Aimeos\MShop\Subscription\Item\Standard or Aimeos\MShop\Locale\Item\Site\Standard or Aimeos\MShop\Locale\Item\Currency\Standard or Aimeos\MShop\Text\Item\Standard or Aimeos\MShop\Locale\Item\Language\Standard or Aimeos\MShop\Locale\Item\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Price\Item\Base or Aimeos\MShop\Supplier\Item\Standard or Aimeos\MShop\Coupon\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Order\Item\Base\Product\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

385
			/** @scrutinizer ignore-call */ 
386
   $struct->enabled = $item->getStatus();
Loading history...
386
			$struct->email = $email;
387
388
			$user = $service->loadUser( $item->getId() );
389
			$service->updateUser( $user, $struct );
390
		}
391
		else
392
		{
393
			$struct = $service->newUserCreateStruct( $item->getCode(), $email, $item->getPassword(), 'eng-GB' );
0 ignored issues
show
Bug introduced by
The method getCode() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Order\Item\Base\Service\Iface or Aimeos\MShop\Customer\Item\Group\Iface or Aimeos\MShop\Order\Item\Base\Coupon\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Order\Item\...Service\Attribute\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Order\Item\...Product\Attribute\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Group\Standard or Aimeos\MShop\Common\Item\Type\Standard or Aimeos\MShop\Locale\Item\Site\Standard or Aimeos\MShop\Locale\Item\Currency\Standard or Aimeos\MShop\Locale\Item\Language\Standard or Aimeos\MShop\Order\Item\Base\Service\Base or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Order\Item\Base\Coupon\Standard or Aimeos\MShop\Coupon\Item\Code\Standard or Aimeos\MShop\Order\Item\...vice\Attribute\Standard or Aimeos\MShop\Supplier\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Order\Item\...duct\Attribute\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Common\Item\Tree\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

393
			$struct = $service->newUserCreateStruct( $item->/** @scrutinizer ignore-call */ getCode(), $email, $item->getPassword(), 'eng-GB' );
Loading history...
394
			$struct->enabled = $item->getStatus();
395
396
			$user = $service->createUser( $struct, [] );
397
			$item->setId( $user->getUserId() );
398
		}
399
400
		$dbm = $context->getDatabaseManager();
401
		$dbname = $this->getResourceName();
402
		$conn = $dbm->acquire( $dbname );
403
404
		try
405
		{
406
			$date = date( 'Y-m-d H:i:s' );
407
			$ctime = ( $item->getTimeCreated() ? $item->getTimeCreated() : $date );
408
			$billingAddress = $item->getPaymentAddress();
409
410
			$path = 'mshop/customer/manager/ezpublish/update';
411
			$stmt = $this->getCachedStatement( $conn, $path );
412
413
			$stmt->bind( 1, $billingAddress->getCompany() );
414
			$stmt->bind( 2, $billingAddress->getVatID() );
415
			$stmt->bind( 3, $billingAddress->getSalutation() );
416
			$stmt->bind( 4, $billingAddress->getTitle() );
417
			$stmt->bind( 5, $billingAddress->getFirstname() );
418
			$stmt->bind( 6, $billingAddress->getLastname() );
419
			$stmt->bind( 7, $billingAddress->getAddress1() );
420
			$stmt->bind( 8, $billingAddress->getAddress2() );
421
			$stmt->bind( 9, $billingAddress->getAddress3() );
422
			$stmt->bind( 10, $billingAddress->getPostal() );
423
			$stmt->bind( 11, $billingAddress->getCity() );
424
			$stmt->bind( 12, $billingAddress->getState() );
425
			$stmt->bind( 13, $billingAddress->getCountryId() );
426
			$stmt->bind( 14, $billingAddress->getLanguageId() );
427
			$stmt->bind( 15, $billingAddress->getTelephone() );
428
			$stmt->bind( 16, $billingAddress->getTelefax() );
429
			$stmt->bind( 17, $billingAddress->getWebsite() );
430
			$stmt->bind( 18, $item->getBirthday() );
0 ignored issues
show
Bug introduced by
The method getBirthday() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

430
			$stmt->bind( 18, $item->/** @scrutinizer ignore-call */ getBirthday() );
Loading history...
431
			$stmt->bind( 19, $item->getDateVerified() );
0 ignored issues
show
Bug introduced by
The method getDateVerified() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

431
			$stmt->bind( 19, $item->/** @scrutinizer ignore-call */ getDateVerified() );
Loading history...
432
			$stmt->bind( 20, $date ); // Modification time
433
			$stmt->bind( 21, $context->getEditor() );
434
			$stmt->bind( 22, $ctime ); // Creation time
435
			$stmt->bind( 23, $item->getId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
436
437
			$stmt->execute()->finish();
438
439
			$dbm->release( $conn, $dbname );
440
		}
441
		catch( \Exception $e )
442
		{
443
			$dbm->release( $conn, $dbname );
444
			throw $e;
445
		}
446
447
		$item = $this->savePropertyItems( $item, 'customer' );
448
		$item = $this->saveAddressItems( $item, 'customer' );
449
		return $this->saveListItems( $item, 'customer' );
450
	}
451
452
453
	/**
454
	 * Returns the item objects matched by the given search criteria.
455
	 *
456
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria object
457
	 * @param integer &$total Number of items that are available in total
458
	 * @return array List of items implementing \Aimeos\MShop\Customer\Item\Iface
459
	 * @throws \Aimeos\MShop\Customer\Exception If creating items failed
460
	 */
461
	public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null )
462
	{
463
		$dbm = $this->getContext()->getDatabaseManager();
464
		$dbname = $this->getResourceName();
465
		$conn = $dbm->acquire( $dbname );
466
		$map = [];
467
468
		try
469
		{
470
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
471
			$cfgPathSearch = 'mshop/customer/manager/ezpublish/search';
472
			$cfgPathCount = 'mshop/customer/manager/ezpublish/count';
473
			$required = array( 'customer' );
474
475
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level );
476
477
			while( ( $row = $results->fetch() ) !== false )
478
			{
479
				$map[ $row['customer.id'] ] = $row;
480
				$map[ $row['customer.id'] ]['groups'] = [];
481
			}
482
483
484
			$path = 'mshop/customer/manager/ezpublish/groups';
485
			$stmt = $conn->create( $this->getGroupSql( array_keys( $map ), $path ) );
486
			$results = $stmt->execute();
487
488
			while( ( $row = $results->fetch() ) !== false ) {
489
				$map[ $row['contentobject_id'] ]['groups'][] = $row['role_id'];
490
			}
491
492
			$dbm->release( $conn, $dbname );
493
		}
494
		catch( \Exception $e )
495
		{
496
			$dbm->release( $conn, $dbname  );
497
			throw $e;
498
		}
499
500
		return $this->buildItems( $map, $ref, 'customer' );
501
	}
502
503
504
	/**
505
	 * Creates a new customer item.
506
	 *
507
	 * @param array $values List of attributes for customer item
508
	 * @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items
509
	 * @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items
510
	 * @param \Aimeos\MShop\Common\Item\Address\Iface[] $addrItems List of referenced address items
511
	 * @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items
512
	 * @return \Aimeos\MShop\Customer\Item\Iface New customer item
513
	 */
514
	protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [],
515
		array $addrItems = [], array $propItems = [] )
516
	{
517
		$address = new \Aimeos\MShop\Common\Item\Address\Simple( 'customer.', $values );
518
519
		return new \Aimeos\MShop\Customer\Item\Ezpublish(
520
			$address, $values, $listItems, $refItems, $addrItems, $propItems
521
		);
522
	}
523
524
525
	/**
526
	 * Returns the SQL statement for retrieving the customer group IDs
527
	 *
528
	 * @param array $ids List of customer IDs
529
	 * @param string $cfgpath Configuration path to the SQL statement
530
	 * @return string SQL statement ready for execution
531
	 */
532
	protected function getGroupSql( array $ids, $cfgpath )
533
	{
534
		if( empty( $ids ) ) { return '1=1'; }
535
536
		$search = $this->getObject()->createSearch();
537
		$search->setConditions( $search->compare( '==', 'id', $ids ) );
538
539
		$types = array( 'id' => \Aimeos\MW\DB\Statement\Base::PARAM_INT );
540
		$translations = array( 'id' => '"contentobject_id"' );
541
542
		$cond = $search->getConditionSource( $types, $translations );
543
544
		return str_replace( ':cond', $cond, $this->getSqlConfig( $cfgpath ) );
545
	}
546
}
547